From patchwork Mon Apr 22 16:25:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638681 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 ED6B115381F for ; Mon, 22 Apr 2024 16:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803950; cv=none; b=IiZY8RyNq6KjNjTI+Twkh5eZ4jZ48j+jFSy09Q1pTrngrJ6MAkIT6lFq1EifgRkR4CGIZEaF4/ArG+9UUweOZ36pFKEdnz5RJ+klpFkSoW/clwbbluHlJS5FY43CMBvqQpJKJraHFAAL/9DQM73R4eQLJ3cPPovXd/vwEGBk47o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803950; c=relaxed/simple; bh=1ki4d1UstzOhjF0XBbF0DXO2M7AI1c3IURAJjhJhWd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nazlFfxhw/Um5YAFD10WRYk/zVQEbS51F6yZhPobhP0hglYavyZqXM0Ef/IZpnGqH8xFXr7edKytqxRVW9yYTdkAdgG6gYPZrUR0RA6yDF/LYX8SNuQnB/ip2sP1/P37Vf4tvbTo+9V1i6UhjamMkubItCLG6bR7110b+2Q17g8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZyjemSt; 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="lZyjemSt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE83C116B1; Mon, 22 Apr 2024 16:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803949; bh=1ki4d1UstzOhjF0XBbF0DXO2M7AI1c3IURAJjhJhWd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZyjemSt59ZYo7AdBob2iRzBgHL7lEk0w0e1UBUL0mRUVj/Gps1nkh+75YD+ymUaS 4BLyuq59vwFME0DqkA/sTOga0iFNVHfdJe5kwpN02IsVBOxXG2Lz0cNp7gwx1MXPMJ cPoYkbvQqn2LD//rVDyWrdDAW+w2Nr4BShnMHaNZE7YobMdMQk1sHDbORavWq/P1yV AvtdVk0ZrNwWHbmvvpUCgraM19JMO+LWJMSPjjypIdjMjRjKr7Jhv66AyLyZOyGjz9 q3S0ID50ppJOv450JUbn9wxfpxmv/2I2CpYZGpmHQeegJFq7HJdNMDVGvziI6RBBaK FQN4q5Dbzc1pg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 01/67] xfs: use xfs_defer_pending objects to recover intent items Date: Mon, 22 Apr 2024 18:25:23 +0200 Message-ID: <20240422163832.858420-3-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 03f7767c9f6120ac933378fdec3bfd78bf07bc11 One thing I never quite got around to doing is porting the log intent item recovery code to reconstruct the deferred pending work state. As a result, each intent item open codes xfs_defer_finish_one in its recovery method, because that's what the EFI code did before xfs_defer.c even existed. This is a gross thing to have left unfixed -- if an EFI cannot proceed due to busy extents, we end up creating separate new EFIs for each unfinished work item, which is a change in behavior from what runtime would have done. Worse yet, Long Li pointed out that there's a UAF in the recovery code. The ->commit_pass2 function adds the intent item to the AIL and drops the refcount. The one remaining refcount is now owned by the recovery mechanism (aka the log intent items in the AIL) with the intent of giving the refcount to the intent done item in the ->iop_recover function. However, if something fails later in recovery, xlog_recover_finish will walk the recovered intent items in the AIL and release them. If the CIL hasn't been pushed before that point (which is possible since we don't force the log until later) then the intent done release will try to free its associated intent, which has already been freed. This patch starts to address this mess by having the ->commit_pass2 functions recreate the xfs_defer_pending state. The next few patches will fix the recovery functions. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 105 +++++++++++++++++++++++++++++++++------------ libxfs/xfs_defer.h | 5 +++ 2 files changed, 82 insertions(+), 28 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 7ff125c5f..bd6f14a2c 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -240,23 +240,53 @@ xfs_defer_create_intents( return ret; } -STATIC void +static inline void xfs_defer_pending_abort( + struct xfs_mount *mp, + struct xfs_defer_pending *dfp) +{ + const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + + trace_xfs_defer_pending_abort(mp, dfp); + + if (dfp->dfp_intent && !dfp->dfp_done) { + ops->abort_intent(dfp->dfp_intent); + dfp->dfp_intent = NULL; + } +} + +static inline void +xfs_defer_pending_cancel_work( + struct xfs_mount *mp, + struct xfs_defer_pending *dfp) +{ + const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + struct list_head *pwi; + struct list_head *n; + + trace_xfs_defer_cancel_list(mp, dfp); + + list_del(&dfp->dfp_list); + list_for_each_safe(pwi, n, &dfp->dfp_work) { + list_del(pwi); + dfp->dfp_count--; + trace_xfs_defer_cancel_item(mp, dfp, pwi); + ops->cancel_item(pwi); + } + ASSERT(dfp->dfp_count == 0); + kmem_cache_free(xfs_defer_pending_cache, dfp); +} + +STATIC void +xfs_defer_pending_abort_list( struct xfs_mount *mp, struct list_head *dop_list) { struct xfs_defer_pending *dfp; - const struct xfs_defer_op_type *ops; /* Abort intent items that don't have a done item. */ - list_for_each_entry(dfp, dop_list, dfp_list) { - ops = defer_op_types[dfp->dfp_type]; - trace_xfs_defer_pending_abort(mp, dfp); - if (dfp->dfp_intent && !dfp->dfp_done) { - ops->abort_intent(dfp->dfp_intent); - dfp->dfp_intent = NULL; - } - } + list_for_each_entry(dfp, dop_list, dfp_list) + xfs_defer_pending_abort(mp, dfp); } /* Abort all the intents that were committed. */ @@ -266,7 +296,7 @@ xfs_defer_trans_abort( struct list_head *dop_pending) { trace_xfs_defer_trans_abort(tp, _RET_IP_); - xfs_defer_pending_abort(tp->t_mountp, dop_pending); + xfs_defer_pending_abort_list(tp->t_mountp, dop_pending); } /* @@ -384,27 +414,13 @@ xfs_defer_cancel_list( { struct xfs_defer_pending *dfp; struct xfs_defer_pending *pli; - struct list_head *pwi; - struct list_head *n; - const struct xfs_defer_op_type *ops; /* * Free the pending items. Caller should already have arranged * for the intent items to be released. */ - list_for_each_entry_safe(dfp, pli, dop_list, dfp_list) { - ops = defer_op_types[dfp->dfp_type]; - trace_xfs_defer_cancel_list(mp, dfp); - list_del(&dfp->dfp_list); - list_for_each_safe(pwi, n, &dfp->dfp_work) { - list_del(pwi); - dfp->dfp_count--; - trace_xfs_defer_cancel_item(mp, dfp, pwi); - ops->cancel_item(pwi); - } - ASSERT(dfp->dfp_count == 0); - kmem_cache_free(xfs_defer_pending_cache, dfp); - } + list_for_each_entry_safe(dfp, pli, dop_list, dfp_list) + xfs_defer_pending_cancel_work(mp, dfp); } /* @@ -660,6 +676,39 @@ xfs_defer_add( dfp->dfp_count++; } +/* + * Create a pending deferred work item to replay the recovered intent item + * and add it to the list. + */ +void +xfs_defer_start_recovery( + struct xfs_log_item *lip, + enum xfs_defer_ops_type dfp_type, + struct list_head *r_dfops) +{ + struct xfs_defer_pending *dfp; + + dfp = kmem_cache_zalloc(xfs_defer_pending_cache, + GFP_NOFS | __GFP_NOFAIL); + dfp->dfp_type = dfp_type; + dfp->dfp_intent = lip; + INIT_LIST_HEAD(&dfp->dfp_work); + list_add_tail(&dfp->dfp_list, r_dfops); +} + +/* + * Cancel a deferred work item created to recover a log intent item. @dfp + * will be freed after this function returns. + */ +void +xfs_defer_cancel_recovery( + struct xfs_mount *mp, + struct xfs_defer_pending *dfp) +{ + xfs_defer_pending_abort(mp, dfp); + xfs_defer_pending_cancel_work(mp, dfp); +} + /* * Move deferred ops from one transaction to another and reset the source to * initial state. This is primarily used to carry state forward across @@ -764,7 +813,7 @@ xfs_defer_ops_capture_abort( { unsigned short i; - xfs_defer_pending_abort(mp, &dfc->dfc_dfops); + xfs_defer_pending_abort_list(mp, &dfc->dfc_dfops); xfs_defer_cancel_list(mp, &dfc->dfc_dfops); for (i = 0; i < dfc->dfc_held.dr_bufs; i++) diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 8788ad5f6..5dce938ba 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -125,6 +125,11 @@ void xfs_defer_ops_capture_abort(struct xfs_mount *mp, struct xfs_defer_capture *d); void xfs_defer_resources_rele(struct xfs_defer_resources *dres); +void xfs_defer_start_recovery(struct xfs_log_item *lip, + enum xfs_defer_ops_type dfp_type, struct list_head *r_dfops); +void xfs_defer_cancel_recovery(struct xfs_mount *mp, + struct xfs_defer_pending *dfp); + int __init xfs_defer_init_item_caches(void); void xfs_defer_destroy_item_caches(void); From patchwork Mon Apr 22 16:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638682 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 8BE1815099A for ; Mon, 22 Apr 2024 16:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803951; cv=none; b=lfkGnIJgptbBG3BfHLa/2M/cBI9WH0KYR6lGC/3ebOOy0uc/8CeiA+zWT7Ly3CkLzzrLapqDiRKeZKXmJZ03+dlfqffJZ2/lwK5QGax99TWkV82I48rHG5L+KL+PeQMCFMSTqCFmI1OOP0sxgrWrOxD8GkwkJqZvnqraevI7xy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803951; c=relaxed/simple; bh=OCDnrkGQoDio//OEuJtqdOtJTzNzHVIQUv884XFzDPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iAsWsnu9W6frLQlqOTYDqhASOJza8dJCMGKO0eRZBWbTG13HJTco9cb+CURgcggVJR2XG1AUqPTZ1pQl7fpP8x7Ge+FyV/IFLcmxKxkVEXrtwjPb0o2tKxASBfWPW6+p2plnAoT0plXT+lONJUVV/GXebj1prt2/Wh1RqXS9g3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AVaTieIR; 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="AVaTieIR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EB14C32781; Mon, 22 Apr 2024 16:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803951; bh=OCDnrkGQoDio//OEuJtqdOtJTzNzHVIQUv884XFzDPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVaTieIRXCJ0485UEXdXpBiO/W5FRuK4PI56FbAhIWskvjUl858xKbhauVMtZsIDt bfQePR6ryLV2K05zlDWwpw5xLkRxooRaf4VstZx9KMDaGm3jlJL6uVR34mGbeEGMwP Bs5inBNhhEOIvR5am/A7a/73LGdayhquWu9JBrWNDkfDQHEmny3kl32M6miWgMFAkR Uwi5JUwW1sH2OW6chrXeULkVoVqAv8eyTIodHnuQE6OD4QxVcphXIVxLsw7yx3vlGj Y8YpzIU/6aay8j1AdgCrPQiNCIN50FAyqnS96MgVyNX6sMBDbXhb7SaQyqNaRMhHdX Z66sJC3TvFT3w== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 02/67] xfs: recreate work items when recovering intent items Date: Mon, 22 Apr 2024 18:25:24 +0200 Message-ID: <20240422163832.858420-4-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e70fb328d5277297ea2d9169a3a046de6412d777 Recreate work items for each xfs_defer_pending object when we are recovering intent items. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 3 +-- libxfs/xfs_defer.h | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index bd6f14a2c..4900a7d62 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -671,9 +671,8 @@ xfs_defer_add( list_add_tail(&dfp->dfp_list, &tp->t_dfops); } - list_add_tail(li, &dfp->dfp_work); + xfs_defer_add_item(dfp, li); trace_xfs_defer_add_item(tp->t_mountp, dfp, li); - dfp->dfp_count++; } /* diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 5dce938ba..bef5823f6 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -130,6 +130,15 @@ void xfs_defer_start_recovery(struct xfs_log_item *lip, void xfs_defer_cancel_recovery(struct xfs_mount *mp, struct xfs_defer_pending *dfp); +static inline void +xfs_defer_add_item( + struct xfs_defer_pending *dfp, + struct list_head *work) +{ + list_add_tail(work, &dfp->dfp_work); + dfp->dfp_count++; +} + int __init xfs_defer_init_item_caches(void); void xfs_defer_destroy_item_caches(void); From patchwork Mon Apr 22 16:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638683 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 EEF69153803 for ; Mon, 22 Apr 2024 16:39: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=1713803953; cv=none; b=NjuZwfUQhTOoewuP5twZuemTxDlaxCTGwDf7cCQ2hU2wdXd61htq3e4RWR1aJBtN6FD0m4kQAk5e6jJSLZRQrvav8JMueh/JN/m4au/6P2Ggc6NzYiq+T+IaOFiX9fngAzj+46WgV3cCeEBue8ElueLexZ0REoFM4VqSy/MD7TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803953; c=relaxed/simple; bh=bdA/ao3InQv5eRhL8YMt8R7khrzhuOYrWNGIKFzpDS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LT9BWpCNfvS3z8ea92fTJLWBvfzrTNYf0IotcZNFz5io/ZQk/Bw+HJIaOaFJd5KBed+AIf955QpQ3iuznkddcCwGiD1impv7DYzUPwkSyVouK2feb0WplnYICZXha583TOt+FLdIb7wfCzl7OwkMwTMfLyRIELjepJJct5cuebg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DaRBmyWO; 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="DaRBmyWO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91DA5C113CC; Mon, 22 Apr 2024 16:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803952; bh=bdA/ao3InQv5eRhL8YMt8R7khrzhuOYrWNGIKFzpDS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DaRBmyWOUn8mdkxdKmGHbYJ1iZIW7vlcZjcte5Dta7uZoz7yLmT/Pn2OLnpungDIc 8Cmh2qViDZDz28Ed7yJrN6iL5QJ9cJXhMHBvhBPW0HJcdNQPVwpvp/W244gPn/rmt/ tT6vLpb2Mu6LkXcgZXTr3OuGiGtlts8OounG5djo14xcw8Rp2Gn/82hUDqpl4HDf/k x8zX8nWpt8Jsw1l8Qkc/Gg1CqthV536+8M9WBgBtUXilGm0R5aqLVVrTCd+Af8B0ri vH2HzhOxc7hn0bg5X4g07Uma1XjI0qageWs+uISFq/FY8cBK1sfCtW9o/9OuG9tdeD MoG70QlEgsHRg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 03/67] xfs: use xfs_defer_finish_one to finish recovered work items Date: Mon, 22 Apr 2024 18:25:25 +0200 Message-ID: <20240422163832.858420-5-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e5f1a5146ec35f3ed5d7f5ac7807a10c0062b6b8 Get rid of the open-coded calls to xfs_defer_finish_one. This also means that the recovery transaction takes care of cleaning up the dfp, and we have solved (I hope) all the ownership issues in recovery. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 2 +- libxfs/xfs_defer.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 4900a7d62..4ef9867cc 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -479,7 +479,7 @@ xfs_defer_relog( * Log an intent-done item for the first pending intent, and finish the work * items. */ -static int +int xfs_defer_finish_one( struct xfs_trans *tp, struct xfs_defer_pending *dfp) diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index bef5823f6..c1a648e99 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -41,6 +41,7 @@ void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type, struct list_head *h); int xfs_defer_finish_noroll(struct xfs_trans **tp); int xfs_defer_finish(struct xfs_trans **tp); +int xfs_defer_finish_one(struct xfs_trans *tp, struct xfs_defer_pending *dfp); void xfs_defer_cancel(struct xfs_trans *); void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp); From patchwork Mon Apr 22 16:25:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638684 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 3A8C915381C for ; Mon, 22 Apr 2024 16:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803954; cv=none; b=JtYo8LCFwRuSAEpClB0Dney9SWI+uIN87TKa2/Iwh0Rwj7V+FSDOdwZ1i0Elq/4BRGvY8qyXD8x/rM/oRNenhKJeV78udmkZilsGIoLAgbyQTvcoSINu10v2ukoF5wOtbLi+u+6Zp2A2A9kDuOjf9sjagWbaPK3A8jpYS2imZm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803954; c=relaxed/simple; bh=u3TZZTy0oaeA8NEEOdJrtE4yIYbcKdNv3fLD3k+f/lE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N/rU0TSH9sVUjFO0aQR1MPmyhLPTglRbjpX5JBmnxm5NP+jHExppHXs6OgTQsaggMhLeSnMAc/UtpGEyCO6l3+RJsJNalDX11D7nAmXpwhcdaGfMwW/uDk+TgPhMSR4Ft5N+qaXiLq6vlZMfsCn1Hn+OBE2nn0OaJfblXz5Q1uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mzem7R8n; 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="Mzem7R8n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20469C116B1; Mon, 22 Apr 2024 16:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803954; bh=u3TZZTy0oaeA8NEEOdJrtE4yIYbcKdNv3fLD3k+f/lE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mzem7R8nKpoOM4OL8yRjOedoUau54z7yB6MNQffE9FRWyjPSIQ9xByG4rm2eeCTGl 1M++1oUfCXBKQt54ZwEs6oXh71kmiS3mT4zbuitsJguA5tcgFv2B/Ylf0Q772pROx4 rF6qSncJE9WftRR4jPKkbnicvbkES4zjZNqKUg2YSaexPwrLego1zFPwjqluaGfKqN kK4rZ7RRYLmoUViCMsx+QBPEtzI2AONoz1bbZFlBiRAEMcBPerdFUCsaLkXpf5IyN0 5MMs/w4PAVG7uH9hkYVGb+2rSL7RFJnTD4OYvQjmpP2vl+HupEymHJr+/v4j7/A8Rm FE4UxbF8lLJaQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 04/67] xfs: move ->iop_recover to xfs_defer_op_type Date: Mon, 22 Apr 2024 18:25:26 +0200 Message-ID: <20240422163832.858420-6-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: db7ccc0bac2add5a41b66578e376b49328fc99d0 Finish off the series by moving the intent item recovery function pointer to the xfs_defer_op_type struct, since this is really a deferred work function now. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- include/xfs_trace.h | 2 ++ libxfs/xfs_defer.c | 17 +++++++++++++++++ libxfs/xfs_defer.h | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 7fd446ad4..c79a4bd74 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -336,4 +336,6 @@ #define trace_xfs_fs_mark_healthy(a,b) ((void) 0) +#define trace_xlog_intent_recovery_failed(...) ((void) 0) + #endif /* __TRACE_H__ */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 4ef9867cc..54865b73b 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -708,6 +708,23 @@ xfs_defer_cancel_recovery( xfs_defer_pending_cancel_work(mp, dfp); } +/* Replay the deferred work item created from a recovered log intent item. */ +int +xfs_defer_finish_recovery( + struct xfs_mount *mp, + struct xfs_defer_pending *dfp, + struct list_head *capture_list) +{ + const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + int error; + + error = ops->recover_work(dfp, capture_list); + if (error) + trace_xlog_intent_recovery_failed(mp, error, + ops->recover_work); + return error; +} + /* * Move deferred ops from one transaction to another and reset the source to * initial state. This is primarily used to carry state forward across diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index c1a648e99..ef86a7f9b 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -57,6 +57,8 @@ struct xfs_defer_op_type { void (*finish_cleanup)(struct xfs_trans *tp, struct xfs_btree_cur *state, int error); void (*cancel_item)(struct list_head *item); + int (*recover_work)(struct xfs_defer_pending *dfp, + struct list_head *capture_list); unsigned int max_items; }; @@ -130,6 +132,8 @@ void xfs_defer_start_recovery(struct xfs_log_item *lip, enum xfs_defer_ops_type dfp_type, struct list_head *r_dfops); void xfs_defer_cancel_recovery(struct xfs_mount *mp, struct xfs_defer_pending *dfp); +int xfs_defer_finish_recovery(struct xfs_mount *mp, + struct xfs_defer_pending *dfp, struct list_head *capture_list); static inline void xfs_defer_add_item( From patchwork Mon Apr 22 16:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638685 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 BE5F015099A for ; Mon, 22 Apr 2024 16:39: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=1713803955; cv=none; b=iUIH+UycqCf1jTRgdx9G+3kb6sJzWdzfG6xGJYyZtu50ZbZzKZxU3yCOWIQpUDAVrDr8R0e4YnaqCcMK/ElKb7x0XWjIw7/sPaGLVg8TeZ0xP2XHkxJIjUZw+7ALc3L3zPt/gdJ6TGFokw7ioRk9uJNuZ010Gb6/XF1ajNS4gpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803955; c=relaxed/simple; bh=5FburhU4w3fQkPHp67dEAIFAh2jkcwegVWZs8Zqa8rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KYtSHeO5sN136VTn40CYkCZMiVbmUG+HD6QzC7Db5FQYL5H184xpC0+j0WjsyNMSewGGtzbH/hWytGDOg+UhxE3eaSpTCFgH3WEnSLY0x6hhJ+j8acK1JBNVz5+YMFAoGBSfbZ8doTKYmGGsQ9Kixsn79i0UT6hWkl9fHW+NZEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DsfQ+lHW; 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="DsfQ+lHW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2F3BC4AF07; Mon, 22 Apr 2024 16:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803955; bh=5FburhU4w3fQkPHp67dEAIFAh2jkcwegVWZs8Zqa8rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DsfQ+lHWt1lFhEayHjgtxOgXsCtC4MqNw5v14e2rQeLKzsI35QrhlSUsvXpUzE7Vd MX8v4ePErbcfarFdDGMwdkUesSqErpLukScGrava4pbNuGPyc/jUXNXokyj4tFyYJy SxBAnFKI/hCxPqBoE5P4/GvAG1KzhzhjpeCn8KGuBdKtFRuX2N7Yh8lfJYwMsEWBuc 5W32PLjgCYnkbacB2ybTonk4s/RPAJxOqzPMsjYwm+jRH/RFySHtCHqRSniyEx8ro4 3NUdNCXspCwRVB6MjkUr2onzN47l4W8CogK9zQaO3gjjZI+qPtOfidYPHZnf16g0H6 GaLtnKUs62tJg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 05/67] xfs: hoist intent done flag setting to ->finish_item callsite Date: Mon, 22 Apr 2024 18:25:27 +0200 Message-ID: <20240422163832.858420-7-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 3dd75c8db1c1675a26d3e228bab349c1fc065867 Each log intent item's ->finish_item call chain inevitably includes some code to set the dirty flag of the transaction. If there's an associated log intent done item, it also sets the item's dirty flag and the transaction's INTENT_DONE flag. This is repeated throughout the codebase. Reduce the LOC by moving all that to xfs_defer_finish_one. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 54865b73b..6a9ce9241 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -186,6 +186,32 @@ static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, }; +/* Create a log intent done item for a log intent item. */ +static inline void +xfs_defer_create_done( + struct xfs_trans *tp, + struct xfs_defer_pending *dfp) +{ + const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + struct xfs_log_item *lip; + + /* + * Mark the transaction dirty, even on error. This ensures the + * transaction is aborted, which: + * + * 1.) releases the log intent item and frees the log done item + * 2.) shuts down the filesystem + */ + tp->t_flags |= XFS_TRANS_DIRTY; + lip = ops->create_done(tp, dfp->dfp_intent, dfp->dfp_count); + if (!lip) + return; + + tp->t_flags |= XFS_TRANS_HAS_INTENT_DONE; + set_bit(XFS_LI_DIRTY, &lip->li_flags); + dfp->dfp_done = lip; +} + /* * Ensure there's a log intent item associated with this deferred work item if * the operation must be restarted on crash. Returns 1 if there's a log item; @@ -491,7 +517,7 @@ xfs_defer_finish_one( trace_xfs_defer_pending_finish(tp->t_mountp, dfp); - dfp->dfp_done = ops->create_done(tp, dfp->dfp_intent, dfp->dfp_count); + xfs_defer_create_done(tp, dfp); list_for_each_safe(li, n, &dfp->dfp_work) { list_del(li); dfp->dfp_count--; From patchwork Mon Apr 22 16:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638686 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 8F0C4153833 for ; Mon, 22 Apr 2024 16:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803957; cv=none; b=Wag/jxxmLJrTN0ptI4fD3d26T2f4FBYKWMgcO0mStrZ8SMPubUDr+Rhv08zCc9y1NEkc7eSQ4Z/DojtOwdtqueIChNLDdINCLHzHtW3RV5YPc0iiPSFLxVCXs0AwWPXdoq87ilJzJgc+ABLa7O8bLZ43NapvxXTrAFNPfFNxwAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803957; c=relaxed/simple; bh=GOdqprI8nrfgICBT9hOwQ5WModjn3kps2kn3kqtvbAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LbzTnv2MhYIFJINdghrXiwrFlzaqYG2SSVIysuC6AnPlZiiqYaF3t77JuFuq3Hv8+1tQ8ZuX1sFbRqeFnA9vTUbBkahg7nEjgi+JqC5d3Uesam3rzaiPPiJtmN892jllNBKW7PXBlQKWJ/mJQv41WW0AU/oj+7Ht7R5zjnrrZTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CL1WD9pk; 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="CL1WD9pk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24B06C32782; Mon, 22 Apr 2024 16:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803957; bh=GOdqprI8nrfgICBT9hOwQ5WModjn3kps2kn3kqtvbAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CL1WD9pkhUwmiCUYKsyIkfCziF1Gos6sdhtnBlz6+nLG/kzcv1f0kVFt0ZKyCVtfc FACfcCEXMA8sm9BXIjPenH9Oy4C9dH930sY/m6NpjT/YwuvF78na4S8c1Gr/lZg7KL r6QIEROGHnbASOlakdwb7eZNm2OFhclPMUwVJf/gVZWerPy4tbjXoc4ALN2qe0L559 Yk/V3zlXBkUk6cNePyCLVGj1BH75JBI7pLkl4XceB3fkm2o82NqbuhGsiPtNN75rgr LKjJdYKHFno0YgmkB6aCLn5t+MUr3dGEQTULouEoeYzOtLFz1RdN0q872zbB4h/78F oL9ZkbsJJOaTg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 06/67] xfs: hoist ->create_intent boilerplate to its callsite Date: Mon, 22 Apr 2024 18:25:28 +0200 Message-ID: <20240422163832.858420-8-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: f3fd7f6fce1cc9b8eb59705b27f823330207b7c9 Hoist the dirty flag setting code out of each ->create_intent implementation up to the callsite to reduce boilerplate further. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 6a9ce9241..1be9554e1 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -235,6 +235,8 @@ xfs_defer_create_intent( if (IS_ERR(lip)) return PTR_ERR(lip); + tp->t_flags |= XFS_TRANS_DIRTY; + set_bit(XFS_LI_DIRTY, &lip->li_flags); dfp->dfp_intent = lip; return 1; } From patchwork Mon Apr 22 16:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638687 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 0812C15381C for ; Mon, 22 Apr 2024 16:39: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=1713803959; cv=none; b=NxWu/YCubtqKBmQApCJr4/RTjWJR61WPPfiWhDuRszMiBzyaCGF45XKTlHuojB4rkRb4udmbEd/rr9/L13nH2ROOOxZAkQnaAc/pqLF2WXQee8mv849t5F7GZi7epIG8A8mH9whNR19m+w5JEhogbfRFlJnZeViWrzLqf6I+F6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803959; c=relaxed/simple; bh=HBiWaFGI7jV7wElNVXWmabTaHFC/KAZcBXDR78iSVWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cVSZme8ZFLMB9mJvQ/3C0Y8qx/AzN89/TbScKmxGArzwttdHDnXMYUdiS5rwGqfqnvnjHYZyDKGdlTiYsMQ2j0cks+xbKykoBq186M0/xX5eSTjeCXECDZMQCOXewMSs27fROVO8r4Z9lCTWa3RUcQ1KSOS6N+1Y8T0BSQ8co6k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i9dsPSqn; 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="i9dsPSqn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CC2FC116B1; Mon, 22 Apr 2024 16:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803958; bh=HBiWaFGI7jV7wElNVXWmabTaHFC/KAZcBXDR78iSVWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9dsPSqnacqxIPQFhaFD7aiNuMpQyrfKWTjUYXl1wCc9xK421BkLHY4XLtF+bTspL 7f8JFC6piomMI4lrs2P7cqbzzLbJuTnh+cJ+fbVuXDGxB14CgInfW6bx0879y67Q6k i02i7lcnkKZbvKK/Rr6OyM2KOSsj+gCMCnz0QlflvWgBYoB//HEv2UndlPPcLeWkjQ 5kILmVoxQLnBYmSyZbvloQexKLDVdg4WuE+EkqcP6H9BreXsz4HwQOBwQ13sX3bYtX keswjfcQ7jXAkTgo5g/M54DgIM0bF00r40mIerT0Ov6F9ZYvJl5YkGSHq2unwmljKI MiUsRrzKQq5Uw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 07/67] xfs: use xfs_defer_create_done for the relogging operation Date: Mon, 22 Apr 2024 18:25:29 +0200 Message-ID: <20240422163832.858420-9-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: bd3a88f6b71c7509566b44b7021581191cc11ae3 Now that we have a helper to handle creating a log intent done item and updating all the necessary state flags, use it to reduce boilerplate in the ->iop_relog implementations. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- include/xfs_trans.h | 2 +- libxfs/xfs_defer.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 8371bc7e8..b39f0c22d 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -158,7 +158,7 @@ libxfs_trans_read_buf( } #define xfs_log_item_in_current_chkpt(lip) (false) -#define xfs_trans_item_relog(lip, tp) (NULL) +#define xfs_trans_item_relog(lip, dip, tp) (NULL) /* Contorted mess to make gcc shut up about unused vars. */ #define xlog_grant_push_threshold(log, need) \ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 1be9554e1..43117099c 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -495,7 +495,11 @@ xfs_defer_relog( trace_xfs_defer_relog_intent((*tpp)->t_mountp, dfp); XFS_STATS_INC((*tpp)->t_mountp, defer_relog); - dfp->dfp_intent = xfs_trans_item_relog(dfp->dfp_intent, *tpp); + + xfs_defer_create_done(*tpp, dfp); + dfp->dfp_intent = xfs_trans_item_relog(dfp->dfp_intent, + dfp->dfp_done, *tpp); + dfp->dfp_done = NULL; } if ((*tpp)->t_flags & XFS_TRANS_DIRTY) From patchwork Mon Apr 22 16:25:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638688 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 8A92C153833 for ; Mon, 22 Apr 2024 16:39: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=1713803960; cv=none; b=AhrUTBuaeVZ14/nSpwWhHo1NBUMKuhp1lEsUm1mJaS0rbRe9Yj3sQdtn/1+JbOL9tcsxj0tkuVEaSHWNVdsynKdPCTlW9TjNF+l23xuvcBYfOuDf/mnOCJJeavVY4fRib5i0vU5XHyLdAG42XyuVczD3aIeZ1ivbRMcFNoEOFK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803960; c=relaxed/simple; bh=Eji+OJtqONYtyhzIfG3EfJ57V3Q/0XMnicUQ1HsFk7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pFlkhVTHi9lm4FnN7sv7vOhDvQv0626RjIEkM6uhUILuifdORKfwa/lFYG9FU3zac9DY1TCAuQ0mQTkJ2iSoBl5+H7vrqj+q+iFCn51jCKkWq2VeHuD/FIUOu8yL2FrsiPvmcDUG1XyypckGyqh8HM2H9a5RPrpyhEYORQlYRPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BlTUjNYp; 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="BlTUjNYp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A32AC32782; Mon, 22 Apr 2024 16:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803960; bh=Eji+OJtqONYtyhzIfG3EfJ57V3Q/0XMnicUQ1HsFk7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BlTUjNYpAokW6TCUTmWdNo6DE5nnrlpoyXv7OOyqn0r9KrnMGW/VW8//sWBdOB22a eerqy6U8bYul5oD77XGIAyMS0ouAUIekkDbX3WAzYFWA0jaANCRoa3iUcF0sY57QFw 4r75An0uH/T05Zw4neIl6vT+eNqFBQEI5dkXevWww2AUNl0fqHA0lbPjGbXsU+6xls zrHlwB7t46AOd+tRpKtNNC87J/HI16yGaDGxrxHfr/8+SBhMwErxp8/uUfQQm0UNXv M2N/rRGC5hg1swURL//ymEwb0ZNPAONntTx0jzKQKMnABY2iT2qgAEy9k1/ZF+Oma9 nufAlXg/sgd0g== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 08/67] xfs: clean out XFS_LI_DIRTY setting boilerplate from ->iop_relog Date: Mon, 22 Apr 2024 18:25:30 +0200 Message-ID: <20240422163832.858420-10-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 3e0958be2156d90ef908a1a547b4e27a3ec38da9 Hoist this dirty flag setting to the ->iop_relog callsite to reduce boilerplate. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 43117099c..42e1c9c0c 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -469,6 +469,8 @@ xfs_defer_relog( ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES); list_for_each_entry(dfp, dfops, dfp_list) { + struct xfs_log_item *lip; + /* * If the log intent item for this deferred op is not a part of * the current log checkpoint, relog the intent item to keep @@ -497,9 +499,12 @@ xfs_defer_relog( XFS_STATS_INC((*tpp)->t_mountp, defer_relog); xfs_defer_create_done(*tpp, dfp); - dfp->dfp_intent = xfs_trans_item_relog(dfp->dfp_intent, - dfp->dfp_done, *tpp); + lip = xfs_trans_item_relog(dfp->dfp_intent, dfp->dfp_done, + *tpp); + if (lip) + set_bit(XFS_LI_DIRTY, &lip->li_flags); dfp->dfp_done = NULL; + dfp->dfp_intent = lip; } if ((*tpp)->t_flags & XFS_TRANS_DIRTY) From patchwork Mon Apr 22 16:25:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638689 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 2202F153BF7 for ; Mon, 22 Apr 2024 16:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803962; cv=none; b=aJ4W8IM/nR88gy/P8//uIdO9R2tjeD13FO+QJsLsF0FKE9+3clDGAjsvCRkHkiIuU5zisbeDCWfcVHoKezthBkepjXD1Bv6Ve2D9KDzVH6Wis4GNlSGiy2v5ydupGyCnpqq4SjQt8BLTdJC/D8DvBX4Te9AM0wf89AEaeKnIKYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803962; c=relaxed/simple; bh=upFCa2zekQJMDxaf5T3z9kreVl94PuC7kL4jmDWNqVM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fecfWwMsGtaiN7nFhpuzk6qd2IjPZICp+ODiSP1VtwnyR3Vh77vhBHEvoFhSRJcAJ0ipesNrfnPo+u8v5nIdzX1y37klo5QtYtq6JBP6Xfxbtt3WFf+8+oStMS1yakXxo4rKj3ElDxuzUry9Wa6kP/hBwq5Wn0o8hguNWjN6xM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xe+Mjd7x; 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="Xe+Mjd7x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD31FC116B1; Mon, 22 Apr 2024 16:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803961; bh=upFCa2zekQJMDxaf5T3z9kreVl94PuC7kL4jmDWNqVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xe+Mjd7xs39m9SUUZYF1K/2zg/6MZDbnOQ7l/v5Pp33BMXpKQJ56iAqvCrufNN8na 6uwg3U/usUD7+Y9QmGZ5u4mgOItoRuXqLLEVrp3QQS/j3uwl6yH4oCr8SoZGy/b7sF tChgg5xSFSAexmzZGvFafVPqH6iBlPMi/Dg94CuM39n7iKDDWtOlR2S3KufSHvXVvP 22cfAPSb7ff12uKvPQtqAYVoytFHCCu+egzjeD3a2glMv6Y0QRzKp6WEBLQhraBqGr 3cDNOpb1onn56ugEhbmepyiLxM4ZnTJXpWL0dp/8DSO8251NwWEFKA2kAo41uKWH9t bhw7UE6+lGjXw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 09/67] xfs: hoist xfs_trans_add_item calls to defer ops functions Date: Mon, 22 Apr 2024 18:25:31 +0200 Message-ID: <20240422163832.858420-11-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: b28852a5bd08654634e4e32eb072fba14c5fae26 Remove even more repeated boilerplate. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 42e1c9c0c..27f9938a0 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -208,6 +208,7 @@ xfs_defer_create_done( return; tp->t_flags |= XFS_TRANS_HAS_INTENT_DONE; + xfs_trans_add_item(tp, lip); set_bit(XFS_LI_DIRTY, &lip->li_flags); dfp->dfp_done = lip; } @@ -236,6 +237,7 @@ xfs_defer_create_intent( return PTR_ERR(lip); tp->t_flags |= XFS_TRANS_DIRTY; + xfs_trans_add_item(tp, lip); set_bit(XFS_LI_DIRTY, &lip->li_flags); dfp->dfp_intent = lip; return 1; @@ -501,8 +503,10 @@ xfs_defer_relog( xfs_defer_create_done(*tpp, dfp); lip = xfs_trans_item_relog(dfp->dfp_intent, dfp->dfp_done, *tpp); - if (lip) + if (lip) { + xfs_trans_add_item(*tpp, lip); set_bit(XFS_LI_DIRTY, &lip->li_flags); + } dfp->dfp_done = NULL; dfp->dfp_intent = lip; } From patchwork Mon Apr 22 16:25:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638690 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 568D815381C for ; Mon, 22 Apr 2024 16:39: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=1713803963; cv=none; b=CJ4yd/ir+vIovx8yMiwDK1ig1+uy3Cdoil+B3SD69aa28KvfkS4to/qFyddduzXco8w3stgfaY1E2onDlLtvjbU6l3ETFH4lpUcixKbRdgmlUBGHr5Do73ZueSJQfLr2WYJEY0NbyA60vM+2tnQ/NtRBMwmj62lA0J2+QqCPjL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803963; c=relaxed/simple; bh=OWXNJHlc2Nk06SpPEEfFoSuWCnSHtzrACRhkZXp+T2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qZir3NI/l76OMiep2BWFsHcKJ1BiuxgCetLlsCTf4CGmsEg16fiscQNYAJchcQQQNvVC3qpPfCjU/A9IM2UbZgoh78ADS5ZakJIThmFSnmbS9p0b9xzd9SSmej7n8MVafaHQskFwbjV90jNciBsjms7gZS8geVm191vXmR3Jet0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fbGYiZdv; 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="fbGYiZdv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BC14C113CC; Mon, 22 Apr 2024 16:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803963; bh=OWXNJHlc2Nk06SpPEEfFoSuWCnSHtzrACRhkZXp+T2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbGYiZdv6eLaTWuuV5ShJIDTbTewqqMSqBlvnjXj4mOdlPCZ16tW92aU6IAMfGN3M UbU7aRWxu8JsNcYArLD8V5UInQBAe86ObvqQWzOKNAxUnw+3trYWJmAu3JQ19dPBsj FbjEdSKWcdYBXwwUGZ1TaAxNWzcmxJp2QHkU+xvdSyFx+vu5KINTf6qTH9KGPz8vIW LMTwKu8e/X0zhQsv764EmQK+tqYaSBLU7D4M36Cy2U5inKMKUeMTPm8ixofYFZyu2R M+RdT87IjNjMynitCBN6BZU3PPCjt85lJ8BTAkeq6ndVfak8L/7O8jMV9EYHefHJMk W1aCnOTB+7eVg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 10/67] xfs: move ->iop_relog to struct xfs_defer_op_type Date: Mon, 22 Apr 2024 18:25:32 +0200 Message-ID: <20240422163832.858420-12-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: a49c708f9a445457f6a5905732081871234f61c6 The only log items that need relogging are the ones created for deferred work operations, and the only part of the code base that relogs log items is the deferred work machinery. Move the function pointers. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- include/xfs_trans.h | 1 - libxfs/xfs_defer.c | 31 ++++++++++++++++++++----------- libxfs/xfs_defer.h | 3 +++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index b39f0c22d..ab298ccfe 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -158,7 +158,6 @@ libxfs_trans_read_buf( } #define xfs_log_item_in_current_chkpt(lip) (false) -#define xfs_trans_item_relog(lip, dip, tp) (NULL) /* Contorted mess to make gcc shut up about unused vars. */ #define xlog_grant_push_threshold(log, need) \ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 27f9938a0..29ec0bd81 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -453,6 +453,25 @@ xfs_defer_cancel_list( xfs_defer_pending_cancel_work(mp, dfp); } +static inline void +xfs_defer_relog_intent( + struct xfs_trans *tp, + struct xfs_defer_pending *dfp) +{ + struct xfs_log_item *lip; + const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + + xfs_defer_create_done(tp, dfp); + + lip = ops->relog_intent(tp, dfp->dfp_intent, dfp->dfp_done); + if (lip) { + xfs_trans_add_item(tp, lip); + set_bit(XFS_LI_DIRTY, &lip->li_flags); + } + dfp->dfp_done = NULL; + dfp->dfp_intent = lip; +} + /* * Prevent a log intent item from pinning the tail of the log by logging a * done item to release the intent item; and then log a new intent item. @@ -471,8 +490,6 @@ xfs_defer_relog( ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES); list_for_each_entry(dfp, dfops, dfp_list) { - struct xfs_log_item *lip; - /* * If the log intent item for this deferred op is not a part of * the current log checkpoint, relog the intent item to keep @@ -500,15 +517,7 @@ xfs_defer_relog( trace_xfs_defer_relog_intent((*tpp)->t_mountp, dfp); XFS_STATS_INC((*tpp)->t_mountp, defer_relog); - xfs_defer_create_done(*tpp, dfp); - lip = xfs_trans_item_relog(dfp->dfp_intent, dfp->dfp_done, - *tpp); - if (lip) { - xfs_trans_add_item(*tpp, lip); - set_bit(XFS_LI_DIRTY, &lip->li_flags); - } - dfp->dfp_done = NULL; - dfp->dfp_intent = lip; + xfs_defer_relog_intent(*tpp, dfp); } if ((*tpp)->t_flags & XFS_TRANS_DIRTY) diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index ef86a7f9b..78d6dcd1a 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -59,6 +59,9 @@ struct xfs_defer_op_type { void (*cancel_item)(struct list_head *item); int (*recover_work)(struct xfs_defer_pending *dfp, struct list_head *capture_list); + struct xfs_log_item *(*relog_intent)(struct xfs_trans *tp, + struct xfs_log_item *intent, + struct xfs_log_item *done_item); unsigned int max_items; }; From patchwork Mon Apr 22 16:25:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638691 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 D94C3153BF9 for ; Mon, 22 Apr 2024 16:39:24 +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=1713803964; cv=none; b=GKResCM73TcyE+cuRcErhMTKQ/WV/OcX4aC7FOs2Vqtmx+iAPvaP3OC+Yjukx65DXyuor+bl2soeT5sDeJO5q4QQawPI09shSRfYNPQHJA69MUYUqwFWF4MO8ZHt3FxI4CHoZU0LSdDdGNAv13SNJOqaei36QHAdkJUgtDAYQV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803964; c=relaxed/simple; bh=/ZNJP8rsck9fA/jlPLFkgFDr2wZWdjS/CO+7UWO9OgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOtH50lUit+R/5euqCh1NM0s7emPrJ+tkWhyN9lhOMSFwxHT3qKHuVhbLIJkA3MRn9DTw5eYCxrjXQ3EwIS9si8yr1KVEvJr351pq7jla6uFNwkJHjK+sE/8vQWze0Ibfknp1lmkn5r8o7xpbczXRoQCZpNGM6gucnAZlc0MrG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QgX3bd0s; 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="QgX3bd0s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEB9DC32781; Mon, 22 Apr 2024 16:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803964; bh=/ZNJP8rsck9fA/jlPLFkgFDr2wZWdjS/CO+7UWO9OgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QgX3bd0sSuh19Q6J5XQbIEAPfITZoV0eTj3oKLHnf1mvV0bTMvjILm/VaTf8N5EuT gLMKzsmivXCmcs92mXV/KZsWU8ZQW+xCcs2PR43C0I6Cd6FX6AAQQiwVrNxFCY2KFv ULpp3BpU0XTtnaathjC1SsVZlqe4Q5Cj1O0JOwJAHNUFQLIflv8r/E1pjmasvR3VT3 VBoImzcSZT9OJEyFqk/RINveiWodZfgxA6n6zdW6enSufTcoD7Xiub9Y4vKZnH2WDV vWd0coUkLIFqEK01RS7gkB+oGkmpTiOIifbZ55setjAX0QrNIAtZtXUk1qchVsYcvb oaf4hxJxqEB2A== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 11/67] xfs: make rextslog computation consistent with mkfs Date: Mon, 22 Apr 2024 18:25:33 +0200 Message-ID: <20240422163832.858420-13-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: a6a38f309afc4a7ede01242b603f36c433997780 There's a weird discrepancy in xfsprogs dating back to the creation of the Linux port -- if there are zero rt extents, mkfs will set sb_rextents and sb_rextslog both to zero: sbp->sb_rextslog = (uint8_t)(rtextents ? libxfs_highbit32((unsigned int)rtextents) : 0); However, that's not the check that xfs_repair uses for nonzero rtblocks: if (sb->sb_rextslog != libxfs_highbit32((unsigned int)sb->sb_rextents)) The difference here is that xfs_highbit32 returns -1 if its argument is zero. Unfortunately, this means that in the weird corner case of a realtime volume shorter than 1 rt extent, xfs_repair will immediately flag a freshly formatted filesystem as corrupt. Because mkfs has been writing ondisk artifacts like this for decades, we have to accept that as "correct". TBH, zero rextslog for zero rtextents makes more sense to me anyway. Regrettably, the superblock verifier checks created in commit copied xfs_repair even though mkfs has been writing out such filesystems for ages. Fix the superblock verifier to accept what mkfs spits out; the userspace version of this patch will have to fix xfs_repair as well. Note that the new helper leaves the zeroday bug where the upper 32 bits of sb_rextents is ripped off and fed to highbit32. This leads to a seriously undersized rt summary file, which immediately breaks mkfs: $ hugedisk.sh foo /dev/sdc $(( 0x100000080 * 4096))B $ /sbin/mkfs.xfs -f /dev/sda -m rmapbt=0,reflink=0 -r rtdev=/dev/mapper/foo meta-data=/dev/sda isize=512 agcount=4, agsize=1298176 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=0 bigtime=1 inobtcount=1 nrext64=1 data = bsize=4096 blocks=5192704, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=16384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =/dev/mapper/foo extsz=4096 blocks=4294967424, rtextents=4294967424 Discarding blocks...Done. mkfs.xfs: Error initializing the realtime space [117 - Structure needs cleaning] The next patch will drop support for rt volumes with fewer than 1 or more than 2^32-1 rt extents, since they've clearly been broken forever. Fixes: f8e566c0f5e1f ("xfs: validate the realtime geometry in xfs_validate_sb_common") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_rtbitmap.c | 12 ++++++++++++ libxfs/xfs_rtbitmap.h | 3 +++ libxfs/xfs_sb.c | 3 ++- mkfs/xfs_mkfs.c | 3 +-- repair/sb.c | 3 +-- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index a16efa007..836ace1ba 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -64,6 +64,7 @@ #define xfs_bunmapi libxfs_bunmapi #define xfs_bwrite libxfs_bwrite #define xfs_calc_dquots_per_chunk libxfs_calc_dquots_per_chunk +#define xfs_compute_rextslog libxfs_compute_rextslog #define xfs_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk #define xfs_da_get_buf libxfs_da_get_buf #define xfs_da_hashname libxfs_da_hashname diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index fb0834990..90fe90288 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1128,6 +1128,18 @@ xfs_rtbitmap_blockcount( return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize); } +/* + * Compute the maximum level number of the realtime summary file, as defined by + * mkfs. The use of highbit32 on a 64-bit quantity is a historic artifact that + * prohibits correct use of rt volumes with more than 2^32 extents. + */ +uint8_t +xfs_compute_rextslog( + xfs_rtbxlen_t rtextents) +{ + return rtextents ? xfs_highbit32(rtextents) : 0; +} + /* * Compute the number of rtbitmap words needed to populate every block of a * bitmap that is large enough to track the given number of rt extents. diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index c0637057d..6e5bae324 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -351,6 +351,8 @@ xfs_rtfree_extent( int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, xfs_filblks_t rtlen); +uint8_t xfs_compute_rextslog(xfs_rtbxlen_t rtextents); + xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents); unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp, @@ -369,6 +371,7 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, # define xfs_rtsummary_read_buf(a,b) (-ENOSYS) # define xfs_rtbuf_cache_relse(a) (0) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) +# define xfs_compute_rextslog(rtx) (0) static inline xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) { diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 1ebdb7ec4..95a29bf1f 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -23,6 +23,7 @@ #include "xfs_da_format.h" #include "xfs_health.h" #include "xfs_ag.h" +#include "xfs_rtbitmap.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace. @@ -507,7 +508,7 @@ xfs_validate_sb_common( NBBY * sbp->sb_blocksize); if (sbp->sb_rextents != rexts || - sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) || + sbp->sb_rextslog != xfs_compute_rextslog(rexts) || sbp->sb_rbmblocks != rbmblocks) { xfs_notice(mp, "realtime geometry sanity check failed"); diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index fcbf54132..e48624bbd 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3693,8 +3693,7 @@ finish_superblock_setup( sbp->sb_agcount = (xfs_agnumber_t)cfg->agcount; sbp->sb_rbmblocks = cfg->rtbmblocks; sbp->sb_logblocks = (xfs_extlen_t)cfg->logblocks; - sbp->sb_rextslog = (uint8_t)(cfg->rtextents ? - libxfs_highbit32((unsigned int)cfg->rtextents) : 0); + sbp->sb_rextslog = libxfs_compute_rextslog(cfg->rtextents); sbp->sb_inprogress = 1; /* mkfs is in progress */ sbp->sb_imax_pct = cfg->imaxpct; sbp->sb_icount = 0; diff --git a/repair/sb.c b/repair/sb.c index dedac53af..384840db1 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -475,8 +475,7 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) if (sb->sb_rblocks / sb->sb_rextsize != sb->sb_rextents) return(XR_BAD_RT_GEO_DATA); - if (sb->sb_rextslog != - libxfs_highbit32((unsigned int)sb->sb_rextents)) + if (sb->sb_rextslog != libxfs_compute_rextslog(sb->sb_rextents)) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rbmblocks != (xfs_extlen_t) howmany(sb->sb_rextents, From patchwork Mon Apr 22 16:25:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638692 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 6B728154425 for ; Mon, 22 Apr 2024 16:39:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803966; cv=none; b=JLK+rcV5SHl+lGPTe8nZzSSUmCGNvA0XXycPP4fa30PMWG04HQWLXFCZFyJSKTpu2in4AsASQPS7UEWUF+YxaaDTTr8gwTHhM02roiDStX37wMlAjZl+/UKuon3t1jYyfhz3o6m4OUBTE4Z7HVnUCovlocW7s9Imt4llXyhagmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803966; c=relaxed/simple; bh=JW+rY1bP+8Phc2+wiHnjx3++O5tqTappEN6lUnU5e5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cg7UaXszl5MdhJavCOqiuz7XX7J7Hh8Ntj5CcxNX8pcxSunKx4DaJmtLXPBzO/ONDINgs0jIfVqYC0Cb19sFFgusjkuMpuIDn6OeRo5s2uRt+QBk1l5axyPTxvUdi6/vQK30/skTHFgAErhLbKFN9pUDx6woeipy3NnclSRU23s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nxuagD4E; 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="nxuagD4E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D823C32782; Mon, 22 Apr 2024 16:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803966; bh=JW+rY1bP+8Phc2+wiHnjx3++O5tqTappEN6lUnU5e5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nxuagD4ERz9v/Lfcth9cSCj3MvpGYo3TRhX+j2COulkZdZyMsauTmSXv+XfmczBza mSxvrFpqLKOamAC/K/SWR9eHELNJC3hiw6cS+0MmPkIgMnDgZavOeJ8uxaf8xsf1+2 /Sa7cUkfXqAqY6rfuR6LnjjYjGcPIzRE2UOe97tSocYwLXsejk6KUzM11p4O5y7Lz7 IdVlvDRi6JRwjrY8t/MLLywkUjw6N87mCudIGABS96IhZ4WXUT4d9evST9sGkeb3Sc 2sA/EEXq6qcbypJ+5dJ3NgXWgEoKEDE9EvZFg5aY2gF+efXW8XXHtKZM2oBEh0i+/b BJknEBQfZwoeQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 12/67] xfs: fix 32-bit truncation in xfs_compute_rextslog Date: Mon, 22 Apr 2024 18:25:34 +0200 Message-ID: <20240422163832.858420-14-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: cf8f0e6c1429be7652869059ea44696b72d5b726 It's quite reasonable that some customer somewhere will want to configure a realtime volume with more than 2^32 extents. If they try to do this, the highbit32() call will truncate the upper bits of the xfs_rtbxlen_t and produce the wrong value for rextslog. This in turn causes the rsumlevels to be wrong, which results in a realtime summary file that is the wrong length. Fix that. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 90fe90288..726543abb 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1130,14 +1130,16 @@ xfs_rtbitmap_blockcount( /* * Compute the maximum level number of the realtime summary file, as defined by - * mkfs. The use of highbit32 on a 64-bit quantity is a historic artifact that - * prohibits correct use of rt volumes with more than 2^32 extents. + * mkfs. The historic use of highbit32 on a 64-bit quantity prohibited correct + * use of rt volumes with more than 2^32 extents. */ uint8_t xfs_compute_rextslog( xfs_rtbxlen_t rtextents) { - return rtextents ? xfs_highbit32(rtextents) : 0; + if (!rtextents) + return 0; + return xfs_highbit64(rtextents); } /* From patchwork Mon Apr 22 16:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638693 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 33C9115381C for ; Mon, 22 Apr 2024 16:39:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803968; cv=none; b=vGNXXuU5ZUT9VX3AWr4bOmmdSd6J7NSKocRQYU6SBUpzMb5yfGK9POq4uMr7bNjgGTbrg+nP6cojzTO6sxfHxqiEWUdmELQUkFvZD8UVrUSiks011sEpQb6Q6M54QOgfOmidkVgAUmbgJQgALWwRsyh/+cHImDGPts0jsOzzD+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803968; c=relaxed/simple; bh=SsbkW/nDB4LrmXy4NJ3a7+CVTLKra3ZgHu7AjUdXaB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SK1EZ/NJvoy1WMaUBSS9pRB9tOkOjJJo59+eQ3KQ7MxS8NtuZC6nZV2L+1gDPldEih4dNxaCP8ZUqrELj0srtRqgt1P5rO1K41QLFBCqr2Q6pmaeEMn5GqAeF4JPmLMIzDB6HrU9i2asJUdl4wKf2AZgjmRhzzDXFNWr0VBwKC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H8ptaThz; 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="H8ptaThz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D034BC32781; Mon, 22 Apr 2024 16:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803967; bh=SsbkW/nDB4LrmXy4NJ3a7+CVTLKra3ZgHu7AjUdXaB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H8ptaThzaphTjMbJvDMxL5N9s3GiMPRqDmlrm+vOZfz9iGgJJDo5FfoBtFuqu+1x8 MIVMQQb4CqHxZQHbzUNWuf3D2IFB5LtUPNlT6nby+IkoGhv2vz2nRAlcXYQqJ8c3Zl RsdVvaOO2dB9pjzEWVDrkOsAtDLLTlSe4J81ptjkRGEUFO5hzVcHyS8zJ+PoTgooe6 kcS5zp1u9TvC5othPpAqKiy3xWcAXGw37j3oAiTA0pa+HBS+xnH7xmWx6g+EwAJ2LS X2bq01oCrTiUJ209OK/u5NuAR9cQT42RvV2Sq3EOkfEH/oSC5mItOGuRlvci0mjcFX KLdNWili1Fn/Q== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 13/67] xfs: don't allow overly small or large realtime volumes Date: Mon, 22 Apr 2024 18:25:35 +0200 Message-ID: <20240422163832.858420-15-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e14293803f4e84eb23a417b462b56251033b5a66 Don't allow realtime volumes that are less than one rt extent long. This has been broken across 4 LTS kernels with nobody noticing, so let's just disable it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.h | 13 +++++++++++++ libxfs/xfs_sb.c | 3 ++- mkfs/xfs_mkfs.c | 6 ++++++ repair/sb.c | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 6e5bae324..1c84b52de 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -353,6 +353,18 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, uint8_t xfs_compute_rextslog(xfs_rtbxlen_t rtextents); +/* Do we support an rt volume having this number of rtextents? */ +static inline bool +xfs_validate_rtextents( + xfs_rtbxlen_t rtextents) +{ + /* No runt rt volumes */ + if (rtextents == 0) + return false; + + return true; +} + xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents); unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp, @@ -372,6 +384,7 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, # define xfs_rtbuf_cache_relse(a) (0) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) # define xfs_compute_rextslog(rtx) (0) +# define xfs_validate_rtextents(rtx) (false) static inline xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) { diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 95a29bf1f..7a72d5a17 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -507,7 +507,8 @@ xfs_validate_sb_common( rbmblocks = howmany_64(sbp->sb_rextents, NBBY * sbp->sb_blocksize); - if (sbp->sb_rextents != rexts || + if (!xfs_validate_rtextents(rexts) || + sbp->sb_rextents != rexts || sbp->sb_rextslog != xfs_compute_rextslog(rexts) || sbp->sb_rbmblocks != rbmblocks) { xfs_notice(mp, diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index e48624bbd..d19f2a2fb 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3025,6 +3025,12 @@ reported by the device (%u).\n"), } cfg->rtextents = cfg->rtblocks / cfg->rtextblocks; + if (cfg->rtextents == 0) { + fprintf(stderr, +_("cannot have a rt subvolume with zero extents\n")); + usage(); + } + cfg->rtbmblocks = (xfs_extlen_t)howmany(cfg->rtextents, NBBY * cfg->blocksize); } diff --git a/repair/sb.c b/repair/sb.c index 384840db1..a26fc149f 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -475,6 +475,9 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) if (sb->sb_rblocks / sb->sb_rextsize != sb->sb_rextents) return(XR_BAD_RT_GEO_DATA); + if (sb->sb_rextents == 0) + return(XR_BAD_RT_GEO_DATA); + if (sb->sb_rextslog != libxfs_compute_rextslog(sb->sb_rextents)) return(XR_BAD_RT_GEO_DATA); From patchwork Mon Apr 22 16:25:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638694 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 794E215383C for ; Mon, 22 Apr 2024 16:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803969; cv=none; b=a+i6/XyXH1obfx3U9BR9jEyPv+er3Mdkrk2pzC4SxQp+sa/oPPCCVohqCP9vrnM3cCfmEPTCeIMoOCW5lZPKJ7ao7pZdw7dQMwCN5AuS/kX+KDT7Y++eQ4gulyiXwa83IFYsvogx9OeJLU22VNJc2JzaY2yQj0qNM6cyDvwWvck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803969; c=relaxed/simple; bh=xuG2F8nmPDhPdSLuNWWFFycgkf8rqnwpQ0kQBe7Aj3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ews5VhWJg9G0t0gfWZn+qIgD2jX5cS3sagHqLrCfl7bti7ltBMLnVL0/74qDnfsY1TIURRS3xzUwWxSrX03V3dyp64oixElrzjA/IQWMwctfvLmw5JeUmftt+1LjHZTvlfNI5Mz/1G5S4PC106etJSVXrmuEn5xGZlSkiz3D53Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CZ2/O5M4; 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="CZ2/O5M4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B013C32783; Mon, 22 Apr 2024 16:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803969; bh=xuG2F8nmPDhPdSLuNWWFFycgkf8rqnwpQ0kQBe7Aj3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZ2/O5M4/u3dsCdRjdg5NS6gWv8JYoDKsk7hk/L3cur0k4VPKw2Hg1GnR3gbvxuG0 lyrzmxQAoShpAt/r+hIbWkZ5Dix2iJ8RGo0Q3nbWWV3eXzuMDA127p6YhzkmPtPDXE /LyEwu8Roj5fBytFSSbP9F1knKLIzdn4TXNGgquej+lUsfjI1zP2IuBuTjTHr3xH5+ gCl2pYlrk6xxTpFhCEyY2pjTAEAtPROP39cxujIZ2LcxXyxWcHZ85NFlCd8h9mme9o e7ayFCUHI/cuf8/QOGX/vqeelip0FhyASoghSWo+Si3VbaXbcoXaWRevBT4BjGfHf5 XKVio3Yc0lmkA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 14/67] xfs: elide ->create_done calls for unlogged deferred work Date: Mon, 22 Apr 2024 18:25:36 +0200 Message-ID: <20240422163832.858420-16-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 9c07bca793b4ff9f0b7871e2a928a1b28b8fa4e3 Extended attribute updates use the deferred work machinery to manage state across a chain of smaller transactions. All previous deferred work users have employed log intent items and log done items to manage restarting of interrupted operations, which means that ->create_intent sets dfp_intent to a log intent item and ->create_done uses that item to create a log intent done item. However, xattrs have used the INCOMPLETE flag to deal with the lack of recovery support for an interrupted transaction chain. Log items are optional if the xattr update caller didn't set XFS_DA_OP_LOGGED to require a restartable sequence. In other words, ->create_intent can return NULL to say that there's no log intent item. If that's the case, no log intent done item should be created. Clean up xfs_defer_create_done not to do this, so that the ->create_done functions don't have to check for non-null dfp_intent themselves. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 29ec0bd81..722ff6a77 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -195,6 +195,10 @@ xfs_defer_create_done( const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; struct xfs_log_item *lip; + /* If there is no log intent item, there can be no log done item. */ + if (!dfp->dfp_intent) + return; + /* * Mark the transaction dirty, even on error. This ensures the * transaction is aborted, which: From patchwork Mon Apr 22 16:25:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638695 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 65D54153BC1 for ; Mon, 22 Apr 2024 16:39: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=1713803972; cv=none; b=paDIAIuiT1Z5PHBUZ9eh7kFIziBIk6cLWEb1yU/YEgJsfwUMyk4fv5lWWR5MxNhTWnrboL01GcJ6LUZEFbmtmVGz3cR+9+IqmPw7s/co00UO5FO/aLhGXA4dlcW/QgUzlLJF3o6SOd0FpDYJ37cB2uzPQLY4Eue21uIneAaHgAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803972; c=relaxed/simple; bh=0PdgUgl89r6jvvmF9cdoUhVzmZCeluXFWjgFeNVrlYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2j5WRkqc/IA0gcM+a2Q2CZy6UBhj1ho2QmHQX5NsZp4kkxtY2CAMW91bbmganLcgJDNqOq6HcrymGYuw0KADkQz8wZgGegUKBAcwUX4AiiSQhphiUxqN4/nc7bfSUhK5z5+1eVu2HY5h6viU2+PUBwbqDQF2+dRFyjEtjvnmFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NefK33q1; 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="NefK33q1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E239BC113CC; Mon, 22 Apr 2024 16:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803970; bh=0PdgUgl89r6jvvmF9cdoUhVzmZCeluXFWjgFeNVrlYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NefK33q17/fO3Y1MWqrqzT9t7fxkw477CfdUmuCvsnwq2G3fqk9/p3zwtgiuCtW8r N51ga/1ki5lSpnkLiUIs/I++nel2hHXtF3puhOzzn22txMwGJhwuz33mkLDV8V/py+ ltaYfkzD+yvbriTVweA1MHZYVw+kUEKCFV3qsI48nKKE9hHeV1TxSOo5lpQYIQwWeH tI13ivB6Zg6V9kYj6NZCTZW6RGlxtPKOOFLkzZWRc3TBWyLEEHOZU3dRZI49lpR8mB gZE/ES1Ivy5uylKOThe2evlRN7fp81FN8DlziZbSmQefH41eDwjwWNfSmHonHIo0kl FtW7Heo9jNoLA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 15/67] xfs: don't append work items to logged xfs_defer_pending objects Date: Mon, 22 Apr 2024 18:25:37 +0200 Message-ID: <20240422163832.858420-17-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 6b126139401a2284402d7c38fe3168d5a26da41d When someone tries to add a deferred work item to xfs_defer_add, it will try to attach the work item to the most recently added xfs_defer_pending object attached to the transaction. However, it doesn't check if the pending object has a log intent item attached to it. This is incorrect behavior because we cannot add more work to an object that has already been committed to the ondisk log. Therefore, change the behavior not to append to pending items with a non null dfp_intent. In practice this has not been an issue because the only way xfs_defer_add gets called after log intent items have been the @dop_pending isolation in xfs_defer_finish_noroll protects the pending items that have already been logged. However, the next patch will add the ability to pause a deferred extent free object during online btree rebuilding, and any new extfree work items need to have their own pending event. While we're at it, hoist the predicate to its own static inline function for readability. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 61 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 722ff6a77..200d1b300 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -689,6 +689,51 @@ xfs_defer_cancel( xfs_defer_cancel_list(mp, &tp->t_dfops); } +/* + * Return the last pending work item attached to this transaction if it matches + * the deferred op type. + */ +static inline struct xfs_defer_pending * +xfs_defer_find_last( + struct xfs_trans *tp, + enum xfs_defer_ops_type type, + const struct xfs_defer_op_type *ops) +{ + struct xfs_defer_pending *dfp = NULL; + + /* No dfops at all? */ + if (list_empty(&tp->t_dfops)) + return NULL; + + dfp = list_last_entry(&tp->t_dfops, struct xfs_defer_pending, + dfp_list); + + /* Wrong type? */ + if (dfp->dfp_type != type) + return NULL; + return dfp; +} + +/* + * Decide if we can add a deferred work item to the last dfops item attached + * to the transaction. + */ +static inline bool +xfs_defer_can_append( + struct xfs_defer_pending *dfp, + const struct xfs_defer_op_type *ops) +{ + /* Already logged? */ + if (dfp->dfp_intent) + return false; + + /* Already full? */ + if (ops->max_items && dfp->dfp_count >= ops->max_items) + return false; + + return true; +} + /* Add an item for later deferred processing. */ void xfs_defer_add( @@ -702,19 +747,9 @@ xfs_defer_add( ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); - /* - * Add the item to a pending item at the end of the intake list. - * If the last pending item has the same type, reuse it. Else, - * create a new pending item at the end of the intake list. - */ - if (!list_empty(&tp->t_dfops)) { - dfp = list_last_entry(&tp->t_dfops, - struct xfs_defer_pending, dfp_list); - if (dfp->dfp_type != type || - (ops->max_items && dfp->dfp_count >= ops->max_items)) - dfp = NULL; - } - if (!dfp) { + dfp = xfs_defer_find_last(tp, type, ops); + if (!dfp || !xfs_defer_can_append(dfp, ops)) { + /* Create a new pending item at the end of the intake list. */ dfp = kmem_cache_zalloc(xfs_defer_pending_cache, GFP_NOFS | __GFP_NOFAIL); dfp->dfp_type = type; From patchwork Mon Apr 22 16:25:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638696 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 8C6A8154422 for ; Mon, 22 Apr 2024 16:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803972; cv=none; b=I9oVMRneLmOxQUcZQ2zVT2BnwwZFKezm+Ph7PUTsE9j1vdyK6qO3JclIl7/WlPCxpgOS8TPGC9vaDBoZ+cGtAEb5WDcmyXUXiS/fSTHHNRVx0/PcZi7vO2qJAAQkACQzEj+KEV3zDffiyyyDPDPBEAjIZ9g4E3BEnirtStK3ULo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803972; c=relaxed/simple; bh=pbAN7dx+RxtgDdDvwdeoCjmiAJ/KR1aLUZTp7B29t8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPJNpmOZ7Ge/KAk8k8NuNbKAhQ6w41g7vRIGUaGEUFfH0oVxE+UZLPs6ATvMhTvh8VFLlLARoQp7g6BqGcDbEUqqXwyTf90z2U+ydWGYCqvVjyCmd6vZTJR/AaR2CzyzdI+XnYfQp1AePmS7wLrJZMoZVpdKMRRfZIeSFjPvhEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P8DkbyR8; 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="P8DkbyR8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7108CC32782; Mon, 22 Apr 2024 16:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803972; bh=pbAN7dx+RxtgDdDvwdeoCjmiAJ/KR1aLUZTp7B29t8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8DkbyR8LjcFOsWvHqU34OAynNtl2lw6tjOUkEkjMjuuFdq2WOd3UOQ/ylT6D56ye Wy2AiAJPwm0+VZQdNjGEPYf9DZdO8TgfccyzkEafL+j37bcma5JDA/7P5lUPnXRb75 H3slp/FmMB3/Xdrgb4EiAR17rh2O4WSkcatQeN5IoCGJ7CCH/sXQktOBhorLbOOO0A dk9JPQf6JtJbfBIYr0zQ6yy11QVg2+jQiPeaA0rgf0rNRe5cUnoUmX45goZW27sLLl pmZi5X+NoJlMURIB7L3tgm7QKcB/KDSzW3elDNoWWd7WkxLUe3iwbGGuyFkmTZQ3Xl b4bUWiO6A5LbQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 16/67] xfs: allow pausing of pending deferred work items Date: Mon, 22 Apr 2024 18:25:38 +0200 Message-ID: <20240422163832.858420-18-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 4dffb2cbb4839fd6f9bbac0b3fd06cc9015cbb9b Traditionally, all pending deferred work attached to a transaction is finished when one of the xfs_defer_finish* functions is called. However, online repair wants to be able to allocate space for a new data structure, format a new metadata structure into the allocated space, and As a hedge against system crashes during repairs, we also want to log some EFI items for the allocated space speculatively, and cancel them if we elect to commit the new data structure. Therefore, introduce the idea of pausing a pending deferred work item. Log intent items are still created for paused items and relogged as necessary. However, paused items are pushed onto a side list before we start calling ->finish_item, and the whole list is reattach to the transaction afterwards. New work items are never attached to paused pending items. Modify xfs_defer_cancel to clean up pending deferred work items holding a log intent item but not a log intent done item, since that is now possible. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- include/list.h | 6 +++ include/xfs_trace.h | 3 ++ libxfs/xfs_defer.c | 97 +++++++++++++++++++++++++++++++++++++++------ libxfs/xfs_defer.h | 17 +++++++- 4 files changed, 109 insertions(+), 14 deletions(-) diff --git a/include/list.h b/include/list.h index e59cbd537..52b53c7a3 100644 --- a/include/list.h +++ b/include/list.h @@ -152,6 +152,12 @@ static inline void list_splice_init(struct list_head *list, #define list_first_entry(ptr, type, member) \ list_entry((ptr)->next, type, member) +#define list_first_entry_or_null(ptr, type, member) ({ \ + struct list_head *head__ = (ptr); \ + struct list_head *pos__ = READ_ONCE(head__->next); \ + pos__ != head__ ? list_entry(pos__, type, member) : NULL; \ +}) + #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index c79a4bd74..06d6aa950 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -337,5 +337,8 @@ #define trace_xfs_fs_mark_healthy(a,b) ((void) 0) #define trace_xlog_intent_recovery_failed(...) ((void) 0) +#define trace_xfs_defer_isolate_paused(...) ((void) 0) +#define trace_xfs_defer_item_pause(...) ((void) 0) +#define trace_xfs_defer_item_unpause(...) ((void) 0) #endif /* __TRACE_H__ */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 200d1b300..58ad1881d 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -481,7 +481,7 @@ xfs_defer_relog_intent( * done item to release the intent item; and then log a new intent item. * The caller should provide a fresh transaction and roll it after we're done. */ -static int +static void xfs_defer_relog( struct xfs_trans **tpp, struct list_head *dfops) @@ -523,10 +523,6 @@ xfs_defer_relog( xfs_defer_relog_intent(*tpp, dfp); } - - if ((*tpp)->t_flags & XFS_TRANS_DIRTY) - return xfs_defer_trans_roll(tpp); - return 0; } /* @@ -582,6 +578,24 @@ out: return error; } +/* Move all paused deferred work from @tp to @paused_list. */ +static void +xfs_defer_isolate_paused( + struct xfs_trans *tp, + struct list_head *paused_list) +{ + struct xfs_defer_pending *dfp; + struct xfs_defer_pending *pli; + + list_for_each_entry_safe(dfp, pli, &tp->t_dfops, dfp_list) { + if (!(dfp->dfp_flags & XFS_DEFER_PAUSED)) + continue; + + list_move_tail(&dfp->dfp_list, paused_list); + trace_xfs_defer_isolate_paused(tp->t_mountp, dfp); + } +} + /* * Finish all the pending work. This involves logging intent items for * any work items that wandered in since the last transaction roll (if @@ -597,6 +611,7 @@ xfs_defer_finish_noroll( struct xfs_defer_pending *dfp = NULL; int error = 0; LIST_HEAD(dop_pending); + LIST_HEAD(dop_paused); ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES); @@ -615,6 +630,8 @@ xfs_defer_finish_noroll( */ int has_intents = xfs_defer_create_intents(*tp); + xfs_defer_isolate_paused(*tp, &dop_paused); + list_splice_init(&(*tp)->t_dfops, &dop_pending); if (has_intents < 0) { @@ -627,22 +644,33 @@ xfs_defer_finish_noroll( goto out_shutdown; /* Relog intent items to keep the log moving. */ - error = xfs_defer_relog(tp, &dop_pending); - if (error) - goto out_shutdown; + xfs_defer_relog(tp, &dop_pending); + xfs_defer_relog(tp, &dop_paused); + + if ((*tp)->t_flags & XFS_TRANS_DIRTY) { + error = xfs_defer_trans_roll(tp); + if (error) + goto out_shutdown; + } } - dfp = list_first_entry(&dop_pending, struct xfs_defer_pending, - dfp_list); + dfp = list_first_entry_or_null(&dop_pending, + struct xfs_defer_pending, dfp_list); + if (!dfp) + break; error = xfs_defer_finish_one(*tp, dfp); if (error && error != -EAGAIN) goto out_shutdown; } + /* Requeue the paused items in the outgoing transaction. */ + list_splice_tail_init(&dop_paused, &(*tp)->t_dfops); + trace_xfs_defer_finish_done(*tp, _RET_IP_); return 0; out_shutdown: + list_splice_tail_init(&dop_paused, &dop_pending); xfs_defer_trans_abort(*tp, &dop_pending); xfs_force_shutdown((*tp)->t_mountp, SHUTDOWN_CORRUPT_INCORE); trace_xfs_defer_finish_error(*tp, error); @@ -655,6 +683,9 @@ int xfs_defer_finish( struct xfs_trans **tp) { +#ifdef DEBUG + struct xfs_defer_pending *dfp; +#endif int error; /* @@ -674,7 +705,10 @@ xfs_defer_finish( } /* Reset LOWMODE now that we've finished all the dfops. */ - ASSERT(list_empty(&(*tp)->t_dfops)); +#ifdef DEBUG + list_for_each_entry(dfp, &(*tp)->t_dfops, dfp_list) + ASSERT(dfp->dfp_flags & XFS_DEFER_PAUSED); +#endif (*tp)->t_flags &= ~XFS_TRANS_LOWMODE; return 0; } @@ -686,6 +720,7 @@ xfs_defer_cancel( struct xfs_mount *mp = tp->t_mountp; trace_xfs_defer_cancel(tp, _RET_IP_); + xfs_defer_trans_abort(tp, &tp->t_dfops); xfs_defer_cancel_list(mp, &tp->t_dfops); } @@ -727,6 +762,10 @@ xfs_defer_can_append( if (dfp->dfp_intent) return false; + /* Paused items cannot absorb more work */ + if (dfp->dfp_flags & XFS_DEFER_PAUSED) + return NULL; + /* Already full? */ if (ops->max_items && dfp->dfp_count >= ops->max_items) return false; @@ -735,7 +774,7 @@ xfs_defer_can_append( } /* Add an item for later deferred processing. */ -void +struct xfs_defer_pending * xfs_defer_add( struct xfs_trans *tp, enum xfs_defer_ops_type type, @@ -762,6 +801,7 @@ xfs_defer_add( xfs_defer_add_item(dfp, li); trace_xfs_defer_add_item(tp->t_mountp, dfp, li); + return dfp; } /* @@ -1087,3 +1127,36 @@ xfs_defer_destroy_item_caches(void) xfs_rmap_intent_destroy_cache(); xfs_defer_destroy_cache(); } + +/* + * Mark a deferred work item so that it will be requeued indefinitely without + * being finished. Caller must ensure there are no data dependencies on this + * work item in the meantime. + */ +void +xfs_defer_item_pause( + struct xfs_trans *tp, + struct xfs_defer_pending *dfp) +{ + ASSERT(!(dfp->dfp_flags & XFS_DEFER_PAUSED)); + + dfp->dfp_flags |= XFS_DEFER_PAUSED; + + trace_xfs_defer_item_pause(tp->t_mountp, dfp); +} + +/* + * Release a paused deferred work item so that it will be finished during the + * next transaction roll. + */ +void +xfs_defer_item_unpause( + struct xfs_trans *tp, + struct xfs_defer_pending *dfp) +{ + ASSERT(dfp->dfp_flags & XFS_DEFER_PAUSED); + + dfp->dfp_flags &= ~XFS_DEFER_PAUSED; + + trace_xfs_defer_item_unpause(tp->t_mountp, dfp); +} diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 78d6dcd1a..b0284154f 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -34,11 +34,24 @@ struct xfs_defer_pending { struct xfs_log_item *dfp_intent; /* log intent item */ struct xfs_log_item *dfp_done; /* log done item */ unsigned int dfp_count; /* # extent items */ + unsigned int dfp_flags; enum xfs_defer_ops_type dfp_type; }; -void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type, - struct list_head *h); +/* + * Create a log intent item for this deferred item, but don't actually finish + * the work. Caller must clear this before the final transaction commit. + */ +#define XFS_DEFER_PAUSED (1U << 0) + +#define XFS_DEFER_PENDING_STRINGS \ + { XFS_DEFER_PAUSED, "paused" } + +void xfs_defer_item_pause(struct xfs_trans *tp, struct xfs_defer_pending *dfp); +void xfs_defer_item_unpause(struct xfs_trans *tp, struct xfs_defer_pending *dfp); + +struct xfs_defer_pending *xfs_defer_add(struct xfs_trans *tp, + enum xfs_defer_ops_type type, struct list_head *h); int xfs_defer_finish_noroll(struct xfs_trans **tp); int xfs_defer_finish(struct xfs_trans **tp); int xfs_defer_finish_one(struct xfs_trans *tp, struct xfs_defer_pending *dfp); From patchwork Mon Apr 22 16:25:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638697 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 7519215383C for ; Mon, 22 Apr 2024 16:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803974; cv=none; b=sOPx6LO67v8LQ60WP8qZoWipcQigGO9gagiXkES3bzAX/B2nl4f6gDJ1oyGN6MPyRvlZxX67j5YwmPK25PjiroLV21GviygDN7WRd3DkUhXz63dhDt3mgToD4ikWRQw05a3EuBCflWR9U/lKa8wtZk7MrclFxsaZq+Grsa9jdWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803974; c=relaxed/simple; bh=VjVTw0kE7eg/n0HwL21q1TNCTqm0EpaQViI9DgjXOQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aZeVIyn2kP2hi9byS9W+Fgy74P4kvSrAee91lJcZNKr0NVIxj8v34hQdhh+81Fa9xsHNvtBCxzLKYGP/EHu0ErV7B2t47B1zxEO1xe4EHNVVohjsZGiXAMkuJQMBO2Skq9o8nqFfRum53LBRO5P/qlSX885v4C5WRbPg/9KMtzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LfutVlob; 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="LfutVlob" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE7A9C32783; Mon, 22 Apr 2024 16:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803974; bh=VjVTw0kE7eg/n0HwL21q1TNCTqm0EpaQViI9DgjXOQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfutVlob++C+zaTuNX4R1OJ9xS7YkTaUc2e6NUMiZC/BzgzDBRlMB5/WaihNKDkkL eM53agCFeodMixAamyAg3SpRwlPJ3a+PpmZnFHGvWWfPlgaklohORLtyrUlleZTylA lA7jBK+SpKkqUD0kzI4YsSrIhYffQ0Sc6Y1Q5eNNCuHEFa/mzcgQ/NIMWEHDnr68BG 3zzsIzGzNH4gV69UAmjbQVmwyZ8V7qJ08IyoqEe+aV20wRNrtqOBvERzzq6Ee5KEwA l/lrYrBR5DTnpA6c2eO3JhlareZPRSynkLqRowqV2cWL+wYpdfHDRqkPmsHw7zY6Ib rkzmIWUV9m/fA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 17/67] xfs: remove __xfs_free_extent_later Date: Mon, 22 Apr 2024 18:25:39 +0200 Message-ID: <20240422163832.858420-19-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 4c88fef3af4a51c2cdba6a28237e98da4873e8dc xfs_free_extent_later is a trivial helper, so remove it to reduce the amount of thinking required to understand the deferred freeing interface. This will make it easier to introduce automatic reaping of speculative allocations in the next patch. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 2 +- libxfs/xfs_alloc.c | 2 +- libxfs/xfs_alloc.h | 14 +------------- libxfs/xfs_bmap.c | 4 ++-- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_ialloc.c | 5 +++-- libxfs/xfs_ialloc_btree.c | 2 +- libxfs/xfs_refcount.c | 6 +++--- libxfs/xfs_refcount_btree.c | 2 +- 9 files changed, 14 insertions(+), 25 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index ac34a1c23..bdb8a08bb 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -982,7 +982,7 @@ xfs_ag_shrink_space( if (err2 != -ENOSPC) goto resv_err; - err2 = __xfs_free_extent_later(*tpp, args.fsbno, delta, NULL, + err2 = xfs_free_extent_later(*tpp, args.fsbno, delta, NULL, XFS_AG_RESV_NONE, true); if (err2) goto resv_err; diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 7ac7c2f6c..0a2404466 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2519,7 +2519,7 @@ xfs_defer_agfl_block( * The list is maintained sorted (by block number). */ int -__xfs_free_extent_later( +xfs_free_extent_later( struct xfs_trans *tp, xfs_fsblock_t bno, xfs_filblks_t len, diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 6bb8d295c..6b95d1d8a 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -231,7 +231,7 @@ xfs_buf_to_agfl_bno( return bp->b_addr; } -int __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno, +int xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno, xfs_filblks_t len, const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type, bool skip_discard); @@ -256,18 +256,6 @@ void xfs_extent_free_get_group(struct xfs_mount *mp, #define XFS_EFI_ATTR_FORK (1U << 1) /* freeing attr fork block */ #define XFS_EFI_BMBT_BLOCK (1U << 2) /* freeing bmap btree block */ -static inline int -xfs_free_extent_later( - struct xfs_trans *tp, - xfs_fsblock_t bno, - xfs_filblks_t len, - const struct xfs_owner_info *oinfo, - enum xfs_ag_resv_type type) -{ - return __xfs_free_extent_later(tp, bno, len, oinfo, type, false); -} - - extern struct kmem_cache *xfs_extfree_item_cache; int __init xfs_extfree_intent_init_cache(void); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 8fde0dc25..8c553d22c 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -569,7 +569,7 @@ xfs_bmap_btree_to_extents( xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork); error = xfs_free_extent_later(cur->bc_tp, cbno, 1, &oinfo, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); if (error) return error; @@ -5212,7 +5212,7 @@ xfs_bmap_del_extent_real( if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { xfs_refcount_decrease_extent(tp, del); } else { - error = __xfs_free_extent_later(tp, del->br_startblock, + error = xfs_free_extent_later(tp, del->br_startblock, del->br_blockcount, NULL, XFS_AG_RESV_NONE, ((bflags & XFS_BMAPI_NODISCARD) || diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 925cc153b..c4d5c8a64 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -270,7 +270,7 @@ xfs_bmbt_free_block( xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_ino.whichfork); error = xfs_free_extent_later(cur->bc_tp, fsbno, 1, &oinfo, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); if (error) return error; diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index a95675b1d..14826280d 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1849,7 +1849,7 @@ xfs_difree_inode_chunk( return xfs_free_extent_later(tp, XFS_AGB_TO_FSB(mp, agno, sagbno), M_IGEO(mp)->ialloc_blks, &XFS_RMAP_OINFO_INODES, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); } /* holemask is only 16-bits (fits in an unsigned long) */ @@ -1895,7 +1895,8 @@ xfs_difree_inode_chunk( 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); + &XFS_RMAP_OINFO_INODES, XFS_AG_RESV_NONE, + false); if (error) return error; diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 0c5d7ba1c..593cb1fcc 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -160,7 +160,7 @@ __xfs_inobt_free_block( xfs_inobt_mod_blockcount(cur, -1); fsbno = XFS_DADDR_TO_FSB(cur->bc_mp, xfs_buf_daddr(bp)); return xfs_free_extent_later(cur->bc_tp, fsbno, 1, - &XFS_RMAP_OINFO_INOBT, resv); + &XFS_RMAP_OINFO_INOBT, resv, false); } STATIC int diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index ae72f2507..2284b45fb 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1152,7 +1152,7 @@ xfs_refcount_adjust_extents( tmp.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, tmp.rc_blockcount, NULL, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); if (error) goto out_error; } @@ -1214,7 +1214,7 @@ xfs_refcount_adjust_extents( ext.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount, NULL, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); if (error) goto out_error; } @@ -1984,7 +1984,7 @@ xfs_refcount_recover_cow_leftovers( /* Free the block. */ error = xfs_free_extent_later(tp, fsb, rr->rr_rrec.rc_blockcount, NULL, - XFS_AG_RESV_NONE); + XFS_AG_RESV_NONE, false); if (error) goto out_trans; diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 67cb59e33..bc8bd867e 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -111,7 +111,7 @@ xfs_refcountbt_free_block( be32_add_cpu(&agf->agf_refcount_blocks, -1); xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS); return xfs_free_extent_later(cur->bc_tp, fsbno, 1, - &XFS_RMAP_OINFO_REFC, XFS_AG_RESV_METADATA); + &XFS_RMAP_OINFO_REFC, XFS_AG_RESV_METADATA, false); } STATIC int From patchwork Mon Apr 22 16:25:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638698 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 9C20E153BC0 for ; Mon, 22 Apr 2024 16:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803975; cv=none; b=TqVywN6hZ30ITe7Ta6s2Q5YJKXmdpm28+C+6t3c8LdgzqOmHs1GQKeQCmKBSDpYcnLSKr6x7oXDmlVsOJ6vPji8qPcZGY23GgW/BZ/vuCtzqyfzqXMUJG651dF4UD/5eAa5NPUBuPA8R1+rfly/boKvA1GGNYGb5ozS9xFi3sVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803975; c=relaxed/simple; bh=TCDWdU2kk64+/UO/U7tkxE2s2HydYSPZQdY+3tpk0Zk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QDggO9JH5Iv6bEzqlY9X7SsmG/DTY2RiQuy8iSQru97V30lVjmalO8qeQwDmbve9/pP8/eolrYGLEXNdqBKscpUabGijGP11YEpfokXSho+qrowsBUi9Fxjp7ic55lhcjjPoCdiUKb6cPUa8gzeqQ9v9Ao1DLLL0w044Xvhpvvk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TDbCK1Bk; 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="TDbCK1Bk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E1A5C32781; Mon, 22 Apr 2024 16:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803975; bh=TCDWdU2kk64+/UO/U7tkxE2s2HydYSPZQdY+3tpk0Zk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDbCK1BkT7oMopfe344NIRBzTLVUpgrvK3ltDKYUZp+WOu8+u7AKeK1y4T1pPG9jc 8XAIVpF71MUxDN6lQ5fh0V0od8b39Cn4BUqC52L+bZUoSP0RnXv6dwI1k7cm+IkgMZ x06W0SZhVC9wj0RTNVbdHimasJ7WjeNO6pVRxSN11IyFt/dQQOJgKi9TzA9dnLeDU/ M1IiJLXhqRmebfptVgwsUcklQOinTG7PUspIIVsjwYqUKS+Z+RzGTffrLGiMUA7wt/ RiSDVg8G2qc4HLxBWX0IWhUMQUjYObOuYqkl2IupKDWu7RAo3zq4zhmjsSIaglCNdT 3YRgffmf/Beaw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 18/67] xfs: automatic freeing of freshly allocated unwritten space Date: Mon, 22 Apr 2024 18:25:40 +0200 Message-ID: <20240422163832.858420-20-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e3042be36c343207b7af249a09f50b4e37e9fda4 As mentioned in the previous commit, online repair wants to allocate space to write out a new metadata structure, and it also wants to hedge against system crashes during repairs by logging (and later cancelling) EFIs to free the space if we crash before committing the new data structure. Therefore, create a trio of functions to schedule automatic reaping of freshly allocated unwritten space. xfs_alloc_schedule_autoreap creates a paused EFI representing the space we just allocated. Once the allocations are made and the autoreaps scheduled, we can start writing to disk. If the writes succeed, xfs_alloc_cancel_autoreap marks the EFI work items as stale and unpauses the pending deferred work item. Assuming that's done in the same transaction that commits the new structure into the filesystem, we guarantee that either the new object is fully visible, or that all the space gets reclaimed. If the writes succeed but only part of an extent was used, repair must call the same _cancel_autoreap function to kill the first EFI and then log a new EFI to free the unused space. The first EFI is already For full extents that aren't used, xfs_alloc_commit_autoreap will unpause the EFI, which results in the space being freed during the next _defer_finish cycle. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/defer_item.c | 10 +++-- libxfs/xfs_alloc.c | 104 ++++++++++++++++++++++++++++++++++++++++++-- libxfs/xfs_alloc.h | 12 +++++ 3 files changed, 119 insertions(+), 7 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 8731d1834..c4a16c7ce 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -101,7 +101,7 @@ xfs_extent_free_finish_item( struct xfs_owner_info oinfo = { }; struct xfs_extent_free_item *xefi; xfs_agblock_t agbno; - int error; + int error = 0; xefi = container_of(item, struct xfs_extent_free_item, xefi_list); @@ -112,8 +112,12 @@ xfs_extent_free_finish_item( oinfo.oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK; agbno = XFS_FSB_TO_AGBNO(tp->t_mountp, xefi->xefi_startblock); - error = xfs_free_extent(tp, xefi->xefi_pag, agbno, - xefi->xefi_blockcount, &oinfo, XFS_AG_RESV_NONE); + + if (!(xefi->xefi_flags & XFS_EFI_CANCELLED)) { + error = xfs_free_extent(tp, xefi->xefi_pag, agbno, + xefi->xefi_blockcount, &oinfo, + XFS_AG_RESV_NONE); + } /* * Don't free the XEFI if we need a new transaction to complete diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 0a2404466..463381be7 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2518,14 +2518,15 @@ xfs_defer_agfl_block( * Add the extent to the list of extents to be free at transaction end. * The list is maintained sorted (by block number). */ -int -xfs_free_extent_later( +static int +xfs_defer_extent_free( struct xfs_trans *tp, xfs_fsblock_t bno, xfs_filblks_t len, const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type, - bool skip_discard) + bool skip_discard, + struct xfs_defer_pending **dfpp) { struct xfs_extent_free_item *xefi; struct xfs_mount *mp = tp->t_mountp; @@ -2573,10 +2574,105 @@ xfs_free_extent_later( XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len); xfs_extent_free_get_group(mp, xefi); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &xefi->xefi_list); + *dfpp = xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &xefi->xefi_list); + return 0; +} + +int +xfs_free_extent_later( + struct xfs_trans *tp, + xfs_fsblock_t bno, + xfs_filblks_t len, + const struct xfs_owner_info *oinfo, + enum xfs_ag_resv_type type, + bool skip_discard) +{ + struct xfs_defer_pending *dontcare = NULL; + + return xfs_defer_extent_free(tp, bno, len, oinfo, type, skip_discard, + &dontcare); +} + +/* + * Set up automatic freeing of unwritten space in the filesystem. + * + * This function attached a paused deferred extent free item to the + * transaction. Pausing means that the EFI will be logged in the next + * transaction commit, but the pending EFI will not be finished until the + * pending item is unpaused. + * + * If the system goes down after the EFI has been persisted to the log but + * before the pending item is unpaused, log recovery will find the EFI, fail to + * find the EFD, and free the space. + * + * If the pending item is unpaused, the next transaction commit will log an EFD + * without freeing the space. + * + * Caller must ensure that the tp, fsbno, len, oinfo, and resv flags of the + * @args structure are set to the relevant values. + */ +int +xfs_alloc_schedule_autoreap( + const struct xfs_alloc_arg *args, + bool skip_discard, + struct xfs_alloc_autoreap *aarp) +{ + int error; + + error = xfs_defer_extent_free(args->tp, args->fsbno, args->len, + &args->oinfo, args->resv, skip_discard, &aarp->dfp); + if (error) + return error; + + xfs_defer_item_pause(args->tp, aarp->dfp); return 0; } +/* + * Cancel automatic freeing of unwritten space in the filesystem. + * + * Earlier, we created a paused deferred extent free item and attached it to + * this transaction so that we could automatically roll back a new space + * allocation if the system went down. Now we want to cancel the paused work + * item by marking the EFI stale so we don't actually free the space, unpausing + * the pending item and logging an EFD. + * + * The caller generally should have already mapped the space into the ondisk + * filesystem. If the reserved space was partially used, the caller must call + * xfs_free_extent_later to create a new EFI to free the unused space. + */ +void +xfs_alloc_cancel_autoreap( + struct xfs_trans *tp, + struct xfs_alloc_autoreap *aarp) +{ + struct xfs_defer_pending *dfp = aarp->dfp; + struct xfs_extent_free_item *xefi; + + if (!dfp) + return; + + list_for_each_entry(xefi, &dfp->dfp_work, xefi_list) + xefi->xefi_flags |= XFS_EFI_CANCELLED; + + xfs_defer_item_unpause(tp, dfp); +} + +/* + * Commit automatic freeing of unwritten space in the filesystem. + * + * This unpauses an earlier _schedule_autoreap and commits to freeing the + * allocated space. Call this if none of the reserved space was used. + */ +void +xfs_alloc_commit_autoreap( + struct xfs_trans *tp, + struct xfs_alloc_autoreap *aarp) +{ + if (aarp->dfp) + xfs_defer_item_unpause(tp, aarp->dfp); +} + #ifdef DEBUG /* * Check if an AGF has a free extent record whose length is equal to diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 6b95d1d8a..851cafbd6 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -255,6 +255,18 @@ void xfs_extent_free_get_group(struct xfs_mount *mp, #define XFS_EFI_SKIP_DISCARD (1U << 0) /* don't issue discard */ #define XFS_EFI_ATTR_FORK (1U << 1) /* freeing attr fork block */ #define XFS_EFI_BMBT_BLOCK (1U << 2) /* freeing bmap btree block */ +#define XFS_EFI_CANCELLED (1U << 3) /* dont actually free the space */ + +struct xfs_alloc_autoreap { + struct xfs_defer_pending *dfp; +}; + +int xfs_alloc_schedule_autoreap(const struct xfs_alloc_arg *args, + bool skip_discard, struct xfs_alloc_autoreap *aarp); +void xfs_alloc_cancel_autoreap(struct xfs_trans *tp, + struct xfs_alloc_autoreap *aarp); +void xfs_alloc_commit_autoreap(struct xfs_trans *tp, + struct xfs_alloc_autoreap *aarp); extern struct kmem_cache *xfs_extfree_item_cache; From patchwork Mon Apr 22 16:25:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638699 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 1130F153BCB for ; Mon, 22 Apr 2024 16:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803977; cv=none; b=QdK5X58elYVgbv0FTNwZF7USqsax66I6q5J7jNNK8fd0Yj6V24ZwE2WHkj/azcOoPXv/YrbH+9is8gnEjQPPDs98DA8A3pyqvENeLn/nw0sfiM6Q9Y+oQMijc6d2UXHMAYR+o3xLKgo2UVQ7tbKaEsHCwO+XUSNhscRtsSFGi8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803977; c=relaxed/simple; bh=tTLhgomp+cvU7nPjmB+nSWUkBZoU/ebAt/EiPk7bqHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oNhNn6OFmr5B/n8QDqYGQ8eI6r3z4AiOmIiOcjihEluIV26EASLi96jdGeJgWjSxaePUsvTuCI7WtiGadZo8HgCIViGzDlTGP9mFxxk0dvNZEvN9ms5i3+s81iB/LNnrMUGRpwB64V4aekV+0VrjEduVKtMRWmpxTkNCuwJlUGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=foX8HSNi; 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="foX8HSNi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF9F5C113CC; Mon, 22 Apr 2024 16:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803976; bh=tTLhgomp+cvU7nPjmB+nSWUkBZoU/ebAt/EiPk7bqHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=foX8HSNiFUFYJsfFAFa0QFCMfEwSebCg2CibS+9B5nSMDSiJyPDuobo1X6sU8PyWo Ux2MjFPMFIYpm98m+ltjthjKipvqDmC9FV+ja3puSS6Sdoz1hOOuvetJ9vNbiJndwo Mcl5fd4TEVgV0Jqo6mGsnomJXYBK1eSS7+GVSVmxk2NBDk4vrZgCUTVDFVHNyRr6JB Q+HRTygGbYH40VsBXDu9AYXEz4mHGtLWfY+trUzfrFJRnuUQvfGHx8PiDqwWy9HZjL Zf/lUICltolJ/L912hUBy2kacw7j+URpFo+uuZuAv+UQS+FVgv0oizHIUONapN91MW dagWHMtF62C4g== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 19/67] xfs: remove unused fields from struct xbtree_ifakeroot Date: Mon, 22 Apr 2024 18:25:41 +0200 Message-ID: <20240422163832.858420-21-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 4c8ecd1cfdd01fb727121035014d9f654a30bdf2 Remove these unused fields since nobody uses them. They should have been removed years ago in a different cleanup series from Christoph Hellwig. Fixes: daf83964a3681 ("xfs: move the per-fork nextents fields into struct xfs_ifork") Fixes: f7e67b20ecbbc ("xfs: move the fork format fields into struct xfs_ifork") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Carlos Maiolino --- libxfs/xfs_btree_staging.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libxfs/xfs_btree_staging.h b/libxfs/xfs_btree_staging.h index f0d297605..5f638f711 100644 --- a/libxfs/xfs_btree_staging.h +++ b/libxfs/xfs_btree_staging.h @@ -37,12 +37,6 @@ struct xbtree_ifakeroot { /* Number of bytes available for this fork in the inode. */ unsigned int if_fork_size; - - /* Fork format. */ - unsigned int if_format; - - /* Number of records. */ - unsigned int if_extents; }; /* Cursor interactions with fake roots for inode-rooted btrees. */ From patchwork Mon Apr 22 16:25:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638700 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 F2939154432 for ; Mon, 22 Apr 2024 16:39: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=1713803979; cv=none; b=dqBIvG6FxQimYx78G+xJKBPAxctP9Fo2wLogvBGXezy5oMURQnQuh6xLa4Ofaf53M9KnVNlcLRRz6VcWhvooeXFE+o9Vc7dToGOpc8ckZDyKVuQUhI6FV27kCTT31QYRzl16h1bA3OHqsDqAoh7gS7wTm0gCzK6/FO9JT0F4gMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803979; c=relaxed/simple; bh=ojxpQjaEGx/XjEa3JtD3O2n1DdffhYcZOZJKf3ZsBl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eVRGrgSF6itsWz0++aocxRHuzremSebxYns30kZVOd3z3jqQlbA+kf+X6RLFtrW9MqIKix8FE7vhMIEZtgrDDUXv3mUemuGLoF/zzm7Vsoup4oMAAsNbBDAvjZYh4BncLXbMXe4Fju6dfJ1/ZQNxqCVAQsWWmz9IdTYHYMyNNuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q/v+f/LU; 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="q/v+f/LU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B67C116B1; Mon, 22 Apr 2024 16:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803978; bh=ojxpQjaEGx/XjEa3JtD3O2n1DdffhYcZOZJKf3ZsBl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q/v+f/LUNSM+63WmC3hNGyQvoYeHDo2JbZn4Ttr0zzr2MCyAuTwEIAY1XNwG3E/t9 SrdO5qVJ1kfO87H9eoZPUkOOjC9d+dxp5FDZf1C3Gmv0bmzQhpqeLziGK7qJaEhbN/ kv7NxHXvgn2hhUflvMg+HD+F+sbEegqrAHSsfYKotuNRQ7iVmT+kxUcC96oaLhkGff 9pOmHTiLnb/3BojfGnoehIGkrx9wE4mwER3arn7mb0Ds2h3sgi63j0wvwaLDpXcMaS mH7l06/ATzbxWH5qPxcu16a7HZnV6bLFLyRbZ/6+/HwrJjYMmHlL3j4wRskYmP0pZE KRmaY3lYzGt2Q== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 20/67] xfs: force small EFIs for reaping btree extents Date: Mon, 22 Apr 2024 18:25:42 +0200 Message-ID: <20240422163832.858420-22-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 3f3cec031099c37513727efc978a12b6346e326d Introduce the concept of a defer ops barrier to separate consecutively queued pending work items of the same type. With a barrier in place, the two work items will be tracked separately, and receive separate log intent items. The goal here is to prevent reaping of old metadata blocks from creating unnecessarily huge EFIs that could then run the risk of overflowing the scrub transaction. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 107 ++++++++++++++++++++++++++++++++++++++++----- libxfs/xfs_defer.h | 3 ++ 2 files changed, 99 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 58ad1881d..98f1cbe6a 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -176,6 +176,58 @@ static struct kmem_cache *xfs_defer_pending_cache; * Note that the continuation requested between t2 and t3 is likely to * reoccur. */ +STATIC struct xfs_log_item * +xfs_defer_barrier_create_intent( + struct xfs_trans *tp, + struct list_head *items, + unsigned int count, + bool sort) +{ + return NULL; +} + +STATIC void +xfs_defer_barrier_abort_intent( + struct xfs_log_item *intent) +{ + /* empty */ +} + +STATIC struct xfs_log_item * +xfs_defer_barrier_create_done( + struct xfs_trans *tp, + struct xfs_log_item *intent, + unsigned int count) +{ + return NULL; +} + +STATIC int +xfs_defer_barrier_finish_item( + struct xfs_trans *tp, + struct xfs_log_item *done, + struct list_head *item, + struct xfs_btree_cur **state) +{ + ASSERT(0); + return -EFSCORRUPTED; +} + +STATIC void +xfs_defer_barrier_cancel_item( + struct list_head *item) +{ + ASSERT(0); +} + +static const struct xfs_defer_op_type xfs_barrier_defer_type = { + .max_items = 1, + .create_intent = xfs_defer_barrier_create_intent, + .abort_intent = xfs_defer_barrier_abort_intent, + .create_done = xfs_defer_barrier_create_done, + .finish_item = xfs_defer_barrier_finish_item, + .cancel_item = xfs_defer_barrier_cancel_item, +}; static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_BMAP] = &xfs_bmap_update_defer_type, @@ -184,6 +236,7 @@ static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type, [XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type, [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, + [XFS_DEFER_OPS_TYPE_BARRIER] = &xfs_barrier_defer_type, }; /* Create a log intent done item for a log intent item. */ @@ -773,6 +826,23 @@ xfs_defer_can_append( return true; } +/* Create a new pending item at the end of the transaction list. */ +static inline struct xfs_defer_pending * +xfs_defer_alloc( + struct xfs_trans *tp, + enum xfs_defer_ops_type type) +{ + struct xfs_defer_pending *dfp; + + dfp = kmem_cache_zalloc(xfs_defer_pending_cache, + GFP_NOFS | __GFP_NOFAIL); + dfp->dfp_type = type; + INIT_LIST_HEAD(&dfp->dfp_work); + list_add_tail(&dfp->dfp_list, &tp->t_dfops); + + return dfp; +} + /* Add an item for later deferred processing. */ struct xfs_defer_pending * xfs_defer_add( @@ -787,23 +857,38 @@ xfs_defer_add( BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); dfp = xfs_defer_find_last(tp, type, ops); - if (!dfp || !xfs_defer_can_append(dfp, ops)) { - /* Create a new pending item at the end of the intake list. */ - dfp = kmem_cache_zalloc(xfs_defer_pending_cache, - GFP_NOFS | __GFP_NOFAIL); - dfp->dfp_type = type; - dfp->dfp_intent = NULL; - dfp->dfp_done = NULL; - dfp->dfp_count = 0; - INIT_LIST_HEAD(&dfp->dfp_work); - list_add_tail(&dfp->dfp_list, &tp->t_dfops); - } + if (!dfp || !xfs_defer_can_append(dfp, ops)) + dfp = xfs_defer_alloc(tp, type); xfs_defer_add_item(dfp, li); trace_xfs_defer_add_item(tp->t_mountp, dfp, li); return dfp; } +/* + * Add a defer ops barrier to force two otherwise adjacent deferred work items + * to be tracked separately and have separate log items. + */ +void +xfs_defer_add_barrier( + struct xfs_trans *tp) +{ + struct xfs_defer_pending *dfp; + const enum xfs_defer_ops_type type = XFS_DEFER_OPS_TYPE_BARRIER; + const struct xfs_defer_op_type *ops = defer_op_types[type]; + + ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); + + /* If the last defer op added was a barrier, we're done. */ + dfp = xfs_defer_find_last(tp, type, ops); + if (dfp) + return; + + xfs_defer_alloc(tp, type); + + trace_xfs_defer_add_item(tp->t_mountp, dfp, NULL); +} + /* * Create a pending deferred work item to replay the recovered intent item * and add it to the list. diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index b0284154f..5b1990ef3 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -20,6 +20,7 @@ enum xfs_defer_ops_type { XFS_DEFER_OPS_TYPE_FREE, XFS_DEFER_OPS_TYPE_AGFL_FREE, XFS_DEFER_OPS_TYPE_ATTR, + XFS_DEFER_OPS_TYPE_BARRIER, XFS_DEFER_OPS_TYPE_MAX, }; @@ -163,4 +164,6 @@ xfs_defer_add_item( int __init xfs_defer_init_item_caches(void); void xfs_defer_destroy_item_caches(void); +void xfs_defer_add_barrier(struct xfs_trans *tp); + #endif /* __XFS_DEFER_H__ */ From patchwork Mon Apr 22 16:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638701 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 25F77154432 for ; Mon, 22 Apr 2024 16:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803980; cv=none; b=hoM1rqRj9btV/hsURs8te1o0oda2pNNchgihTvMLWwY+60qwnqxjB8IqMgxdrB7Ts8AA29cingP3db+bFH1oxRj/y4n1pLcdqnwtc7PZpBDEyxCzwx212vExtV5ZtF6AKiyfXrNGpWKz0cjp6h10uIU+a/XCnaG+vvMjFe3IhTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803980; c=relaxed/simple; bh=w0J/LMADVK3+d8ySMyvNPamSzna0f7Lj1cS5v0+TlTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sMdisA3l9W87RECtsqunbDabL3Ilex9v/lHbwnzHSTqDHmbvZHNUDPL8Efq+8o6RRBuMglCUetojk+mVW/u4+IPqdzR+/HG0TmU9e79ZPu0pgdngbd6NuoFvx8MB5o+8jGD83/bX2tz6dtHtT1IbbVGyn0mnoA45dCGr7jMJjp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UHOnamoF; 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="UHOnamoF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09831C32782; Mon, 22 Apr 2024 16:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803980; bh=w0J/LMADVK3+d8ySMyvNPamSzna0f7Lj1cS5v0+TlTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UHOnamoFN6Ridva/HvY/dY8ziPnQpe2qsBFp2q5gJBIh1l/lYGOkhMBWdbes9C9GG Vic86iPXHIp4u6PcwNoXDXCWwz6waVnD9kctihKbz+4JfnVNaa9+zktcOsZAYtsdtu bjgQaCkKnp4vLXYvtu9+2lHncbkJkmF3/oX8WJiwK1ocnt6cwfe73lNVzUyAvIXFg+ uYqcMbxnX41MtbStz4JyFo27K601GBgtB6My21U74zMOqihU3oTK+T3XOOxl1tnVCf P1UfbZ1w1bDmfS79H7g9YyEmZQR6gtxKLNuY6zJDhTc77zLtwEnXIMOgFUxckNnZN5 jcXx+8WuRgpiQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 21/67] xfs: ensure logflagsp is initialized in xfs_bmap_del_extent_real Date: Mon, 22 Apr 2024 18:25:43 +0200 Message-ID: <20240422163832.858420-23-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jiachen Zhang Source kernel commit: e6af9c98cbf0164a619d95572136bfb54d482dd6 In the case of returning -ENOSPC, ensure logflagsp is initialized by 0. Otherwise the caller __xfs_bunmapi will set uninitialized illegal tmp_logflags value into xfs log, which might cause unpredictable error in the log recovery procedure. Also, remove the flags variable and set the *logflagsp directly, so that the code should be more robust in the long run. Fixes: 1b24b633aafe ("xfs: move some more code into xfs_bmap_del_extent_real") Signed-off-by: Jiachen Zhang Reviewed-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_bmap.c | 73 ++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 8c553d22c..20ec22dfc 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5004,7 +5004,6 @@ xfs_bmap_del_extent_real( xfs_fileoff_t del_endoff; /* first offset past del */ int do_fx; /* free extent at end of routine */ int error; /* error return value */ - int flags = 0;/* inode logging flags */ struct xfs_bmbt_irec got; /* current extent entry */ xfs_fileoff_t got_endoff; /* first offset past got */ int i; /* temp state */ @@ -5017,6 +5016,8 @@ xfs_bmap_del_extent_real( uint32_t state = xfs_bmap_fork_to_state(whichfork); struct xfs_bmbt_irec old; + *logflagsp = 0; + mp = ip->i_mount; XFS_STATS_INC(mp, xs_del_exlist); @@ -5029,7 +5030,6 @@ xfs_bmap_del_extent_real( ASSERT(got_endoff >= del_endoff); ASSERT(!isnullstartblock(got.br_startblock)); qfield = 0; - error = 0; /* * If it's the case where the directory code is running with no block @@ -5045,13 +5045,13 @@ xfs_bmap_del_extent_real( del->br_startoff > got.br_startoff && del_endoff < got_endoff) return -ENOSPC; - flags = XFS_ILOG_CORE; + *logflagsp = XFS_ILOG_CORE; if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) { if (!(bflags & XFS_BMAPI_REMAP)) { error = xfs_rtfree_blocks(tp, del->br_startblock, del->br_blockcount); if (error) - goto done; + return error; } do_fx = 0; @@ -5066,11 +5066,9 @@ xfs_bmap_del_extent_real( if (cur) { error = xfs_bmbt_lookup_eq(cur, &got, &i); if (error) - goto done; - if (XFS_IS_CORRUPT(mp, i != 1)) { - error = -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i != 1)) + return -EFSCORRUPTED; } if (got.br_startoff == del->br_startoff) @@ -5087,17 +5085,15 @@ xfs_bmap_del_extent_real( xfs_iext_prev(ifp, icur); ifp->if_nextents--; - flags |= XFS_ILOG_CORE; + *logflagsp |= XFS_ILOG_CORE; if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } if ((error = xfs_btree_delete(cur, &i))) - goto done; - if (XFS_IS_CORRUPT(mp, i != 1)) { - error = -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i != 1)) + return -EFSCORRUPTED; break; case BMAP_LEFT_FILLING: /* @@ -5108,12 +5104,12 @@ xfs_bmap_del_extent_real( got.br_blockcount -= del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } error = xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; break; case BMAP_RIGHT_FILLING: /* @@ -5122,12 +5118,12 @@ xfs_bmap_del_extent_real( got.br_blockcount -= del->br_blockcount; xfs_iext_update_extent(ip, state, icur, &got); if (!cur) { - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); break; } error = xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; break; case 0: /* @@ -5144,18 +5140,18 @@ xfs_bmap_del_extent_real( new.br_state = got.br_state; new.br_startblock = del_endblock; - flags |= XFS_ILOG_CORE; + *logflagsp |= XFS_ILOG_CORE; if (cur) { error = xfs_bmbt_update(cur, &got); if (error) - goto done; + return error; error = xfs_btree_increment(cur, 0, &i); if (error) - goto done; + return error; cur->bc_rec.b = new; error = xfs_btree_insert(cur, &i); if (error && error != -ENOSPC) - goto done; + return error; /* * If get no-space back from btree insert, it tried a * split, and we have a zero block reservation. Fix up @@ -5168,33 +5164,28 @@ xfs_bmap_del_extent_real( */ error = xfs_bmbt_lookup_eq(cur, &got, &i); if (error) - goto done; - if (XFS_IS_CORRUPT(mp, i != 1)) { - error = -EFSCORRUPTED; - goto done; - } + return error; + if (XFS_IS_CORRUPT(mp, i != 1)) + return -EFSCORRUPTED; /* * Update the btree record back * to the original value. */ error = xfs_bmbt_update(cur, &old); if (error) - goto done; + return error; /* * Reset the extent record back * to the original value. */ xfs_iext_update_extent(ip, state, icur, &old); - flags = 0; - error = -ENOSPC; - goto done; - } - if (XFS_IS_CORRUPT(mp, i != 1)) { - error = -EFSCORRUPTED; - goto done; + *logflagsp = 0; + return -ENOSPC; } + if (XFS_IS_CORRUPT(mp, i != 1)) + return -EFSCORRUPTED; } else - flags |= xfs_ilog_fext(whichfork); + *logflagsp |= xfs_ilog_fext(whichfork); ifp->if_nextents++; xfs_iext_next(ifp, icur); @@ -5218,7 +5209,7 @@ xfs_bmap_del_extent_real( ((bflags & XFS_BMAPI_NODISCARD) || del->br_state == XFS_EXT_UNWRITTEN)); if (error) - goto done; + return error; } } @@ -5233,9 +5224,7 @@ xfs_bmap_del_extent_real( if (qfield && !(bflags & XFS_BMAPI_REMAP)) xfs_trans_mod_dquot_byino(tp, ip, qfield, (long)-nblks); -done: - *logflagsp = flags; - return error; + return 0; } /* From patchwork Mon Apr 22 16:25:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638702 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 9E7A1153BCF for ; Mon, 22 Apr 2024 16:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803981; cv=none; b=mbYX17fKk6hjPa23LmRHIIDNrcdYfknFh75cd6x2zas93QYqmjtXjDtJpCCkZ0F8k5Jn0E0TDo8AClRUGHd/CX8IcdkiP4Zha4mNAiWYnlTRS9obXuour6+cvoA48jgkfJfIBn5EiHqWcYk2GDvbauWxPN7ySQEEP+bfB+S8Ndg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803981; c=relaxed/simple; bh=I3uPu+NnvYpcA54lCXV2p/3UdGR/BbZN2wGNEdvNzzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W7337OehbtfolmX2VDSYMLtxIZEYqmaa5CCC5evAwgLO0zAAQnLMPyzv94RnPp27kuwLUYLk6Irgd2QVxV+aG8CV1raxmZkcW4f8YqgYkWukF6IDpVSkaGjYbittg304Yg3UGo0lmhN5LB4xIbXhq2EL45i86GwNjn341I3ZUi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OMc+2aGH; 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="OMc+2aGH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CB00C113CC; Mon, 22 Apr 2024 16:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803981; bh=I3uPu+NnvYpcA54lCXV2p/3UdGR/BbZN2wGNEdvNzzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OMc+2aGHW/1f4zmSQazD17yTDf1aTQz98RZF//twvFzYFjvraHKBYIvcCv9gFDNY9 jL3JyIl7gCfe0DaY0g+9aj8s4hiUK1aXpjTXaDqiCiY1jNoWUJsd/IUFH/TBVnzUSu qA1HIEfVQFNa9Zg4cwfw61qQuLfrWQUQ/H2APsg+stCHyCs0RaG9OQu1bJb+/vDzFM s/v8h+AREPlNgaXQ2QKLpE5l19EdTHjkrZbszdit8Sg4alw0bNQhA/IYJuiAfmccpk SkgpMjP6Uq65adIGtSEZqUmFwlvETnQXYg0YU4qJADNEGOeO50o7Ug2TF9mORtNjVo IVasbFF3SjuTg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 22/67] xfs: update dir3 leaf block metadata after swap Date: Mon, 22 Apr 2024 18:25:44 +0200 Message-ID: <20240422163832.858420-24-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhang Tianci Source kernel commit: 5759aa4f956034b289b0ae2c99daddfc775442e1 xfs_da3_swap_lastblock() copy the last block content to the dead block, but do not update the metadata in it. We need update some metadata for some kinds of type block, such as dir3 leafn block records its blkno, we shall update it to the dead block blkno. Otherwise, before write the xfs_buf to disk, the verify_write() will fail in blk_hdr->blkno != xfs_buf->b_bn, then xfs will be shutdown. We will get this warning: XFS (dm-0): Metadata corruption detected at xfs_dir3_leaf_verify+0xa8/0xe0 [xfs], xfs_dir3_leafn block 0x178 XFS (dm-0): Unmount and run xfs_repair XFS (dm-0): First 128 bytes of corrupted metadata buffer: 00000000e80f1917: 00 80 00 0b 00 80 00 07 3d ff 00 00 00 00 00 00 ........=....... 000000009604c005: 00 00 00 00 00 00 01 a0 00 00 00 00 00 00 00 00 ................ 000000006b6fb2bf: e4 44 e3 97 b5 64 44 41 8b 84 60 0e 50 43 d9 bf .D...dDA..`.PC.. 00000000678978a2: 00 00 00 00 00 00 00 83 01 73 00 93 00 00 00 00 .........s...... 00000000b28b247c: 99 29 1d 38 00 00 00 00 99 29 1d 40 00 00 00 00 .).8.....).@.... 000000002b2a662c: 99 29 1d 48 00 00 00 00 99 49 11 00 00 00 00 00 .).H.....I...... 00000000ea2ffbb8: 99 49 11 08 00 00 45 25 99 49 11 10 00 00 48 fe .I....E%.I....H. 0000000069e86440: 99 49 11 18 00 00 4c 6b 99 49 11 20 00 00 4d 97 .I....Lk.I. ..M. XFS (dm-0): xfs_do_force_shutdown(0x8) called from line 1423 of file fs/xfs/xfs_buf.c. Return address = 00000000c0ff63c1 XFS (dm-0): Corruption of in-memory data detected. Shutting down filesystem XFS (dm-0): Please umount the filesystem and rectify the problem(s) >From the log above, we know xfs_buf->b_no is 0x178, but the block's hdr record its blkno is 0x1a0. Fixes: 24df33b45ecf ("xfs: add CRC checking to dir2 leaf blocks") Signed-off-by: Zhang Tianci Suggested-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_da_btree.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index a068a0164..3903486d1 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -2312,10 +2312,17 @@ xfs_da3_swap_lastblock( return error; /* * Copy the last block into the dead buffer and log it. + * On CRC-enabled file systems, also update the stamped in blkno. */ memcpy(dead_buf->b_addr, last_buf->b_addr, args->geo->blksize); + if (xfs_has_crc(mp)) { + struct xfs_da3_blkinfo *da3 = dead_buf->b_addr; + + da3->blkno = cpu_to_be64(xfs_buf_daddr(dead_buf)); + } xfs_trans_log_buf(tp, dead_buf, 0, args->geo->blksize - 1); dead_info = dead_buf->b_addr; + /* * Get values from the moved block. */ From patchwork Mon Apr 22 16:25:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638703 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 58C81153BCF for ; Mon, 22 Apr 2024 16:39: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=1713803983; cv=none; b=JQdKYFkPsMdk+Lo1jC83u65cU4q0g5EnlOEIV5FMWjtt2wAwCvkzB7xXrED/ymNZr1t5MBKFSema1R0jf3jtqWhuWBfAC9rXaYG2/laE/wVm6ijsAQmW0d39Cspd1qTyTTULJNIMz7wxrUr0H8V1O66HpuwVlY8cjpI3wSBRTOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803983; c=relaxed/simple; bh=AF/Beh2BTqJX7DPXeYYCKvoWNf4TdDLemRe9GmQ4JA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f7xq/eeLCs+JNuIJbxDKuCuxg2qfA6ha4qrwuf6eN/YVUodEXFFbvBe5yhFskPpLylutadcSvMj2WvHTsTr5tu9Grc56ubvpT+pvYcB/UFlFAQkCMSfRLthmZt6Tp900Ac3KGFHWNHrMWRhMN9XoksWOxHGFKnsp3wLkUAXCR78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pCE3SIRj; 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="pCE3SIRj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 022B9C32781; Mon, 22 Apr 2024 16:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803983; bh=AF/Beh2BTqJX7DPXeYYCKvoWNf4TdDLemRe9GmQ4JA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pCE3SIRjxY6n2uTYLhQknOFSWUhc5rTDIktzXXb8Po2p1F8e8Q7jTyqWb0+3zc9wL 9d02g5DsI3P6F3umEhZw8h+kfHoRaVIDMwzCEGN9MruM3QvGEZ8Dcu4kMKEV6wMSDm urh+y9q0ymJCs8T5PaJjazADssmcjPqyWNXKtRN7y8DAMeqGIdGOcB7RktpgATXS2u 4To9AlT3I6Xe03YXWW2IbEHmgeNjkSqH825fRpNuxsF72iMt4N/3ufqEIXFwL2r7BL sCl2HOvSbyRPu1fwh4aCRbawrLU0C9bF64Vp1/jSVvcsLs4+gmLIWoT7hHXaOTRcFv It6CUTB45iR3Q== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 23/67] xfs: extract xfs_da_buf_copy() helper function Date: Mon, 22 Apr 2024 18:25:45 +0200 Message-ID: <20240422163832.858420-25-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhang Tianci Source kernel commit: fd45ddb9dd606b3eaddf26e13f64340636955986 This patch does not modify logic. xfs_da_buf_copy() will copy one block from src xfs_buf to dst xfs_buf, and update the block metadata in dst directly. Signed-off-by: Zhang Tianci Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr_leaf.c | 12 +++---- libxfs/xfs_da_btree.c | 74 +++++++++++++++++------------------------- libxfs/xfs_da_btree.h | 2 ++ 3 files changed, 36 insertions(+), 52 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index ed81471ce..baa168318 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -1241,14 +1241,10 @@ xfs_attr3_leaf_to_node( if (error) goto out; - /* copy leaf to new buffer, update identifiers */ - xfs_trans_buf_set_type(args->trans, bp2, XFS_BLFT_ATTR_LEAF_BUF); - bp2->b_ops = bp1->b_ops; - memcpy(bp2->b_addr, bp1->b_addr, args->geo->blksize); - if (xfs_has_crc(mp)) { - struct xfs_da3_blkinfo *hdr3 = bp2->b_addr; - hdr3->blkno = cpu_to_be64(xfs_buf_daddr(bp2)); - } + /* + * Copy leaf to new buffer and log it. + */ + xfs_da_buf_copy(bp2, bp1, args->geo->blksize); xfs_trans_log_buf(args->trans, bp2, 0, args->geo->blksize - 1); /* diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 3903486d1..0779bb624 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -417,6 +417,25 @@ xfs_da3_node_read_mapped( return xfs_da3_node_set_type(tp, *bpp); } +/* + * Copy src directory/attr leaf/node buffer to the dst. + * For v5 file systems make sure the right blkno is stamped in. + */ +void +xfs_da_buf_copy( + struct xfs_buf *dst, + struct xfs_buf *src, + size_t size) +{ + struct xfs_da3_blkinfo *da3 = dst->b_addr; + + memcpy(dst->b_addr, src->b_addr, size); + dst->b_ops = src->b_ops; + xfs_trans_buf_copy_type(dst, src); + if (xfs_has_crc(dst->b_mount)) + da3->blkno = cpu_to_be64(xfs_buf_daddr(dst)); +} + /*======================================================================== * Routines used for growing the Btree. *========================================================================*/ @@ -686,12 +705,6 @@ xfs_da3_root_split( btree = icnodehdr.btree; size = (int)((char *)&btree[icnodehdr.count] - (char *)oldroot); level = icnodehdr.level; - - /* - * we are about to copy oldroot to bp, so set up the type - * of bp while we know exactly what it will be. - */ - xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF); } else { struct xfs_dir3_icleaf_hdr leafhdr; @@ -703,31 +716,17 @@ xfs_da3_root_split( size = (int)((char *)&leafhdr.ents[leafhdr.count] - (char *)leaf); level = 0; - - /* - * we are about to copy oldroot to bp, so set up the type - * of bp while we know exactly what it will be. - */ - xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_LEAFN_BUF); } /* - * we can copy most of the information in the node from one block to - * another, but for CRC enabled headers we have to make sure that the - * block specific identifiers are kept intact. We update the buffer - * directly for this. + * Copy old root to new buffer and log it. */ - memcpy(node, oldroot, size); - if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC) || - oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC)) { - struct xfs_da3_intnode *node3 = (struct xfs_da3_intnode *)node; - - node3->hdr.info.blkno = cpu_to_be64(xfs_buf_daddr(bp)); - } + xfs_da_buf_copy(bp, blk1->bp, size); xfs_trans_log_buf(tp, bp, 0, size - 1); - bp->b_ops = blk1->bp->b_ops; - xfs_trans_buf_copy_type(bp, blk1->bp); + /* + * Update blk1 to point to new buffer. + */ blk1->bp = bp; blk1->blkno = blkno; @@ -1216,21 +1215,14 @@ xfs_da3_root_join( xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level); /* - * This could be copying a leaf back into the root block in the case of - * there only being a single leaf block left in the tree. Hence we have - * to update the b_ops pointer as well to match the buffer type change - * that could occur. For dir3 blocks we also need to update the block - * number in the buffer header. + * Copy child to root buffer and log it. */ - memcpy(root_blk->bp->b_addr, bp->b_addr, args->geo->blksize); - root_blk->bp->b_ops = bp->b_ops; - xfs_trans_buf_copy_type(root_blk->bp, bp); - if (oldroothdr.magic == XFS_DA3_NODE_MAGIC) { - struct xfs_da3_blkinfo *da3 = root_blk->bp->b_addr; - da3->blkno = cpu_to_be64(xfs_buf_daddr(root_blk->bp)); - } + xfs_da_buf_copy(root_blk->bp, bp, args->geo->blksize); xfs_trans_log_buf(args->trans, root_blk->bp, 0, args->geo->blksize - 1); + /* + * Now we can drop the child buffer. + */ error = xfs_da_shrink_inode(args, child, bp); return error; } @@ -2312,14 +2304,8 @@ xfs_da3_swap_lastblock( return error; /* * Copy the last block into the dead buffer and log it. - * On CRC-enabled file systems, also update the stamped in blkno. */ - memcpy(dead_buf->b_addr, last_buf->b_addr, args->geo->blksize); - if (xfs_has_crc(mp)) { - struct xfs_da3_blkinfo *da3 = dead_buf->b_addr; - - da3->blkno = cpu_to_be64(xfs_buf_daddr(dead_buf)); - } + xfs_da_buf_copy(dead_buf, last_buf, args->geo->blksize); xfs_trans_log_buf(tp, dead_buf, 0, args->geo->blksize - 1); dead_info = dead_buf->b_addr; diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index ffa3df5b2..706baf36e 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -219,6 +219,8 @@ int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno, const struct xfs_buf_ops *ops); int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, struct xfs_buf *dead_buf); +void xfs_da_buf_copy(struct xfs_buf *dst, struct xfs_buf *src, + size_t size); uint xfs_da_hashname(const uint8_t *name_string, int name_length); enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, From patchwork Mon Apr 22 16:25:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638704 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 B6E1C153BCE for ; Mon, 22 Apr 2024 16: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=1713803984; cv=none; b=kl+jTMTrG8s70Px7aZ5Sd4OHAAv8IsMMxDduM6FWzQEUiI7fhaB6bB76yheFx+VtcaHY7v95zDW2v3wW7SGOhn8l69GbmMiPBXLoTjCuW5hHNZDlUZslnBdRUONaaW1sQ6zbjcAlkZMQAs7X0WXUletXijCnWDqvW2l/WEc4XjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803984; c=relaxed/simple; bh=hulg6lXaxvq6FFNGxeH+aBjzckylcnCF+SwSTPt8GAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YYkSGpsWGm8shHmUeJN/SDeGcQcc2X6LPREFJ3guTFOqUZ5cZu3d0v8HHcGTnEsfRNFZa18Y8oIw48Q4Yzr8b0K7Mr97aHComWJKXnPoUeA50nQMrT9F4Tdt5oRahvB//VTcDUOx9ydbyhQRNKTmelBKE2hT9P/jWlqGEB/MQwQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XDZxLAUa; 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="XDZxLAUa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 850C6C113CC; Mon, 22 Apr 2024 16:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803984; bh=hulg6lXaxvq6FFNGxeH+aBjzckylcnCF+SwSTPt8GAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDZxLAUaIsMcVJx0Gq+DiR5OfPCRPTNYEug/tOmjXzrgX6tfm3OCHOHmUD2R67xNb eiEveTVgZfF/DEK5J4DiCN4oqZ/4ptXu4KWPd79LGKK/d2Go2xrSTvYhNp//mCridQ W3pvYZtvFFnOt7OQIpoEzQ4m5z+mxJooH4AmOlqVjlv0MyUcEWXXSww2EJozkwn4CQ hG01IkZMxqBHcwe4Dw24nC8q+2wWnwgHWMj+aoQRMaEa44cNKsq4K7DDDqQEOgtpXq rfNcwK4tYoHrKU1LXngXP6oHW/8lH/oEsNfcUL4eZCePvlbGYnwZwcPcySj4WBtirs 0EpN453Hid/SA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 24/67] xfs: move xfs_ondisk.h to libxfs/ Date: Mon, 22 Apr 2024 18:25:46 +0200 Message-ID: <20240422163832.858420-26-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 18793e050504288345eb455a471677b57117bcc6 Move xfs_ondisk.h to libxfs so that we can do the struct sanity checks in userspace libxfs as well. This should allow us to retire the somewhat fragile xfs/122 test on xfstests. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Carlos Maiolino Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/init.c | 6 ++ libxfs/xfs_ondisk.h | 199 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 libxfs/xfs_ondisk.h diff --git a/libxfs/init.c b/libxfs/init.c index 63c506a69..f7ba4d1b3 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -23,6 +23,11 @@ #include "xfs_refcount_btree.h" #include "libfrog/platform.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_ondisk.h" + #include "libxfs.h" /* for now */ #ifndef HAVE_LIBURCU_ATOMIC64 @@ -248,6 +253,7 @@ libxfs_close_devices( int libxfs_init(struct libxfs_init *a) { + xfs_check_ondisk_structs(); rcu_init(); rcu_register_thread(); radix_tree_init(); diff --git a/libxfs/xfs_ondisk.h b/libxfs/xfs_ondisk.h new file mode 100644 index 000000000..d9c988c5a --- /dev/null +++ b/libxfs/xfs_ondisk.h @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2016 Oracle. + * All Rights Reserved. + */ +#ifndef __XFS_ONDISK_H +#define __XFS_ONDISK_H + +#define XFS_CHECK_STRUCT_SIZE(structname, size) \ + static_assert(sizeof(structname) == (size), \ + "XFS: sizeof(" #structname ") is wrong, expected " #size) + +#define XFS_CHECK_OFFSET(structname, member, off) \ + static_assert(offsetof(structname, member) == (off), \ + "XFS: offsetof(" #structname ", " #member ") is wrong, " \ + "expected " #off) + +#define XFS_CHECK_VALUE(value, expected) \ + static_assert((value) == (expected), \ + "XFS: value of " #value " is wrong, expected " #expected) + +static inline void __init +xfs_check_ondisk_structs(void) +{ + /* ag/file structures */ + XFS_CHECK_STRUCT_SIZE(struct xfs_acl, 4); + XFS_CHECK_STRUCT_SIZE(struct xfs_acl_entry, 12); + XFS_CHECK_STRUCT_SIZE(struct xfs_agf, 224); + XFS_CHECK_STRUCT_SIZE(struct xfs_agfl, 36); + XFS_CHECK_STRUCT_SIZE(struct xfs_agi, 344); + XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_key, 8); + XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_rec, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_bmdr_block, 4); + XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block_shdr, 48); + XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block_lhdr, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block, 72); + 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_dsymlink_hdr, 56); + XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key, 4); + XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_refcount_key, 4); + XFS_CHECK_STRUCT_SIZE(struct xfs_refcount_rec, 12); + XFS_CHECK_STRUCT_SIZE(struct xfs_rmap_key, 20); + XFS_CHECK_STRUCT_SIZE(struct xfs_rmap_rec, 24); + XFS_CHECK_STRUCT_SIZE(xfs_timestamp_t, 8); + XFS_CHECK_STRUCT_SIZE(struct xfs_legacy_timestamp, 8); + XFS_CHECK_STRUCT_SIZE(xfs_alloc_key_t, 8); + XFS_CHECK_STRUCT_SIZE(xfs_alloc_ptr_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_alloc_rec_t, 8); + XFS_CHECK_STRUCT_SIZE(xfs_inobt_ptr_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_refcount_ptr_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_rmap_ptr_t, 4); + + /* dir/attr trees */ + XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leaf_hdr, 80); + XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leafblock, 80); + XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_rmt_hdr, 56); + XFS_CHECK_STRUCT_SIZE(struct xfs_da3_blkinfo, 56); + XFS_CHECK_STRUCT_SIZE(struct xfs_da3_intnode, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_da3_node_hdr, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_blk_hdr, 48); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_data_hdr, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_free, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_free_hdr, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_leaf, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_dir3_leaf_hdr, 64); + XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_entry_t, 8); + XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_hdr_t, 32); + XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_map_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_local_t, 4); + + /* realtime structures */ + XFS_CHECK_STRUCT_SIZE(union xfs_rtword_raw, 4); + XFS_CHECK_STRUCT_SIZE(union xfs_suminfo_raw, 4); + + /* + * m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to + * 4 bytes anyway so it's not obviously a problem. Hence for the moment + * we don't check this structure. This can be re-instated when the attr + * definitions are updated to use c99 VLA definitions. + * + XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_remote_t, 12); + */ + + XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, valuelen, 0); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, namelen, 2); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, nameval, 3); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, valueblk, 0); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, valuelen, 4); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, namelen, 8); + XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, name, 9); + XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_attr_shortform, 4); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.totsize, 0); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.count, 2); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].namelen, 4); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].valuelen, 5); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].flags, 6); + XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].nameval, 7); + XFS_CHECK_STRUCT_SIZE(xfs_da_blkinfo_t, 12); + XFS_CHECK_STRUCT_SIZE(xfs_da_intnode_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_da_node_entry_t, 8); + XFS_CHECK_STRUCT_SIZE(xfs_da_node_hdr_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_data_free_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_data_hdr_t, 16); + XFS_CHECK_OFFSET(xfs_dir2_data_unused_t, freetag, 0); + XFS_CHECK_OFFSET(xfs_dir2_data_unused_t, length, 2); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_hdr_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_entry_t, 8); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_hdr_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_t, 16); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_tail_t, 4); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_sf_entry_t, 3); + XFS_CHECK_OFFSET(xfs_dir2_sf_entry_t, namelen, 0); + XFS_CHECK_OFFSET(xfs_dir2_sf_entry_t, offset, 1); + XFS_CHECK_OFFSET(xfs_dir2_sf_entry_t, name, 3); + XFS_CHECK_STRUCT_SIZE(xfs_dir2_sf_hdr_t, 10); + + /* log structures */ + XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88); + XFS_CHECK_STRUCT_SIZE(struct xfs_dq_logformat, 24); + XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_32, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_efd_log_format_64, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_32, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_efi_log_format_64, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_extent_32, 12); + XFS_CHECK_STRUCT_SIZE(struct xfs_extent_64, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_log_dinode, 176); + XFS_CHECK_STRUCT_SIZE(struct xfs_icreate_log, 28); + XFS_CHECK_STRUCT_SIZE(xfs_log_timestamp_t, 8); + XFS_CHECK_STRUCT_SIZE(struct xfs_log_legacy_timestamp, 8); + XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format_32, 52); + XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56); + XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20); + XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_bui_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_bud_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_cui_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_cud_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_rui_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_rud_log_format, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_map_extent, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_phys_extent, 16); + + XFS_CHECK_OFFSET(struct xfs_bui_log_format, bui_extents, 16); + XFS_CHECK_OFFSET(struct xfs_cui_log_format, cui_extents, 16); + XFS_CHECK_OFFSET(struct xfs_rui_log_format, rui_extents, 16); + XFS_CHECK_OFFSET(struct xfs_efi_log_format, efi_extents, 16); + XFS_CHECK_OFFSET(struct xfs_efi_log_format_32, efi_extents, 16); + XFS_CHECK_OFFSET(struct xfs_efi_log_format_64, efi_extents, 16); + + /* + * The v5 superblock format extended several v4 header structures with + * additional data. While new fields are only accessible on v5 + * superblocks, it's important that the v5 structures place original v4 + * fields/headers in the correct location on-disk. For example, we must + * be able to find magic values at the same location in certain blocks + * regardless of superblock version. + * + * The following checks ensure that various v5 data structures place the + * subset of v4 metadata associated with the same type of block at the + * start of the on-disk block. If there is no data structure definition + * for certain types of v4 blocks, traverse down to the first field of + * common metadata (e.g., magic value) and make sure it is at offset + * zero. + */ + XFS_CHECK_OFFSET(struct xfs_dir3_leaf, hdr.info.hdr, 0); + XFS_CHECK_OFFSET(struct xfs_da3_intnode, hdr.info.hdr, 0); + XFS_CHECK_OFFSET(struct xfs_dir3_data_hdr, hdr.magic, 0); + XFS_CHECK_OFFSET(struct xfs_dir3_free, hdr.hdr.magic, 0); + XFS_CHECK_OFFSET(struct xfs_attr3_leafblock, hdr.info.hdr, 0); + + XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat, 192); + XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers, 24); + XFS_CHECK_STRUCT_SIZE(struct xfs_bulkstat_req, 64); + XFS_CHECK_STRUCT_SIZE(struct xfs_inumbers_req, 64); + + /* + * Make sure the incore inode timestamp range corresponds to hand + * converted values based on the ondisk format specification. + */ + XFS_CHECK_VALUE(XFS_BIGTIME_TIME_MIN - XFS_BIGTIME_EPOCH_OFFSET, + XFS_LEGACY_TIME_MIN); + XFS_CHECK_VALUE(XFS_BIGTIME_TIME_MAX - XFS_BIGTIME_EPOCH_OFFSET, + 16299260424LL); + + /* Do the same with the incore quota expiration range. */ + XFS_CHECK_VALUE(XFS_DQ_BIGTIME_EXPIRY_MIN << XFS_DQ_BIGTIME_SHIFT, 4); + XFS_CHECK_VALUE(XFS_DQ_BIGTIME_EXPIRY_MAX << XFS_DQ_BIGTIME_SHIFT, + 16299260424LL); +} + +#endif /* __XFS_ONDISK_H */ From patchwork Mon Apr 22 16:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638705 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 6140E153BCF for ; Mon, 22 Apr 2024 16:39: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=1713803986; cv=none; b=dMe9oEa4e5O09Tz9u2t0fF5X1Cv3wxNhDPh5UZnsxw4o1YGKUpv4yvVotedrVwh6TGj1dyzqrA+JBZClJ9vWvMpslvGTuYIL1ZtS9lAlF4K3TN9kM6MLx9HyJ6HN30RPvZJGv2PmGMGteK5Ez6pkEnafbgLMzIJIlJK3Pd9JIWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803986; c=relaxed/simple; bh=cUtkCKTPNXwhktTBgXvdP/lBZWE+rJmLWeeo3z7QbSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iF1Htt8+PQDT/PaoiBAZpZON3kgk8gq1mhBw8tjLm4x68qcrTCHf4T3CfldwBbSUcdrnss3fzU4GNYbirmOM5XUKwxF0awVYb84gj3t6+PSG1ru96bPpN0fnMP104ZZ2vihyNWcsy4bly/meZXiy9+8Vwe+WqPUQgot4cXjyPlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SOc+3oZJ; 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="SOc+3oZJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AC82C116B1; Mon, 22 Apr 2024 16:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803986; bh=cUtkCKTPNXwhktTBgXvdP/lBZWE+rJmLWeeo3z7QbSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SOc+3oZJxi5+oV7pDlb0ICB1rJoeL78GEWRKuTe9s53P3+QG7YWoBakR2Scceb2lB fuLBYmUwfjFWnowcNh6KyQyBYiZYBxfBUINHjun/XFh1WGSMGZGX7iXBQSF7uzYQRb G0OQd1pHkaMpRymzK9HguWLpFMUw83rMyazK3FSXMTteCpME3mSX+fDkFOwSwsx/K6 bhMBJ1LZUs8Z9apdypI9FEhpVbn20enIMdM8GKjACT28ij531JoffOXzURnpg4ax3h 9jU0V47/vERYIPwiZtlohSORJ2KgRTjJlrxsLqIIXcrsfr/LBDqMX3u2aUeKAZhe37 koRc+ERBwTX7w== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 25/67] xfs: consolidate the xfs_attr_defer_* helpers Date: Mon, 22 Apr 2024 18:25:47 +0200 Message-ID: <20240422163832.858420-27-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: c00eebd09e95757c9c1d08f0a6bbc32c543daf90 Consolidate the xfs_attr_defer_* helpers into a single xfs_attr_defer_add one that picks the right dela_state based on the passed in operation. Also move to a single trace point as the actual operation is visible through the flags in the delta_state passed to the trace point. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr.c | 90 +++++++++++------------------------------------ 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 2103a06b9..550ca6b2e 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -878,11 +878,10 @@ xfs_attr_lookup( return error; } -static int -xfs_attr_intent_init( +static void +xfs_attr_defer_add( struct xfs_da_args *args, - unsigned int op_flags, /* op flag (set or remove) */ - struct xfs_attr_intent **attr) /* new xfs_attr_intent */ + unsigned int op_flags) { struct xfs_attr_intent *new; @@ -891,66 +890,22 @@ xfs_attr_intent_init( new->xattri_op_flags = op_flags; new->xattri_da_args = args; - *attr = new; - return 0; -} - -/* Sets an attribute for an inode as a deferred operation */ -static int -xfs_attr_defer_add( - struct xfs_da_args *args) -{ - struct xfs_attr_intent *new; - int error = 0; - - error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_SET, &new); - if (error) - return error; + switch (op_flags) { + case XFS_ATTRI_OP_FLAGS_SET: + new->xattri_dela_state = xfs_attr_init_add_state(args); + break; + case XFS_ATTRI_OP_FLAGS_REPLACE: + new->xattri_dela_state = xfs_attr_init_replace_state(args); + break; + case XFS_ATTRI_OP_FLAGS_REMOVE: + new->xattri_dela_state = xfs_attr_init_remove_state(args); + break; + default: + ASSERT(0); + } - new->xattri_dela_state = xfs_attr_init_add_state(args); xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp); - - return 0; -} - -/* Sets an attribute for an inode as a deferred operation */ -static int -xfs_attr_defer_replace( - struct xfs_da_args *args) -{ - struct xfs_attr_intent *new; - int error = 0; - - error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new); - if (error) - return error; - - new->xattri_dela_state = xfs_attr_init_replace_state(args); - xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); - trace_xfs_attr_defer_replace(new->xattri_dela_state, args->dp); - - return 0; -} - -/* Removes an attribute for an inode as a deferred operation */ -static int -xfs_attr_defer_remove( - struct xfs_da_args *args) -{ - - struct xfs_attr_intent *new; - int error; - - error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REMOVE, &new); - if (error) - return error; - - new->xattri_dela_state = xfs_attr_init_remove_state(args); - xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); - trace_xfs_attr_defer_remove(new->xattri_dela_state, args->dp); - - return 0; } /* @@ -1036,16 +991,16 @@ xfs_attr_set( error = xfs_attr_lookup(args); switch (error) { case -EEXIST: - /* if no value, we are performing a remove operation */ if (!args->value) { - error = xfs_attr_defer_remove(args); + /* if no value, we are performing a remove operation */ + xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REMOVE); break; } + /* Pure create fails if the attr already exists */ if (args->attr_flags & XATTR_CREATE) goto out_trans_cancel; - - error = xfs_attr_defer_replace(args); + xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REPLACE); break; case -ENOATTR: /* Can't remove what isn't there. */ @@ -1055,14 +1010,11 @@ xfs_attr_set( /* Pure replace fails if no existing attr to replace. */ if (args->attr_flags & XATTR_REPLACE) goto out_trans_cancel; - - error = xfs_attr_defer_add(args); + xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_SET); break; default: goto out_trans_cancel; } - if (error) - goto out_trans_cancel; /* * If this is a synchronous mount, make sure that the From patchwork Mon Apr 22 16:25:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638706 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 5A7F4153BE3 for ; Mon, 22 Apr 2024 16:39:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803988; cv=none; b=b/QaT02IxvpY1roM1XL2vQaJq5v+0Psom2H8SI/Wr8O0AkbubE0LxQaoCZ09CfFSlpwnqlHCRwqvC7aKL1GQKa+82UNpocVwI9QQnYf6VC3guUXvA8CXjz0ZtvIcIqmsgjYyEC1kms4cIjZMP5cQ6x0ckQnvYXhf2huzmAq8YvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803988; c=relaxed/simple; bh=CsW71WxzvTmJmMbJ/BvYlkrrdwKSIbpP1tIBowkQPsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=prqb0Tu5QDcJcMuVckXu+FiTv9tME1iRtMzl69+545UJB5YBqBpibCWjKjJWpqPPuUnYKmhvBq6b6+ART3p8eC+/fAxwMrBBKV0L6S7HuIAzLGmfS9HgOmtqqzWLOARD3zF0TuaLXQSM8ykGqVC6b7MdYkKDMAilC+r/PVxsjXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bRkT7k2Z; 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="bRkT7k2Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C86B0C32783; Mon, 22 Apr 2024 16:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803987; bh=CsW71WxzvTmJmMbJ/BvYlkrrdwKSIbpP1tIBowkQPsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRkT7k2ZCWI/I4PALThNhM/EKHTp86OdAaRQOp5VfvLRn9sqwoVwycAOmafOeh/kj Huy4X4VOe0ibK4LbIO7LUSqoB+RaR925EF25uNFf54iCTJpR/YSHtmajxwBlcSyocE EtpVI/0Z+FEM0V0cokjGaS2mt7hO35Ve2p1tFr1PVbYvI+IZLaRftUvIzIBZZj/Fk4 IVDRpb4hMFWh5Py0Z/D4qb8wz5aXtWP3ODtepK9lCGThqkrNhdLvxM+X8PTshZLCsx VDykFwcmz4YxJVg0rm8Jy33VWuiLIN07FkS3EYmjl5Ae2XtPndqJ6gUPgvW77Khtlb 8twGyjCjhNAjA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 26/67] xfs: store an ops pointer in struct xfs_defer_pending Date: Mon, 22 Apr 2024 18:25:48 +0200 Message-ID: <20240422163832.858420-28-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 7f2f7531e0d455f1abb9f48fbbe17c37e8742590 The dfp_type field in struct xfs_defer_pending is only used to either look up the operations associated with the pending word or in trace points. Replace it with a direct pointer to the operations vector, and store a pretty name in the vector for tracing. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/defer_item.c | 6 ++++++ libxfs/xfs_defer.c | 43 +++++++++++++++++-------------------------- libxfs/xfs_defer.h | 5 +++-- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index c4a16c7ce..9e6899fea 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -152,6 +152,7 @@ xfs_extent_free_cancel_item( } const struct xfs_defer_op_type xfs_extent_free_defer_type = { + .name = "extent_free", .create_intent = xfs_extent_free_create_intent, .abort_intent = xfs_extent_free_abort_intent, .create_done = xfs_extent_free_create_done, @@ -195,6 +196,7 @@ xfs_agfl_free_finish_item( /* sub-type with special handling for AGFL deferred frees */ const struct xfs_defer_op_type xfs_agfl_free_defer_type = { + .name = "agfl_free", .create_intent = xfs_extent_free_create_intent, .abort_intent = xfs_extent_free_abort_intent, .create_done = xfs_extent_free_create_done, @@ -306,6 +308,7 @@ xfs_rmap_update_cancel_item( } const struct xfs_defer_op_type xfs_rmap_update_defer_type = { + .name = "rmap", .create_intent = xfs_rmap_update_create_intent, .abort_intent = xfs_rmap_update_abort_intent, .create_done = xfs_rmap_update_create_done, @@ -424,6 +427,7 @@ xfs_refcount_update_cancel_item( } const struct xfs_defer_op_type xfs_refcount_update_defer_type = { + .name = "refcount", .create_intent = xfs_refcount_update_create_intent, .abort_intent = xfs_refcount_update_abort_intent, .create_done = xfs_refcount_update_create_done, @@ -546,6 +550,7 @@ xfs_bmap_update_cancel_item( } const struct xfs_defer_op_type xfs_bmap_update_defer_type = { + .name = "bmap", .create_intent = xfs_bmap_update_create_intent, .abort_intent = xfs_bmap_update_abort_intent, .create_done = xfs_bmap_update_create_done, @@ -641,6 +646,7 @@ xfs_attr_cancel_item( } const struct xfs_defer_op_type xfs_attr_defer_type = { + .name = "attr", .max_items = 1, .create_intent = xfs_attr_create_intent, .abort_intent = xfs_attr_abort_intent, diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 98f1cbe6a..bb5411b84 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -245,7 +245,6 @@ xfs_defer_create_done( struct xfs_trans *tp, struct xfs_defer_pending *dfp) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; struct xfs_log_item *lip; /* If there is no log intent item, there can be no log done item. */ @@ -260,7 +259,7 @@ xfs_defer_create_done( * 2.) shuts down the filesystem */ tp->t_flags |= XFS_TRANS_DIRTY; - lip = ops->create_done(tp, dfp->dfp_intent, dfp->dfp_count); + lip = dfp->dfp_ops->create_done(tp, dfp->dfp_intent, dfp->dfp_count); if (!lip) return; @@ -281,13 +280,13 @@ xfs_defer_create_intent( struct xfs_defer_pending *dfp, bool sort) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; struct xfs_log_item *lip; if (dfp->dfp_intent) return 1; - lip = ops->create_intent(tp, &dfp->dfp_work, dfp->dfp_count, sort); + lip = dfp->dfp_ops->create_intent(tp, &dfp->dfp_work, dfp->dfp_count, + sort); if (!lip) return 0; if (IS_ERR(lip)) @@ -332,12 +331,10 @@ xfs_defer_pending_abort( struct xfs_mount *mp, struct xfs_defer_pending *dfp) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; - trace_xfs_defer_pending_abort(mp, dfp); if (dfp->dfp_intent && !dfp->dfp_done) { - ops->abort_intent(dfp->dfp_intent); + dfp->dfp_ops->abort_intent(dfp->dfp_intent); dfp->dfp_intent = NULL; } } @@ -347,7 +344,6 @@ xfs_defer_pending_cancel_work( struct xfs_mount *mp, struct xfs_defer_pending *dfp) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; struct list_head *pwi; struct list_head *n; @@ -358,7 +354,7 @@ xfs_defer_pending_cancel_work( list_del(pwi); dfp->dfp_count--; trace_xfs_defer_cancel_item(mp, dfp, pwi); - ops->cancel_item(pwi); + dfp->dfp_ops->cancel_item(pwi); } ASSERT(dfp->dfp_count == 0); kmem_cache_free(xfs_defer_pending_cache, dfp); @@ -516,11 +512,10 @@ xfs_defer_relog_intent( struct xfs_defer_pending *dfp) { struct xfs_log_item *lip; - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; xfs_defer_create_done(tp, dfp); - lip = ops->relog_intent(tp, dfp->dfp_intent, dfp->dfp_done); + lip = dfp->dfp_ops->relog_intent(tp, dfp->dfp_intent, dfp->dfp_done); if (lip) { xfs_trans_add_item(tp, lip); set_bit(XFS_LI_DIRTY, &lip->li_flags); @@ -587,7 +582,7 @@ xfs_defer_finish_one( struct xfs_trans *tp, struct xfs_defer_pending *dfp) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; + const struct xfs_defer_op_type *ops = dfp->dfp_ops; struct xfs_btree_cur *state = NULL; struct list_head *li, *n; int error; @@ -784,7 +779,6 @@ xfs_defer_cancel( static inline struct xfs_defer_pending * xfs_defer_find_last( struct xfs_trans *tp, - enum xfs_defer_ops_type type, const struct xfs_defer_op_type *ops) { struct xfs_defer_pending *dfp = NULL; @@ -797,7 +791,7 @@ xfs_defer_find_last( dfp_list); /* Wrong type? */ - if (dfp->dfp_type != type) + if (dfp->dfp_ops != ops) return NULL; return dfp; } @@ -830,13 +824,13 @@ xfs_defer_can_append( static inline struct xfs_defer_pending * xfs_defer_alloc( struct xfs_trans *tp, - enum xfs_defer_ops_type type) + const struct xfs_defer_op_type *ops) { struct xfs_defer_pending *dfp; dfp = kmem_cache_zalloc(xfs_defer_pending_cache, GFP_NOFS | __GFP_NOFAIL); - dfp->dfp_type = type; + dfp->dfp_ops = ops; INIT_LIST_HEAD(&dfp->dfp_work); list_add_tail(&dfp->dfp_list, &tp->t_dfops); @@ -856,9 +850,9 @@ xfs_defer_add( ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); - dfp = xfs_defer_find_last(tp, type, ops); + dfp = xfs_defer_find_last(tp, ops); if (!dfp || !xfs_defer_can_append(dfp, ops)) - dfp = xfs_defer_alloc(tp, type); + dfp = xfs_defer_alloc(tp, ops); xfs_defer_add_item(dfp, li); trace_xfs_defer_add_item(tp->t_mountp, dfp, li); @@ -874,17 +868,15 @@ xfs_defer_add_barrier( struct xfs_trans *tp) { struct xfs_defer_pending *dfp; - const enum xfs_defer_ops_type type = XFS_DEFER_OPS_TYPE_BARRIER; - const struct xfs_defer_op_type *ops = defer_op_types[type]; ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); /* If the last defer op added was a barrier, we're done. */ - dfp = xfs_defer_find_last(tp, type, ops); + dfp = xfs_defer_find_last(tp, &xfs_barrier_defer_type); if (dfp) return; - xfs_defer_alloc(tp, type); + xfs_defer_alloc(tp, &xfs_barrier_defer_type); trace_xfs_defer_add_item(tp->t_mountp, dfp, NULL); } @@ -903,7 +895,7 @@ xfs_defer_start_recovery( dfp = kmem_cache_zalloc(xfs_defer_pending_cache, GFP_NOFS | __GFP_NOFAIL); - dfp->dfp_type = dfp_type; + dfp->dfp_ops = defer_op_types[dfp_type]; dfp->dfp_intent = lip; INIT_LIST_HEAD(&dfp->dfp_work); list_add_tail(&dfp->dfp_list, r_dfops); @@ -929,13 +921,12 @@ xfs_defer_finish_recovery( struct xfs_defer_pending *dfp, struct list_head *capture_list) { - const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type]; int error; - error = ops->recover_work(dfp, capture_list); + error = dfp->dfp_ops->recover_work(dfp, capture_list); if (error) trace_xlog_intent_recovery_failed(mp, error, - ops->recover_work); + dfp->dfp_ops->recover_work); return error; } diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 5b1990ef3..957a06278 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -34,9 +34,9 @@ struct xfs_defer_pending { struct list_head dfp_work; /* work items */ struct xfs_log_item *dfp_intent; /* log intent item */ struct xfs_log_item *dfp_done; /* log done item */ + const struct xfs_defer_op_type *dfp_ops; unsigned int dfp_count; /* # extent items */ unsigned int dfp_flags; - enum xfs_defer_ops_type dfp_type; }; /* @@ -61,6 +61,8 @@ void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp); /* Description of a deferred type. */ struct xfs_defer_op_type { + const char *name; + unsigned int max_items; struct xfs_log_item *(*create_intent)(struct xfs_trans *tp, struct list_head *items, unsigned int count, bool sort); void (*abort_intent)(struct xfs_log_item *intent); @@ -76,7 +78,6 @@ struct xfs_defer_op_type { struct xfs_log_item *(*relog_intent)(struct xfs_trans *tp, struct xfs_log_item *intent, struct xfs_log_item *done_item); - unsigned int max_items; }; extern const struct xfs_defer_op_type xfs_bmap_update_defer_type; From patchwork Mon Apr 22 16:25:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638707 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 A1F662EB11 for ; Mon, 22 Apr 2024 16:39: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=1713803989; cv=none; b=C3J0uHDpUY5xPkF0LHhKLLGgsLrtdJk/U2tns7ud0o1RIBwakXmDX0RDeY8C5n3v99FGm1V5QvXQiYBt2oGBvZ91YObYI84Wrn8hO/uQEfp/44SAAK1c1nU24l0piMNFNylVb6Z4T5tdbtDpYh4kL5Bq76A3x5msf1ciSNBvDtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803989; c=relaxed/simple; bh=AI59iQzEZ+B9kXgW+eKlfBTqice+eI8bN3YrL77T8Hs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DDncr8xKD4kIIeinIjVn5IT6gPGZOMb4V6KSMDee8ja8dneFLZT/OArenPyCME+f7YL2R67M8AsAvlowDS4aAUzfY8kiURXxBozyOD34IMooQf7qE8HhGIblG2sJsPh5SfdJCpNiSVcfOH3k3XUN29lnvZ9V5ZxvAWetKvM1N7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NQH0+IoJ; 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="NQH0+IoJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 703BBC113CC; Mon, 22 Apr 2024 16:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803989; bh=AI59iQzEZ+B9kXgW+eKlfBTqice+eI8bN3YrL77T8Hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NQH0+IoJ5B+2RtS+2/BPCQ4dsr6HWRHhS4O5DptWVxxkaGcTKGSHDz3oRPFADATAI AlSxh+6DMBw67KROLHL2wFEyr4nIBVmvQ8g/Hg+Cf8ekdE1Et7nhqENnZsVNCX6uVl 2vB7FqtwOsmbhObK37yRoDuxJeg09pEricDVHfl0DxtALN9ofkHVYCi8BWiCXxyQ38 LBD/sHryVA/wvxRST0OzRSP/dblyWGSYdMYfZJ+ujGq0bhH14SeEvYWoOBg6/v2YmA EXwiqnz6FB7+x3s03D7saAr6Mg/f4HYl4IUtQ/V9DhvCbzhOEKOGKqKhlHGVRQlL8P lyGdMHVeouaSA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 27/67] xfs: pass the defer ops instead of type to xfs_defer_start_recovery Date: Mon, 22 Apr 2024 18:25:49 +0200 Message-ID: <20240422163832.858420-29-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: dc22af64368291a86fb6b7eb2adab21c815836b7 xfs_defer_start_recovery is only called from xlog_recover_intent_item, and the callers of that all have the actual xfs_defer_ops_type operation vector at hand. Pass that directly instead of looking it up from the defer_op_types table. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 6 +++--- libxfs/xfs_defer.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index bb5411b84..033283017 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -888,14 +888,14 @@ xfs_defer_add_barrier( void xfs_defer_start_recovery( struct xfs_log_item *lip, - enum xfs_defer_ops_type dfp_type, - struct list_head *r_dfops) + struct list_head *r_dfops, + const struct xfs_defer_op_type *ops) { struct xfs_defer_pending *dfp; dfp = kmem_cache_zalloc(xfs_defer_pending_cache, GFP_NOFS | __GFP_NOFAIL); - dfp->dfp_ops = defer_op_types[dfp_type]; + dfp->dfp_ops = ops; dfp->dfp_intent = lip; INIT_LIST_HEAD(&dfp->dfp_work); list_add_tail(&dfp->dfp_list, r_dfops); diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 957a06278..60de91b66 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -147,7 +147,7 @@ void xfs_defer_ops_capture_abort(struct xfs_mount *mp, void xfs_defer_resources_rele(struct xfs_defer_resources *dres); void xfs_defer_start_recovery(struct xfs_log_item *lip, - enum xfs_defer_ops_type dfp_type, struct list_head *r_dfops); + struct list_head *r_dfops, const struct xfs_defer_op_type *ops); void xfs_defer_cancel_recovery(struct xfs_mount *mp, struct xfs_defer_pending *dfp); int xfs_defer_finish_recovery(struct xfs_mount *mp, From patchwork Mon Apr 22 16:25:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638708 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 915F2153BE3 for ; Mon, 22 Apr 2024 16:39: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=1713803991; cv=none; b=n3oZ9JGoD/SdeYgPdmm4KwvinanB1kOwEnvamQ/mIMaZcwTyjS+RgPrCzHdRvS8PbNMvzZpQW8Jbpp5kG/iTwMVl9aTrxY7OSVWN1vUf5v8Fbxb6IRYHF2bswDlRtXwrmX/XtQZ5U96ApNr1+WEOl/ofzfutdDDiG38bhpOd3VM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803991; c=relaxed/simple; bh=H3fkKs8b6Hq8a3oytfV8/+ZwnNUhn2wCTDTUvCvVAs0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=drhOb7iZQ8bC9D7TIluxQASvJ2hZoeI9BaPwV5G0LT0O2e3NiC0ZPLcEIVr8fyOpZhx/E0cyv+K2nyx2cuuhK0eQLRQv2OV2bVksS3mFuJXheS6uEVHRhCQI1zQ9h5HbTFhLWMYYFCfHKXBOaByiH3su+SVrc5Knn3B7WDJzHy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YC884Q2d; 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="YC884Q2d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1857FC32782; Mon, 22 Apr 2024 16:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803991; bh=H3fkKs8b6Hq8a3oytfV8/+ZwnNUhn2wCTDTUvCvVAs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YC884Q2dAWGdw/10oPCdkGWI/3wgREGlji+Mk+yN0VMCYS9OwxOlGZ2u7uGoB3m9/ 1U2qx5GOnJ4o2lGo/l6rZbpsNRxOIE11RLf9hc1bsS407bwz9z1G7Nb+ONayVRSQFA YC55JtfMMdqP8inAiQ/uKM17Zu2o0df8M9/HUEZQ30VYHFspWYwfWh8A6E16pvg4WH 82XDIVR2DmkyzIn58ORpnAwYnxoHyGfhJYzL30vj3JutwWcPRESH9tDJCSkhSVO5ya 6rl2y4qQXjVuirS9ZtMjpek9gDW/FeTJymZvDp9y6ZMR5vMMlW/OMsQuOk+oWvOYxH uv9669cg4JCYQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 28/67] xfs: pass the defer ops directly to xfs_defer_add Date: Mon, 22 Apr 2024 18:25:50 +0200 Message-ID: <20240422163832.858420-30-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 603ce8ab12094a2d9483c79a7541335e258a5328 Pass a pointer to the xfs_defer_op_type structure to xfs_defer_add and remove the indirection through the xfs_defer_ops_type enum and a global table of all possible operations. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_alloc.c | 4 ++-- libxfs/xfs_attr.c | 2 +- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_defer.c | 16 ++-------------- libxfs/xfs_defer.h | 18 ++---------------- libxfs/xfs_refcount.c | 2 +- libxfs/xfs_rmap.c | 2 +- 7 files changed, 10 insertions(+), 36 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 463381be7..aaa159615 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2510,7 +2510,7 @@ xfs_defer_agfl_block( trace_xfs_agfl_free_defer(mp, agno, 0, agbno, 1); xfs_extent_free_get_group(mp, xefi); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &xefi->xefi_list); + xfs_defer_add(tp, &xefi->xefi_list, &xfs_agfl_free_defer_type); return 0; } @@ -2574,7 +2574,7 @@ xfs_defer_extent_free( XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len); xfs_extent_free_get_group(mp, xefi); - *dfpp = xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &xefi->xefi_list); + *dfpp = xfs_defer_add(tp, &xefi->xefi_list, &xfs_extent_free_defer_type); return 0; } diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 550ca6b2e..cb6c8d081 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -904,7 +904,7 @@ xfs_attr_defer_add( ASSERT(0); } - xfs_defer_add(args->trans, XFS_DEFER_OPS_TYPE_ATTR, &new->xattri_list); + xfs_defer_add(args->trans, &new->xattri_list, &xfs_attr_defer_type); trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp); } diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 20ec22dfc..6d23c5e3e 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -6085,7 +6085,7 @@ __xfs_bmap_add( bi->bi_bmap = *bmap; xfs_bmap_update_get_group(tp->t_mountp, bi); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_BMAP, &bi->bi_list); + xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type); return 0; } diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 033283017..077e99298 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -229,16 +229,6 @@ static const struct xfs_defer_op_type xfs_barrier_defer_type = { .cancel_item = xfs_defer_barrier_cancel_item, }; -static const struct xfs_defer_op_type *defer_op_types[] = { - [XFS_DEFER_OPS_TYPE_BMAP] = &xfs_bmap_update_defer_type, - [XFS_DEFER_OPS_TYPE_REFCOUNT] = &xfs_refcount_update_defer_type, - [XFS_DEFER_OPS_TYPE_RMAP] = &xfs_rmap_update_defer_type, - [XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type, - [XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type, - [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, - [XFS_DEFER_OPS_TYPE_BARRIER] = &xfs_barrier_defer_type, -}; - /* Create a log intent done item for a log intent item. */ static inline void xfs_defer_create_done( @@ -841,14 +831,12 @@ xfs_defer_alloc( struct xfs_defer_pending * xfs_defer_add( struct xfs_trans *tp, - enum xfs_defer_ops_type type, - struct list_head *li) + struct list_head *li, + const struct xfs_defer_op_type *ops) { struct xfs_defer_pending *dfp = NULL; - const struct xfs_defer_op_type *ops = defer_op_types[type]; ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); - BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); dfp = xfs_defer_find_last(tp, ops); if (!dfp || !xfs_defer_can_append(dfp, ops)) diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 60de91b66..18a9fb92d 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -10,20 +10,6 @@ struct xfs_btree_cur; struct xfs_defer_op_type; struct xfs_defer_capture; -/* - * Header for deferred operation list. - */ -enum xfs_defer_ops_type { - XFS_DEFER_OPS_TYPE_BMAP, - XFS_DEFER_OPS_TYPE_REFCOUNT, - XFS_DEFER_OPS_TYPE_RMAP, - XFS_DEFER_OPS_TYPE_FREE, - XFS_DEFER_OPS_TYPE_AGFL_FREE, - XFS_DEFER_OPS_TYPE_ATTR, - XFS_DEFER_OPS_TYPE_BARRIER, - XFS_DEFER_OPS_TYPE_MAX, -}; - /* * Save a log intent item and a list of extents, so that we can replay * whatever action had to happen to the extent list and file the log done @@ -51,8 +37,8 @@ struct xfs_defer_pending { void xfs_defer_item_pause(struct xfs_trans *tp, struct xfs_defer_pending *dfp); void xfs_defer_item_unpause(struct xfs_trans *tp, struct xfs_defer_pending *dfp); -struct xfs_defer_pending *xfs_defer_add(struct xfs_trans *tp, - enum xfs_defer_ops_type type, struct list_head *h); +struct xfs_defer_pending *xfs_defer_add(struct xfs_trans *tp, struct list_head *h, + const struct xfs_defer_op_type *ops); int xfs_defer_finish_noroll(struct xfs_trans **tp); int xfs_defer_finish(struct xfs_trans **tp); int xfs_defer_finish_one(struct xfs_trans *tp, struct xfs_defer_pending *dfp); diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 2284b45fb..45f8134e4 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1457,7 +1457,7 @@ __xfs_refcount_add( ri->ri_blockcount = blockcount; xfs_refcount_update_get_group(tp->t_mountp, ri); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_REFCOUNT, &ri->ri_list); + xfs_defer_add(tp, &ri->ri_list, &xfs_refcount_update_defer_type); } /* diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index 5ff6d7a32..4731e10d2 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -2566,7 +2566,7 @@ __xfs_rmap_add( ri->ri_bmap = *bmap; xfs_rmap_update_get_group(tp->t_mountp, ri); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_RMAP, &ri->ri_list); + xfs_defer_add(tp, &ri->ri_list, &xfs_rmap_update_defer_type); } /* Map an extent into a file. */ From patchwork Mon Apr 22 16:25:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638709 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 90783153BE3 for ; Mon, 22 Apr 2024 16:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803992; cv=none; b=WVm9b1x3Qn2HUWPGpUH9L5cUNRsb9rYd28HVN5wb+6FjjSkEzUgKENH+J5OzKha2zSCbp3Myr8YCG0CK9JzDG+WIdWXXJ+miO1ux9rv1Nnvr6Ab8J73cns594W4bWSKsgYp9crIAkFiJu9TrS+rZeU4Um0H0x+ffvPkP0ulWsjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803992; c=relaxed/simple; bh=K9VpRABzGPOPrZVrFlHG3LAJglKAiWczgDiSdsRXaVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LlDm2k1L+R3yMXUAsAX5peGo+5V+pAkwThxV9PZnlYHB3V8brO8/xSfWd8f5v14iQmzN0wrBKR5WEitnIolTz0fS6BvmB/gCCQVqWxqiUeV20u9iVrNLNlWGgAK+K4+zHoKUsrTdh2Erxvs+qbNfsUJgfKFLpzqFGVcAeSf1pGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sPoRi2yE; 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="sPoRi2yE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 840D0C116B1; Mon, 22 Apr 2024 16:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803992; bh=K9VpRABzGPOPrZVrFlHG3LAJglKAiWczgDiSdsRXaVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sPoRi2yERV1OgzWasz81i/dhW2J8h2j55DI8lcb57mk3NXnQJNYfQkHkAwXpkRaWp +KW+9u3gLBSwMHDSIQhlAQOGQaCbmY9Xrm0kU/FR7kyHT9GZ8tl0AMbXDiwJ/dTBFL VJd6o0PdMIweVqLzGsBUGoJDhk0HLWRdn/Kw9q/ylVEHD/eWdZ7BjgtLg4O3WFisvy cmuRx05rUIXEZz3nABcz+OBHk/E2Iql6/dXgp/RYlmFV6o7X5lqh4vo0JmW2vnvU0O qfJmOZn1EelyQJb1mtbFYgB+I7MbHsAkSvGpZ6AMz+IaYL4YKS+PCjJOKpJxVE4sSC ZKm6BbnFrkP0A== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 29/67] xfs: force all buffers to be written during btree bulk load Date: Mon, 22 Apr 2024 18:25:51 +0200 Message-ID: <20240422163832.858420-31-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 13ae04d8d45227c2ba51e188daf9fc13d08a1b12 While stress-testing online repair of btrees, I noticed periodic assertion failures from the buffer cache about buffers with incorrect DELWRI_Q state. Looking further, I observed this race between the AIL trying to write out a btree block and repair zapping a btree block after the fact: AIL: Repair0: pin buffer X delwri_queue: set DELWRI_Q add to delwri list stale buf X: clear DELWRI_Q does not clear b_list free space X delwri_submit # oops Worse yet, I discovered that running the same repair over and over in a tight loop can result in a second race that cause data integrity problems with the repair: AIL: Repair0: Repair1: pin buffer X delwri_queue: set DELWRI_Q add to delwri list stale buf X: clear DELWRI_Q does not clear b_list free space X find free space X get buffer rewrite buffer delwri_queue: set DELWRI_Q already on a list, do not add BAD: committed tree root before all blocks written delwri_submit # too late now I traced this to my own misunderstanding of how the delwri lists work, particularly with regards to the AIL's buffer list. If a buffer is logged and committed, the buffer can end up on that AIL buffer list. If btree repairs are run twice in rapid succession, it's possible that the first repair will invalidate the buffer and free it before the next time the AIL wakes up. Marking the buffer stale clears DELWRI_Q from the buffer state without removing the buffer from its delwri list. The buffer doesn't know which list it's on, so it cannot know which lock to take to protect the list for a removal. If the second repair allocates the same block, it will then recycle the buffer to start writing the new btree block. Meanwhile, if the AIL wakes up and walks the buffer list, it will ignore the buffer because it can't lock it, and go back to sleep. When the second repair calls delwri_queue to put the buffer on the list of buffers to write before committing the new btree, it will set DELWRI_Q again, but since the buffer hasn't been removed from the AIL's buffer list, it won't add it to the bulkload buffer's list. This is incorrect, because the bulkload caller relies on delwri_submit to ensure that all the buffers have been sent to disk /before/ required for data consistency. Worse, the AIL won't clear DELWRI_Q from the buffer when it does finally drop it, so the next thread to walk through the btree will trip over a debug assertion on that flag. To fix this, create a new function that waits for the buffer to be removed from any other delwri lists before adding the buffer to the caller's delwri list. By waiting for the buffer to clear both the delwri list and any potential delwri wait list, we can be sure that repair will initiate writes of all buffers and report all write errors back to userspace instead of committing the new structure. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/libxfs_io.h | 11 +++++++++++ libxfs/xfs_btree_staging.c | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h index 267ea9796..259c6a7cf 100644 --- a/libxfs/libxfs_io.h +++ b/libxfs/libxfs_io.h @@ -244,6 +244,17 @@ xfs_buf_delwri_queue(struct xfs_buf *bp, struct list_head *buffer_list) return true; } +static inline void +xfs_buf_delwri_queue_here(struct xfs_buf *bp, struct list_head *buffer_list) +{ + ASSERT(list_empty(&bp->b_list)); + + /* This buffer is uptodate; don't let it get reread. */ + libxfs_buf_mark_dirty(bp); + + xfs_buf_delwri_queue(bp, buffer_list); +} + int xfs_buf_delwri_submit(struct list_head *buffer_list); void xfs_buf_delwri_cancel(struct list_head *list); diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index a6a907916..baf7f4226 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -342,9 +342,7 @@ xfs_btree_bload_drop_buf( if (*bpp == NULL) return; - if (!xfs_buf_delwri_queue(*bpp, buffers_list)) - ASSERT(0); - + xfs_buf_delwri_queue_here(*bpp, buffers_list); xfs_buf_relse(*bpp); *bpp = NULL; } From patchwork Mon Apr 22 16:25:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638710 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 12B7B153BF2 for ; Mon, 22 Apr 2024 16:39: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=1713803994; cv=none; b=Y9iduw7lDtJQz0v0mOsMuWyc8uBHSlmtny0zK/dNaPgI3Ri9GWQyBGHZfEGNfZOJx04lOSXQBDml/rT4ITLCkKwruarZ/WKmFnzEIygyB4QX6wsQQcsURMKyuO322UBWd3cXt/cvhzgnCK852vLSCvxxNIxDfUtxNlO531Rqb/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803994; c=relaxed/simple; bh=LfYwI2i/Cl+MWr/gX91Gs26/pBz5iPrUgY4Kaq/uTDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FlSLx+c1zCAGPWppTwRa4FFfShfaFpbpBJ5xGHz2TmkqXlGyEbxBSZozx4/e6npzrggjkXXEWClWWBApHA/4xarKWVlhbjYdHvoqn/U8pJ0LGvsctiTIXJ7YLiLxJSzNWd+WK03YZIlA/t4KDkp2Ykb3oToYYqdRu9ErRCnzFuU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TUMJQje7; 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="TUMJQje7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBB82C113CC; Mon, 22 Apr 2024 16:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803993; bh=LfYwI2i/Cl+MWr/gX91Gs26/pBz5iPrUgY4Kaq/uTDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TUMJQje7pS9FlHyhBw/P1qWYKQNhvlFbcb3Mf4GTvwUFwbLxlzRzqqoV/+cwZQFDZ yrcyotOnG4twFLi7FgevpEomI+OdqCIesUl6yQ7ffJc3CrAa+08Hy00E8Y0UKjNQiH N/OmzGEXd17XwG0bkG64wXh4WpMxXke/6N5qQQdyPo8RkSQ67BKbQMSWdp4DbyjDEz BhgBdzY8Eu8iTJ8eNQ29vd/5h1cRPcJAXq7rxj9W9SwoqJZbzho0FLpuyfq1INxTQ9 x1ENkOG93xmPShwOY7qDCIR0mECb+UWdMVSInxuuGvT/eDolrBPJyLiJ/BfKEZDgDN Fsf5SrJliSHFQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 30/67] xfs: set XBF_DONE on newly formatted btree block that are ready for writing Date: Mon, 22 Apr 2024 18:25:52 +0200 Message-ID: <20240422163832.858420-32-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: c1e0f8e6fb060b23b6f1b82eb4265983f7d271f8 The btree bulkloading code calls xfs_buf_delwri_queue_here when it has finished formatting a new btree block and wants to queue it to be written to disk. Once the new btree root has been committed, the blocks (and hence the buffers) will be accessible to the rest of the filesystem. Mark each new buffer as DONE when adding it to the delwri list so that the next btree traversal can skip reloading the contents from disk. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_btree_staging.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index baf7f4226..ae2d9c63f 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -342,6 +342,12 @@ xfs_btree_bload_drop_buf( if (*bpp == NULL) return; + /* + * Mark this buffer XBF_DONE (i.e. uptodate) so that a subsequent + * xfs_buf_read will not pointlessly reread the contents from the disk. + */ + (*bpp)->b_flags |= XBF_DONE; + xfs_buf_delwri_queue_here(*bpp, buffers_list); xfs_buf_relse(*bpp); *bpp = NULL; From patchwork Mon Apr 22 16:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638711 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 E9137328A0 for ; Mon, 22 Apr 2024 16:39: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=1713803996; cv=none; b=oVt5cvB8awRykyAiQ86PL3APPpsF/fRWT0HvdbwQeYEIVDwIsdqgx+c+x5GM5oGD59Kz5ur0DobC4g/CheMJlwoSbLUgChxLfQZ4zZCP0EsGRPAVYeD9dJVUlUB/N0taJjTP7qqaIgc2yYhnhVF7eS1U0aRMfBHxKMrWvK9rj/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803996; c=relaxed/simple; bh=axADbrm1DdtL0QWmuCyYnKjOPgKPBQJx7q4+VK1lzPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UdATXJvZC1YU7r8OAeG54Hhp0ATqyGJ2OpHaYqSAl/aYpPtRGVrsb/nGVF3xJVh/xVbGiO6ehbSHFoDHrN5XX3AmzNqZ4dsPqC6TViVPge+EvC7Qblk+oqhARi2HblR7dy6Wc9quJSNyZf+p+BI3l20vHKY4SNK5dsWMvNuzLlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TWhfe0aC; 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="TWhfe0aC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B06C113CC; Mon, 22 Apr 2024 16:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803995; bh=axADbrm1DdtL0QWmuCyYnKjOPgKPBQJx7q4+VK1lzPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWhfe0aCGbRQiIW/v2t7bVrOd72XBFeq8WfCKP6uNS/EVOBmY20z8Oxe6Act3Wcwo PJqXUk08XhXE+XLwqFqZAocQvBOZGo0uphtHflUkHoVQsszzxFPUUUbqAdXHSj9IjG +ESz/muXbWIpQjGbAaeu7BqgeG+N5RJWSMSbS2lRW5BnC+tx2+87A/7nb5w1kT6lgC 5EysCFN6qGDnnCmb+4qBHElbOT31dR8UB+Hqk5JW8Paj/au65ywVupZ9KGg5qbbEjm HyFA4tOs4sCUcgbh+XzOyJ/CIHFj+9ArY6CIA2MLeMmcEa8CmAkiokJ0QcWZT0j8p3 FGnNfbLDpzYfw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 31/67] xfs: read leaf blocks when computing keys for bulkloading into node blocks Date: Mon, 22 Apr 2024 18:25:53 +0200 Message-ID: <20240422163832.858420-33-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 26de64629d8b439a03bce243f14a46f7440729f3 When constructing a new btree, xfs_btree_bload_node needs to read the btree blocks for level N to compute the keyptrs for the blocks that will be loaded into level N+1. The level N blocks must be formatted at that point. A subsequent patch will change the btree bulkloader to write new btree blocks in 256K chunks to moderate memory consumption if the new btree is very large. As a consequence of that, it's possible that the buffers for lower level blocks might have been reclaimed by the time the node builder comes back to the block. Therefore, change xfs_btree_bload_node to read the lower level blocks to handle the reclaimed buffer case. As a side effect, the read will increase the LRU refs, which will bias towards keeping new btree buffers in memory after the new btree commits. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree.h | 3 +++ libxfs/xfs_btree_staging.c | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 85f8bef06..97962fc16 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -1327,7 +1327,7 @@ xfs_btree_get_buf_block( * Read in the buffer at the given ptr and return the buffer and * the block pointer within the buffer. */ -STATIC int +int xfs_btree_read_buf_block( struct xfs_btree_cur *cur, const union xfs_btree_ptr *ptr, diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 4d68a58be..e0875cec4 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -700,6 +700,9 @@ void xfs_btree_set_ptr_null(struct xfs_btree_cur *cur, int xfs_btree_get_buf_block(struct xfs_btree_cur *cur, const union xfs_btree_ptr *ptr, struct xfs_btree_block **block, struct xfs_buf **bpp); +int xfs_btree_read_buf_block(struct xfs_btree_cur *cur, + const union xfs_btree_ptr *ptr, int flags, + struct xfs_btree_block **block, struct xfs_buf **bpp); void xfs_btree_set_sibling(struct xfs_btree_cur *cur, struct xfs_btree_block *block, const union xfs_btree_ptr *ptr, int lr); diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index ae2d9c63f..be0b43e45 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -489,7 +489,12 @@ xfs_btree_bload_node( ASSERT(!xfs_btree_ptr_is_null(cur, child_ptr)); - ret = xfs_btree_get_buf_block(cur, child_ptr, &child_block, + /* + * Read the lower-level block in case the buffer for it has + * been reclaimed. LRU refs will be set on the block, which is + * desirable if the new btree commits. + */ + ret = xfs_btree_read_buf_block(cur, child_ptr, 0, &child_block, &child_bp); if (ret) return ret; From patchwork Mon Apr 22 16:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638712 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 3B0C015382C for ; Mon, 22 Apr 2024 16:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803997; cv=none; b=T4ec4I36d9a6O66bn299enddmoYmg/R/PcLTMsuLtkCWG5gX+aSz1tIXhNt01rRwycxl9iWfNIdk8EGHUP5VBFS99CtDtyN8Aq6wT1X3qauL+bwfkDlNh8A3oAw9tN17oTFCxJ3K1ZjsAX/HAwKAEioNCM4shxrZaQ0S67j1zBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803997; c=relaxed/simple; bh=UQR8Fw2GhLnOYbtRzhcoWtczDKRjReTilNHxkEes6XI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ApdRO6C6BFj0qxHWVk+iEwDx7pd91VP1mPpVcwsZfENHuTWi3x2BQCuJqjcb/Ae8H3UvpdsF16ee7ijR/hIe0gOgF4j8uhHXw8vFotGf+2l51O4XONvLJ0zJGK96aXxuWkIhg9vqGoiLJcdIu/YY4+vkO02j+b+WOnknDQQ7zIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pVKqQJIU; 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="pVKqQJIU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 092D9C32782; Mon, 22 Apr 2024 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803997; bh=UQR8Fw2GhLnOYbtRzhcoWtczDKRjReTilNHxkEes6XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pVKqQJIUfNTKHE1lFrnslPVEgFe9ov34t5C6BbEuoAoqJGsfG5vdFQ3XszAjZKtKl cnzroHYld+U49X1ZV5e852BHb9shwiIMINL1andEnDTIsRMqBpeNLWlK0Hgpet/Asg CIdXiEjM/L3gtDtMAY+R0xIfK0IrqG/nAOdS9/cNryFX/7EwdpzhrPJ6CuPaC0IlV7 n+mPuu3LYVjso7Q2C5kKTKH9OwFsetA6BcGyrI1cRiQ37qWHoagmgp/L1StPhvX5+c Z4JPvl51X4ZNSpO3TpJnQUB8Oz8oLgSr9Ph5mFh5Z0czIjVlaRNJqTaPv54bc3rryr SPbS7U6VXcS6w== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 32/67] xfs: move btree bulkload record initialization to ->get_record implementations Date: Mon, 22 Apr 2024 18:25:54 +0200 Message-ID: <20240422163832.858420-34-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 6dfeb0c2ecde71d61af77f65eabbdd6ca9315161 When we're performing a bulk load of a btree, move the code that actually stores the btree record in the new btree block out of the generic code and into the individual ->get_record implementations. This is preparation for being able to store multiple records with a single indirect call. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_btree_staging.c | 17 +++++------- libxfs/xfs_btree_staging.h | 15 ++++++---- repair/agbtree.c | 56 ++++++++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 836ace1ba..4edc8a7e1 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -53,6 +53,7 @@ #define xfs_btree_bload_compute_geometry libxfs_btree_bload_compute_geometry #define xfs_btree_del_cursor libxfs_btree_del_cursor #define xfs_btree_init_block libxfs_btree_init_block +#define xfs_btree_rec_addr libxfs_btree_rec_addr #define xfs_buf_delwri_submit libxfs_buf_delwri_submit #define xfs_buf_get libxfs_buf_get #define xfs_buf_get_uncached libxfs_buf_get_uncached diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index be0b43e45..a6f0d7d3b 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -440,22 +440,19 @@ STATIC int xfs_btree_bload_leaf( struct xfs_btree_cur *cur, unsigned int recs_this_block, - xfs_btree_bload_get_record_fn get_record, + xfs_btree_bload_get_records_fn get_records, struct xfs_btree_block *block, void *priv) { - unsigned int j; + unsigned int j = 1; int ret; /* Fill the leaf block with records. */ - for (j = 1; j <= recs_this_block; j++) { - union xfs_btree_rec *block_rec; - - ret = get_record(cur, priv); - if (ret) + while (j <= recs_this_block) { + ret = get_records(cur, j, block, recs_this_block - j + 1, priv); + if (ret < 0) return ret; - block_rec = xfs_btree_rec_addr(cur, j, block); - cur->bc_ops->init_rec_from_cur(cur, block_rec); + j += ret; } return 0; @@ -798,7 +795,7 @@ xfs_btree_bload( trace_xfs_btree_bload_block(cur, level, i, blocks, &ptr, nr_this_block); - ret = xfs_btree_bload_leaf(cur, nr_this_block, bbl->get_record, + ret = xfs_btree_bload_leaf(cur, nr_this_block, bbl->get_records, block, priv); if (ret) goto out; diff --git a/libxfs/xfs_btree_staging.h b/libxfs/xfs_btree_staging.h index 5f638f711..bd5b3f004 100644 --- a/libxfs/xfs_btree_staging.h +++ b/libxfs/xfs_btree_staging.h @@ -47,7 +47,9 @@ void xfs_btree_commit_ifakeroot(struct xfs_btree_cur *cur, struct xfs_trans *tp, int whichfork, const struct xfs_btree_ops *ops); /* Bulk loading of staged btrees. */ -typedef int (*xfs_btree_bload_get_record_fn)(struct xfs_btree_cur *cur, void *priv); +typedef int (*xfs_btree_bload_get_records_fn)(struct xfs_btree_cur *cur, + unsigned int idx, struct xfs_btree_block *block, + unsigned int nr_wanted, void *priv); typedef int (*xfs_btree_bload_claim_block_fn)(struct xfs_btree_cur *cur, union xfs_btree_ptr *ptr, void *priv); typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur, @@ -55,11 +57,14 @@ typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur, struct xfs_btree_bload { /* - * This function will be called nr_records times to load records into - * the btree. The function does this by setting the cursor's bc_rec - * field in in-core format. Records must be returned in sort order. + * This function will be called to load @nr_wanted records into the + * btree. The implementation does this by setting the cursor's bc_rec + * field in in-core format and using init_rec_from_cur to set the + * records in the btree block. Records must be returned in sort order. + * The function must return the number of records loaded or the usual + * negative errno. */ - xfs_btree_bload_get_record_fn get_record; + xfs_btree_bload_get_records_fn get_records; /* * This function will be called nr_blocks times to obtain a pointer diff --git a/repair/agbtree.c b/repair/agbtree.c index 7211765d3..10a0c7e48 100644 --- a/repair/agbtree.c +++ b/repair/agbtree.c @@ -209,18 +209,25 @@ get_bno_rec( /* Grab one bnobt record and put it in the btree cursor. */ static int -get_bnobt_record( +get_bnobt_records( struct xfs_btree_cur *cur, + unsigned int idx, + struct xfs_btree_block *block, + unsigned int nr_wanted, void *priv) { struct bt_rebuild *btr = priv; struct xfs_alloc_rec_incore *arec = &cur->bc_rec.a; + union xfs_btree_rec *block_rec; btr->bno_rec = get_bno_rec(cur, btr->bno_rec); arec->ar_startblock = btr->bno_rec->ex_startblock; arec->ar_blockcount = btr->bno_rec->ex_blockcount; btr->freeblks += btr->bno_rec->ex_blockcount; - return 0; + + block_rec = libxfs_btree_rec_addr(cur, idx, block); + cur->bc_ops->init_rec_from_cur(cur, block_rec); + return 1; } void @@ -247,10 +254,10 @@ init_freespace_cursors( btr_cnt->cur = libxfs_allocbt_stage_cursor(sc->mp, &btr_cnt->newbt.afake, pag, XFS_BTNUM_CNT); - btr_bno->bload.get_record = get_bnobt_record; + btr_bno->bload.get_records = get_bnobt_records; btr_bno->bload.claim_block = rebuild_claim_block; - btr_cnt->bload.get_record = get_bnobt_record; + btr_cnt->bload.get_records = get_bnobt_records; btr_cnt->bload.claim_block = rebuild_claim_block; /* @@ -371,13 +378,17 @@ get_ino_rec( /* Grab one inobt record. */ static int -get_inobt_record( +get_inobt_records( struct xfs_btree_cur *cur, + unsigned int idx, + struct xfs_btree_block *block, + unsigned int nr_wanted, void *priv) { struct bt_rebuild *btr = priv; struct xfs_inobt_rec_incore *irec = &cur->bc_rec.i; struct ino_tree_node *ino_rec; + union xfs_btree_rec *block_rec; int inocnt = 0; int finocnt = 0; int k; @@ -431,7 +442,10 @@ get_inobt_record( btr->first_agino = ino_rec->ino_startnum; btr->freecount += finocnt; btr->count += inocnt; - return 0; + + block_rec = libxfs_btree_rec_addr(cur, idx, block); + cur->bc_ops->init_rec_from_cur(cur, block_rec); + return 1; } /* Initialize both inode btree cursors as needed. */ @@ -490,7 +504,7 @@ init_ino_cursors( btr_ino->cur = libxfs_inobt_stage_cursor(pag, &btr_ino->newbt.afake, XFS_BTNUM_INO); - btr_ino->bload.get_record = get_inobt_record; + btr_ino->bload.get_records = get_inobt_records; btr_ino->bload.claim_block = rebuild_claim_block; btr_ino->first_agino = NULLAGINO; @@ -510,7 +524,7 @@ _("Unable to compute inode btree geometry, error %d.\n"), error); btr_fino->cur = libxfs_inobt_stage_cursor(pag, &btr_fino->newbt.afake, XFS_BTNUM_FINO); - btr_fino->bload.get_record = get_inobt_record; + btr_fino->bload.get_records = get_inobt_records; btr_fino->bload.claim_block = rebuild_claim_block; btr_fino->first_agino = NULLAGINO; @@ -560,16 +574,23 @@ _("Error %d while creating finobt btree for AG %u.\n"), error, agno); /* Grab one rmap record. */ static int -get_rmapbt_record( +get_rmapbt_records( struct xfs_btree_cur *cur, + unsigned int idx, + struct xfs_btree_block *block, + unsigned int nr_wanted, void *priv) { struct xfs_rmap_irec *rec; struct bt_rebuild *btr = priv; + union xfs_btree_rec *block_rec; rec = pop_slab_cursor(btr->slab_cursor); memcpy(&cur->bc_rec.r, rec, sizeof(struct xfs_rmap_irec)); - return 0; + + block_rec = libxfs_btree_rec_addr(cur, idx, block); + cur->bc_ops->init_rec_from_cur(cur, block_rec); + return 1; } /* Set up the rmap rebuild parameters. */ @@ -589,7 +610,7 @@ init_rmapbt_cursor( init_rebuild(sc, &XFS_RMAP_OINFO_AG, est_agfreeblocks, btr); btr->cur = libxfs_rmapbt_stage_cursor(sc->mp, &btr->newbt.afake, pag); - btr->bload.get_record = get_rmapbt_record; + btr->bload.get_records = get_rmapbt_records; btr->bload.claim_block = rebuild_claim_block; /* Compute how many blocks we'll need. */ @@ -631,16 +652,23 @@ _("Error %d while creating rmap btree for AG %u.\n"), error, agno); /* Grab one refcount record. */ static int -get_refcountbt_record( +get_refcountbt_records( struct xfs_btree_cur *cur, + unsigned int idx, + struct xfs_btree_block *block, + unsigned int nr_wanted, void *priv) { struct xfs_refcount_irec *rec; struct bt_rebuild *btr = priv; + union xfs_btree_rec *block_rec; rec = pop_slab_cursor(btr->slab_cursor); memcpy(&cur->bc_rec.rc, rec, sizeof(struct xfs_refcount_irec)); - return 0; + + block_rec = libxfs_btree_rec_addr(cur, idx, block); + cur->bc_ops->init_rec_from_cur(cur, block_rec); + return 1; } /* Set up the refcount rebuild parameters. */ @@ -661,7 +689,7 @@ init_refc_cursor( btr->cur = libxfs_refcountbt_stage_cursor(sc->mp, &btr->newbt.afake, pag); - btr->bload.get_record = get_refcountbt_record; + btr->bload.get_records = get_refcountbt_records; btr->bload.claim_block = rebuild_claim_block; /* Compute how many blocks we'll need. */ From patchwork Mon Apr 22 16:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638713 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 BE194153BF8 for ; Mon, 22 Apr 2024 16:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803998; cv=none; b=e1ljrSARUs/NmlFHPSxZUWnKGHY16FEmXBvRIFnJnANOyqG4/MAdEYSxCYKGKqtWVb22eH0HCzA5WrzuemVPnJywDQMJ7O4A14HnSSDjB7pGpptu2oE9meIsuQVwn2o9X4ecQFoNW3Z4966QcfqLb8RT0MRcGeAtBvNh9S5mGfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713803998; c=relaxed/simple; bh=Mxuhz5gLmUJbK8WQX2dFBEdFld+GGPAt5PoWfk70KSw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JBUfkTD0dpehQtuxvPJpHiHB3DvYRNKQDTnnU9YBAbgw33oSPIT+2QLKrJOuTT0Q2zQris6Tugcbp5jFzue2tQ2nC4wlAZ4IsG9zmm1d1PHvurpETzcfH8XdC+0D6q5Z9ERD0V+3NuLvKRXcHdFXgH8GMwjNiuj3wmE4GxKlbsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gJa/yl4j; 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="gJa/yl4j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A59E3C32783; Mon, 22 Apr 2024 16:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713803998; bh=Mxuhz5gLmUJbK8WQX2dFBEdFld+GGPAt5PoWfk70KSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gJa/yl4jLuqgAMgT6t3bMz9IaEX3GPk2IHHLEPou+rlqLELDdR4knXiwFJJZLSsCe yQLEJPtND7HsD+E7Hf7DLH068frPoRDIjA6T81QgU9a0Nc7BVxdYQ5SJvKBQa5Kkbx CpaHG4ZIyveFyvIjP/Kd51ksIlC8dEzFrrdo9zxynHUAD+UCvuH22PXURibQfQHds1 7AiCh0ueTWxiTrPNIr4fIw4yRCrXpnObxD5JsIxyXFcenfO4299ClMNSYZT0tY0pr/ ny7bbYhaqw8s+w6AOHiBCUzsva2pY33GqRARRu5Lu9NOrrqweVboPF89t0penb6cEp EDhXhZ3kFs6rA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 33/67] xfs: constrain dirty buffers while formatting a staged btree Date: Mon, 22 Apr 2024 18:25:55 +0200 Message-ID: <20240422163832.858420-35-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e069d549705e49841247acf9b3176744e27d5425 Constrain the number of dirty buffers that are locked by the btree staging code at any given time by establishing a threshold at which we put them all on the delwri queue and push them to disk. This limits memory consumption while writing out new btrees. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_btree_staging.c | 50 +++++++++++++++++++++++++++++--------- libxfs/xfs_btree_staging.h | 10 ++++++++ repair/agbtree.c | 1 + 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index a6f0d7d3b..d4164e37b 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -333,24 +333,41 @@ xfs_btree_commit_ifakeroot( /* * Put a btree block that we're loading onto the ordered list and release it. * The btree blocks will be written to disk when bulk loading is finished. + * If we reach the dirty buffer threshold, flush them to disk before + * continuing. */ -static void +static int xfs_btree_bload_drop_buf( - struct list_head *buffers_list, - struct xfs_buf **bpp) + struct xfs_btree_bload *bbl, + struct list_head *buffers_list, + struct xfs_buf **bpp) { - if (*bpp == NULL) - return; + struct xfs_buf *bp = *bpp; + int error; + + if (!bp) + return 0; /* * Mark this buffer XBF_DONE (i.e. uptodate) so that a subsequent * xfs_buf_read will not pointlessly reread the contents from the disk. */ - (*bpp)->b_flags |= XBF_DONE; + bp->b_flags |= XBF_DONE; - xfs_buf_delwri_queue_here(*bpp, buffers_list); - xfs_buf_relse(*bpp); + xfs_buf_delwri_queue_here(bp, buffers_list); + xfs_buf_relse(bp); *bpp = NULL; + bbl->nr_dirty++; + + if (!bbl->max_dirty || bbl->nr_dirty < bbl->max_dirty) + return 0; + + error = xfs_buf_delwri_submit(buffers_list); + if (error) + return error; + + bbl->nr_dirty = 0; + return 0; } /* @@ -422,7 +439,10 @@ xfs_btree_bload_prep_block( */ if (*blockp) xfs_btree_set_sibling(cur, *blockp, &new_ptr, XFS_BB_RIGHTSIB); - xfs_btree_bload_drop_buf(buffers_list, bpp); + + ret = xfs_btree_bload_drop_buf(bbl, buffers_list, bpp); + if (ret) + return ret; /* Initialize the new btree block. */ xfs_btree_init_block_cur(cur, new_bp, level, nr_this_block); @@ -770,6 +790,7 @@ xfs_btree_bload( cur->bc_nlevels = bbl->btree_height; xfs_btree_set_ptr_null(cur, &child_ptr); xfs_btree_set_ptr_null(cur, &ptr); + bbl->nr_dirty = 0; xfs_btree_bload_level_geometry(cur, bbl, level, nr_this_level, &avg_per_block, &blocks, &blocks_with_extra); @@ -808,7 +829,10 @@ xfs_btree_bload( xfs_btree_copy_ptrs(cur, &child_ptr, &ptr, 1); } total_blocks += blocks; - xfs_btree_bload_drop_buf(&buffers_list, &bp); + + ret = xfs_btree_bload_drop_buf(bbl, &buffers_list, &bp); + if (ret) + goto out; /* Populate the internal btree nodes. */ for (level = 1; level < cur->bc_nlevels; level++) { @@ -850,7 +874,11 @@ xfs_btree_bload( xfs_btree_copy_ptrs(cur, &first_ptr, &ptr, 1); } total_blocks += blocks; - xfs_btree_bload_drop_buf(&buffers_list, &bp); + + ret = xfs_btree_bload_drop_buf(bbl, &buffers_list, &bp); + if (ret) + goto out; + xfs_btree_copy_ptrs(cur, &child_ptr, &first_ptr, 1); } diff --git a/libxfs/xfs_btree_staging.h b/libxfs/xfs_btree_staging.h index bd5b3f004..f0a500728 100644 --- a/libxfs/xfs_btree_staging.h +++ b/libxfs/xfs_btree_staging.h @@ -112,6 +112,16 @@ struct xfs_btree_bload { * height of the new btree. */ unsigned int btree_height; + + /* + * Flush the new btree block buffer list to disk after this many blocks + * have been formatted. Zero prohibits writing any buffers until all + * blocks have been formatted. + */ + uint16_t max_dirty; + + /* Number of dirty buffers. */ + uint16_t nr_dirty; }; int xfs_btree_bload_compute_geometry(struct xfs_btree_cur *cur, diff --git a/repair/agbtree.c b/repair/agbtree.c index 10a0c7e48..981d8e340 100644 --- a/repair/agbtree.c +++ b/repair/agbtree.c @@ -23,6 +23,7 @@ init_rebuild( memset(btr, 0, sizeof(struct bt_rebuild)); bulkload_init_ag(&btr->newbt, sc, oinfo); + btr->bload.max_dirty = XFS_B_TO_FSBT(sc->mp, 256U << 10); /* 256K */ bulkload_estimate_ag_slack(sc, &btr->bload, est_agfreeblocks); } From patchwork Mon Apr 22 16:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638714 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 42EE96A039 for ; Mon, 22 Apr 2024 16: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=1713804000; cv=none; b=QIGW3ShfWfHyIHLBeOjlISy5FVlR6o6+SLrEigrWwcQrMq/WdPM0pEsIttnvhh9qUKdarPn0jEI+XpfQ9WaFTxfh67F4iNUEEoFC4xGbFTgsSovJN94wfa7nVUSe/4qXfrROam/EWPHfDgDiV5c83XHdReWW+rA7um4bmtiLsq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804000; c=relaxed/simple; bh=GQjrV1YIt6nsqALvikL/YeliW4jr3cFkets2jHSHHNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=drkGYkxjmeLVP0qpJxeMuQCQOTlz7bgEHsWGFWWM7JlG0I/7s01vJb9l1qEuv9/BRa9qJ2XzKzmIBEQWzrcJysD8mTwmMQz+ChbSa+7ygKf/kKtpn5Yb5Qi5a2iT2017527H2H4IaPl7ZJSYfxUwn3aarIO/EqtIhaDIj57TwJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nyQhufKs; 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="nyQhufKs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33951C116B1; Mon, 22 Apr 2024 16:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804000; bh=GQjrV1YIt6nsqALvikL/YeliW4jr3cFkets2jHSHHNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nyQhufKs3IxzUCeYqnfoui1vKEngVfncpyAZl8FLtE03hds8KDvfedMFMK406kaVc CuvXnRzdruKJceY8DxlLBMXEslKQA4+X49dlekYdfaoPPL52R0nmXEIXbNlRDbG97I 6EL8tpmQo9jQMTkL4GNxBCISHId9cuTOLZQ6gm2/R1NDUCS3V1rNdevDTgdM9Q7C3i m2oLqMS/CQiuUWWO6MW7j81eZkUPOwBN2OCZySvdckuZlq/88b5+saevpflipEuWQl gJmuF7GYM9cQc8QCAl78nyU7FtLnHaIqhIQ7z62ktLr7X0R56kLChDEkasjjxTPOFe eHcTBwtFHzcsg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 34/67] xfs: repair free space btrees Date: Mon, 22 Apr 2024 18:25:56 +0200 Message-ID: <20240422163832.858420-36-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 4bdfd7d15747b170ce93a06fafccaf20544b6684 Rebuild the free space btrees from the gaps in the rmap btree. Refer to the case study in Documentation/filesystems/xfs-online-fsck-design.rst for more details. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.h | 9 +++++++++ libxfs/xfs_ag_resv.c | 2 ++ libxfs/xfs_alloc.c | 10 ++++------ libxfs/xfs_alloc.h | 2 +- libxfs/xfs_alloc_btree.c | 13 ++++++++++++- libxfs/xfs_types.h | 7 +++++++ 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 2e0aef87d..f16cb7a17 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -80,6 +80,15 @@ struct xfs_perag { */ 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 + * verifiers while rebuilding the AG btrees. + */ + uint8_t pagf_repair_levels[XFS_BTNUM_AGF]; +#endif + spinlock_t pag_state_lock; spinlock_t pagb_lock; /* lock for pagb_tree */ diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index 29bbcb55d..3a80b1613 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -410,6 +410,8 @@ xfs_ag_resv_free_extent( fallthrough; case XFS_AG_RESV_NONE: xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, (int64_t)len); + fallthrough; + case XFS_AG_RESV_IGNORE: return; } diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index aaa159615..352efbeca 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -242,11 +242,9 @@ xfs_alloc_btrec_to_irec( /* Simple checks for free space records. */ xfs_failaddr_t xfs_alloc_check_irec( - struct xfs_btree_cur *cur, - const struct xfs_alloc_rec_incore *irec) + struct xfs_perag *pag, + const struct xfs_alloc_rec_incore *irec) { - struct xfs_perag *pag = cur->bc_ag.pag; - if (irec->ar_blockcount == 0) return __this_address; @@ -295,7 +293,7 @@ xfs_alloc_get_rec( return error; xfs_alloc_btrec_to_irec(rec, &irec); - fa = xfs_alloc_check_irec(cur, &irec); + fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec); if (fa) return xfs_alloc_complain_bad_rec(cur, fa, &irec); @@ -3940,7 +3938,7 @@ xfs_alloc_query_range_helper( xfs_failaddr_t fa; xfs_alloc_btrec_to_irec(rec, &irec); - fa = xfs_alloc_check_irec(cur, &irec); + fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec); if (fa) return xfs_alloc_complain_bad_rec(cur, fa, &irec); diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 851cafbd6..0b956f8b9 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -185,7 +185,7 @@ xfs_alloc_get_rec( union xfs_btree_rec; void xfs_alloc_btrec_to_irec(const union xfs_btree_rec *rec, struct xfs_alloc_rec_incore *irec); -xfs_failaddr_t xfs_alloc_check_irec(struct xfs_btree_cur *cur, +xfs_failaddr_t xfs_alloc_check_irec(struct xfs_perag *pag, const struct xfs_alloc_rec_incore *irec); int xfs_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags, diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 5ec14288d..a472ec6d2 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -321,7 +321,18 @@ xfs_allocbt_verify( if (bp->b_ops->magic[0] == cpu_to_be32(XFS_ABTC_MAGIC)) btnum = XFS_BTNUM_CNTi; if (pag && xfs_perag_initialised_agf(pag)) { - if (level >= pag->pagf_levels[btnum]) + unsigned int maxlevel = pag->pagf_levels[btnum]; + +#ifdef CONFIG_XFS_ONLINE_REPAIR + /* + * Online repair could be rewriting the free space btrees, so + * we'll validate against the larger of either tree while this + * is going on. + */ + maxlevel = max_t(unsigned int, maxlevel, + pag->pagf_repair_levels[btnum]); +#endif + if (level >= maxlevel) return __this_address; } else if (level >= mp->m_alloc_maxlevels) return __this_address; diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index 533200c4c..035bf703d 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -208,6 +208,13 @@ enum xfs_ag_resv_type { XFS_AG_RESV_AGFL, XFS_AG_RESV_METADATA, XFS_AG_RESV_RMAPBT, + + /* + * Don't increase fdblocks when freeing extent. This is a pony for + * the bnobt repair functions to re-free the free space without + * altering fdblocks. If you think you need this you're wrong. + */ + XFS_AG_RESV_IGNORE, }; /* Results of scanning a btree keyspace to check occupancy. */ From patchwork Mon Apr 22 16:25:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638715 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 07C4515530C for ; Mon, 22 Apr 2024 16:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804002; cv=none; b=EhzmOjtz5GgZpIs24SCLynYg418yZxMoNnolrxkpglpBX5yY6gkkRTW+eatG29i1X3fvyF7irZhNRHbdpL5Bwl3WoiMF/+MMlkQBPHJjQFYvVoW3R5LylkdUzSyLra1vka4qpnNVmavPeAfyu+RVF6BJSYjxO56DR7sn1DudQf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804002; c=relaxed/simple; bh=gm6AxcRc8hnyA/NI+z6ayH9dKLueLSB1MyhG12tWfFg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E3jHv4D6XvOJm3P9vsGW6HVcinmWs8YxuCI2O/kvjNq51v+n1yRBHCNSidjz8Pm6f0Z47Czg7kZMyazyk+u8yCC7C6jfMST0wRyg9SxepnJPgesmGG25yMQZb82cHBsR6CcwYV86jP3uE/nTU45CvFurTYe0l7bJSXKYMGPxh40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=roPZlkw/; 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="roPZlkw/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E349C116B1; Mon, 22 Apr 2024 16:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804001; bh=gm6AxcRc8hnyA/NI+z6ayH9dKLueLSB1MyhG12tWfFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roPZlkw//nTb7FF568Cz2WsrRmcy6QBg8CKnj5HkG6MT1u4lbnvyFFrui41TLbHjO W2rPkMLZH1kSfOskNkDg0GyXAa5V7Ue+pQA17WvO91SJ/LhJGGgR25ddxgZVuh5NNr 94xKUkMHV/qDdV7ia8FF/i9t9O7e0lgiJ7JPi7Yv1D3rCPo18BfLL2j6mZW5JvMwMW 3J3qCvBQ9SFQHLdO57TvSbwwK1vu9H3WHFWcMNla5cQOmTVgGiTnwyUuHmNdUPjBEp 0jW4fpyattujuTgIj5uIGRrODzH0AB7XdX//K7XxWtktNhQWPN8QHO8XbPKHwxrHM5 3auPYkniwt1LQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 35/67] xfs: repair inode btrees Date: Mon, 22 Apr 2024 18:25:57 +0200 Message-ID: <20240422163832.858420-37-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: dbfbf3bdf639a20da7d5fb390cd2e197d25aa418 Use the rmapbt to find inode chunks, query the chunks to compute hole and free masks, and with that information rebuild the inobt and finobt. Refer to the case study in Documentation/filesystems/xfs-online-fsck-design.rst for more details. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_ialloc.c | 31 ++++++++++++++++++------------- libxfs/xfs_ialloc.h | 3 ++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 14826280d..5ff09c8c9 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -90,18 +90,28 @@ xfs_inobt_btrec_to_irec( irec->ir_free = be64_to_cpu(rec->inobt.ir_free); } +/* Compute the freecount of an incore inode record. */ +uint8_t +xfs_inobt_rec_freecount( + const struct xfs_inobt_rec_incore *irec) +{ + uint64_t realfree = irec->ir_free; + + if (xfs_inobt_issparse(irec->ir_holemask)) + realfree &= xfs_inobt_irec_to_allocmask(irec); + return hweight64(realfree); +} + /* Simple checks for inode records. */ xfs_failaddr_t xfs_inobt_check_irec( - struct xfs_btree_cur *cur, + struct xfs_perag *pag, const struct xfs_inobt_rec_incore *irec) { - uint64_t realfree; - /* Record has to be properly aligned within the AG. */ - if (!xfs_verify_agino(cur->bc_ag.pag, irec->ir_startino)) + if (!xfs_verify_agino(pag, irec->ir_startino)) return __this_address; - if (!xfs_verify_agino(cur->bc_ag.pag, + if (!xfs_verify_agino(pag, irec->ir_startino + XFS_INODES_PER_CHUNK - 1)) return __this_address; if (irec->ir_count < XFS_INODES_PER_HOLEMASK_BIT || @@ -110,12 +120,7 @@ xfs_inobt_check_irec( if (irec->ir_freecount > XFS_INODES_PER_CHUNK) return __this_address; - /* if there are no holes, return the first available offset */ - if (!xfs_inobt_issparse(irec->ir_holemask)) - realfree = irec->ir_free; - else - realfree = irec->ir_free & xfs_inobt_irec_to_allocmask(irec); - if (hweight64(realfree) != irec->ir_freecount) + if (xfs_inobt_rec_freecount(irec) != irec->ir_freecount) return __this_address; return NULL; @@ -159,7 +164,7 @@ xfs_inobt_get_rec( return error; xfs_inobt_btrec_to_irec(mp, rec, irec); - fa = xfs_inobt_check_irec(cur, irec); + fa = xfs_inobt_check_irec(cur->bc_ag.pag, irec); if (fa) return xfs_inobt_complain_bad_rec(cur, fa, irec); @@ -2735,7 +2740,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, &irec); + fa = xfs_inobt_check_irec(cur->bc_ag.pag, &irec); if (fa) return xfs_inobt_complain_bad_rec(cur, fa, &irec); diff --git a/libxfs/xfs_ialloc.h b/libxfs/xfs_ialloc.h index fe824bb04..f1412183b 100644 --- a/libxfs/xfs_ialloc.h +++ b/libxfs/xfs_ialloc.h @@ -79,6 +79,7 @@ int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino, */ int xfs_inobt_get_rec(struct xfs_btree_cur *cur, xfs_inobt_rec_incore_t *rec, int *stat); +uint8_t xfs_inobt_rec_freecount(const struct xfs_inobt_rec_incore *irec); /* * Inode chunk initialisation routine @@ -93,7 +94,7 @@ union xfs_btree_rec; void xfs_inobt_btrec_to_irec(struct xfs_mount *mp, const union xfs_btree_rec *rec, struct xfs_inobt_rec_incore *irec); -xfs_failaddr_t xfs_inobt_check_irec(struct xfs_btree_cur *cur, +xfs_failaddr_t xfs_inobt_check_irec(struct xfs_perag *pag, const struct xfs_inobt_rec_incore *irec); int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur, xfs_agblock_t bno, xfs_extlen_t len, From patchwork Mon Apr 22 16:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638716 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 2CDA51552EC for ; Mon, 22 Apr 2024 16:40:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804003; cv=none; b=uz9tEaC1vp3VTX7NT/lIN7NutwNpnBGe8ySFGHY7dahIgtMWL/sW/XzHjK2ZCZJ9GzhciMDlpGCQ/v3w20W2lTjEg7XYjTK/vQC1lUtNz0sJNz4Gh/8JS4+LJjT+z//5HZvYz3xsdHlDMl1hkEOd5G4I6AYdPF+CuoeIL+/RyQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804003; c=relaxed/simple; bh=XyDwrcC6BZKxUTZfvAdffjZfkko9ihoxhDswC2KC04s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ons8gMeL0qzU9J/y0weIZ3kYay0K1CAgif+yDkqWbs9EMNgN1pBjf1rwQOxU1GP1inJILLFe7lwqjfM7nfcRo15sNU5/4nPduqrRQ+LVIw++nVNKJjH2xPYaa2ufaCS6xvGGrrKRBBhSyJdXNztiKuFIZWmnrITn1N86exTOi5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tJJxiGud; 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="tJJxiGud" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14E88C113CC; Mon, 22 Apr 2024 16:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804003; bh=XyDwrcC6BZKxUTZfvAdffjZfkko9ihoxhDswC2KC04s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJJxiGudoGtirUIDnkss/UTlhZAcMkhZYEhqgjZ/jTger+WRW8ZZR7imBsrT4sut8 1stx22d/P+0YayubamUOzfJxNhRI/pyvBOIzJ08mr2KNAXtIMSFn4+AxfBabdNPo/D XBANuZ9kWcTk9fd24CVmyWMVRvIs/m4FaDmuBy49p881p2UbhuHOMjHyxLPuZjVzDr jEBM2I+apoxkOttq6eBoHLc3AIlKYeAVTwQJumsosP9L4A5WqrGKPtUaHZyhTRpqfA YirQGKSkNxUuz5BrdRZJL3tgKvEu2G9yH/ExmcYWqLxKMV8vSPhKZSG4sZ0Pci23t/ vKiyWAa4JutNw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 36/67] xfs: repair refcount btrees Date: Mon, 22 Apr 2024 18:25:58 +0200 Message-ID: <20240422163832.858420-38-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 9099cd38002f8029c9a1da08e6832d1cd18e8451 Reconstruct the refcount data from the rmap btree. Link: https://docs.kernel.org/filesystems/xfs-online-fsck-design.html#case-study-rebuilding-the-space-reference-counts Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.h | 1 + libxfs/xfs_btree.c | 26 ++++++++++++++++++++++++++ libxfs/xfs_btree.h | 2 ++ libxfs/xfs_refcount.c | 8 +++----- libxfs/xfs_refcount.h | 2 +- libxfs/xfs_refcount_btree.c | 13 ++++++++++++- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index f16cb7a17..67c3260ee 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -87,6 +87,7 @@ struct xfs_perag { * verifiers while rebuilding the AG btrees. */ uint8_t pagf_repair_levels[XFS_BTNUM_AGF]; + uint8_t pagf_repair_refcount_level; #endif spinlock_t pag_state_lock; diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 97962fc16..0022bb641 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -5209,3 +5209,29 @@ xfs_btree_destroy_cur_caches(void) xfs_rmapbt_destroy_cur_cache(); xfs_refcountbt_destroy_cur_cache(); } + +/* Move the btree cursor before the first record. */ +int +xfs_btree_goto_left_edge( + struct xfs_btree_cur *cur) +{ + int stat = 0; + int error; + + memset(&cur->bc_rec, 0, sizeof(cur->bc_rec)); + error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, &stat); + if (error) + return error; + if (!stat) + return 0; + + error = xfs_btree_decrement(cur, 0, &stat); + if (error) + return error; + if (stat != 0) { + ASSERT(0); + return -EFSCORRUPTED; + } + + return 0; +} diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index e0875cec4..d906324e2 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -738,4 +738,6 @@ xfs_btree_alloc_cursor( int __init xfs_btree_init_cur_caches(void); void xfs_btree_destroy_cur_caches(void); +int xfs_btree_goto_left_edge(struct xfs_btree_cur *cur); + #endif /* __XFS_BTREE_H__ */ diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 45f8134e4..3377fac12 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -122,11 +122,9 @@ xfs_refcount_btrec_to_irec( /* Simple checks for refcount records. */ xfs_failaddr_t xfs_refcount_check_irec( - struct xfs_btree_cur *cur, + struct xfs_perag *pag, const struct xfs_refcount_irec *irec) { - struct xfs_perag *pag = cur->bc_ag.pag; - if (irec->rc_blockcount == 0 || irec->rc_blockcount > MAXREFCEXTLEN) return __this_address; @@ -178,7 +176,7 @@ xfs_refcount_get_rec( return error; xfs_refcount_btrec_to_irec(rec, irec); - fa = xfs_refcount_check_irec(cur, irec); + fa = xfs_refcount_check_irec(cur->bc_ag.pag, irec); if (fa) return xfs_refcount_complain_bad_rec(cur, fa, irec); @@ -1898,7 +1896,7 @@ 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, &rr->rr_rrec) != NULL || + if (xfs_refcount_check_irec(cur->bc_ag.pag, &rr->rr_rrec) != NULL || XFS_IS_CORRUPT(cur->bc_mp, rr->rr_rrec.rc_domain != XFS_REFC_DOMAIN_COW)) { kfree(rr); diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 783cd89ca..5c207f1c6 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -117,7 +117,7 @@ extern int xfs_refcount_has_records(struct xfs_btree_cur *cur, union xfs_btree_rec; extern void xfs_refcount_btrec_to_irec(const union xfs_btree_rec *rec, struct xfs_refcount_irec *irec); -xfs_failaddr_t xfs_refcount_check_irec(struct xfs_btree_cur *cur, +xfs_failaddr_t xfs_refcount_check_irec(struct xfs_perag *pag, const struct xfs_refcount_irec *irec); extern int xfs_refcount_insert(struct xfs_btree_cur *cur, struct xfs_refcount_irec *irec, int *stat); diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index bc8bd867e..ac1c3ab86 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -225,7 +225,18 @@ xfs_refcountbt_verify( level = be16_to_cpu(block->bb_level); if (pag && xfs_perag_initialised_agf(pag)) { - if (level >= pag->pagf_refcount_level) + unsigned int maxlevel = pag->pagf_refcount_level; + +#ifdef CONFIG_XFS_ONLINE_REPAIR + /* + * Online repair could be rewriting the refcount btree, so + * we'll validate against the larger of either tree while this + * is going on. + */ + maxlevel = max_t(unsigned int, maxlevel, + pag->pagf_repair_refcount_level); +#endif + if (level >= maxlevel) return __this_address; } else if (level >= mp->m_refc_maxlevels) return __this_address; From patchwork Mon Apr 22 16:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638717 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 8E859155313 for ; Mon, 22 Apr 2024 16:40:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804004; cv=none; b=qZETLY9sgskxlFZ+oilio5PynE3vZqkBMJ4BtMFx0j0snitOosPQODgUvkMZlujNT2RQz4SuwgJxSg+0QutckKpaQoON4RL/zRJKkrPyS7KqJ5QwHJvOWTj4t6Htc7i8KT6Ic3HRooIjysGRmKhoWiW7sXiZ8alAs8FrKVbd13Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804004; c=relaxed/simple; bh=651JdkIKH8HUqx0716uQJmNAkp2CMsm27IT2q/6R37U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=inAYIgmyqGcUCQOUVmy81YwN3rrPKmzCMWo4Is8Noh2OC2yBMgLUvRj3CmjQPilEmMUG2iUhnXno59uk6+GYgZ1xD1G9rWyBkBzxWfDAmFRYNbZYWujF9fcoY0vGv+NaBLI6rdSQfwXnv0wj66XscheHSZMfqZCmCshamHNkJsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J125P3iR; 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="J125P3iR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7ED6BC32781; Mon, 22 Apr 2024 16:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804004; bh=651JdkIKH8HUqx0716uQJmNAkp2CMsm27IT2q/6R37U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J125P3iR3ARQvZrMpbh6h6TrTp/tZDZN9KON9C7lUFz4Sd+5ZBA/RJ8+/QUAcYkgF y+MYMIPv365UXFnHC4ZohQxVFOFbK5hyT0rbwwFsjPpTjP6SiZ2LE8XVto0f4hpyQT maB2OM42gp51Daq2kj/8la8h5SyNEmUe8oKe9b9NczEqY8evysIP6t87PTjDYL4mFB vWPosePUqss7pFpWPqHfnz7Mt9YZRYVdfRARW5PzMgMFDx47vTuXZmBpPWDRnVASTD vetxPIUxMHqX0iXxUWLkQuxDbtsu13EXpHhUpdfl5/q7BNZporXsSZlYwoamP1MyGR 3t86T8Uf9TYhw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 37/67] xfs: dont cast to char * for XFS_DFORK_*PTR macros Date: Mon, 22 Apr 2024 18:25:59 +0200 Message-ID: <20240422163832.858420-39-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 6b5d917780219d0d8f8e2cefefcb6f50987d0fa3 Code in the next patch will assign the return value of XFS_DFORK_*PTR macros to a struct pointer. gcc complains about casting char* strings to struct pointers, so let's fix the macro's cast to void* to shut up the warnings. While we're at it, fix one of the scrub tests that uses PTR to use BOFF instead for a simpler integer comparison, since other linters whine about char* and void* comparisons. Can't satisfy all these dman bots. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 9a88aba15..f16974126 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1008,7 +1008,7 @@ enum xfs_dinode_fmt { * Return pointers to the data or attribute forks. */ #define XFS_DFORK_DPTR(dip) \ - ((char *)dip + xfs_dinode_size(dip->di_version)) + ((void *)dip + xfs_dinode_size(dip->di_version)) #define XFS_DFORK_APTR(dip) \ (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip)) #define XFS_DFORK_PTR(dip,w) \ From patchwork Mon Apr 22 16:26:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638718 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 EA3141552EC for ; Mon, 22 Apr 2024 16:40: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=1713804006; cv=none; b=i3o+/PBbHjR6zXTnp8xT8pdsHfnTnlG86cpzEqdfDLfOXZ9abfsuIGgEjoXlUd0PMvqWfUHZjDepOLBP7kjdxsoCIBne8D4eYEcHGAGKoalE5KHaUHW0kT/bxPe2vV3sG9t4wvPgXzL3EGS77WyF2jKF/f24VNvyqXN868Y9KXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804006; c=relaxed/simple; bh=I8epqSaStVeOoiCRWesthf3j4xojYvRvgKU59y/h+M4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UuCfOwzY3lWZKV39pCshrM75XzbnqTq13ZGGWdfb0UR2sQ0hPXjF+obtiJ8ZQgZHm+ZU2MyQ8cH6oFCgN6y1Di/wpVr8BDlKfDRxDi1D0p7dvq1J7ZLoRZ4DFE4rXJ8X38nUjcDOhAq9o9Qm2NMhJTCNo6Lm1zqEr/obN4xf9fM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YreS4++v; 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="YreS4++v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6F07C113CC; Mon, 22 Apr 2024 16:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804005; bh=I8epqSaStVeOoiCRWesthf3j4xojYvRvgKU59y/h+M4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YreS4++vxYA6nifIJR1vobIdlggDzq42GxBOomKAsBdMItQOthGx7QsB/UaT89To8 o+bIQYSunOgP6Hi+JUo9wH7GQYLA1YGH/nTdkQmhpe1VaXJd0ZLviO65Pr/PbR8RTm LEUwgx2wGoxqWdbL/ZEHXf80zQxSobshgDmEckqVyAk535//tTeCAcEBbPjq+ztA2N rvE/f8KARTIE4MZme09t3hlOwkZn5WqF7AYLvNGL6/C5eh8VTAI2F2sKYVu4UUjUjU W44fenfVDwlj1djZP6VQn8AXokzj++BJoeM2m4vt4RA4SpuYkpDXU4yNGYu6A35IT5 P3LKSxcDW5CJg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 38/67] xfs: set inode sick state flags when we zap either ondisk fork Date: Mon, 22 Apr 2024 18:26:00 +0200 Message-ID: <20240422163832.858420-40-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: d9041681dd2f5334529a68868c9266631c384de4 In a few patches, we'll add some online repair code that tries to massage the ondisk inode record just enough to get it to pass the inode verifiers so that we can continue with more file repairs. Part of that massaging can include zapping the ondisk forks to clear errors. After that point, the bmap fork repair functions will rebuild the zapped forks. Christoph asked for stronger protections against online repair zapping a fork to get the inode to load vs. other threads trying to access the partially repaired file. Do this by adding a special "[DA]FORK_ZAPPED" inode health flag whenever repair zaps a fork, and sprinkling checks for that flag into the various file operations for things that don't like handling an unexpected zero-extents fork. In practice xfs_scrub will scrub and fix the forks almost immediately after zapping them, so the window is very small. However, if a crash or unmount should occur, we can still detect these zapped inode forks by looking for a zero-extents fork when data was expected. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_health.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index 99e796256..6296993ff 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -68,6 +68,11 @@ struct xfs_fsop_geom; #define XFS_SICK_INO_SYMLINK (1 << 6) /* symbolic link remote target */ #define XFS_SICK_INO_PARENT (1 << 7) /* parent pointers */ +#define XFS_SICK_INO_BMBTD_ZAPPED (1 << 8) /* data fork erased */ +#define XFS_SICK_INO_BMBTA_ZAPPED (1 << 9) /* attr fork erased */ +#define XFS_SICK_INO_DIR_ZAPPED (1 << 10) /* directory erased */ +#define XFS_SICK_INO_SYMLINK_ZAPPED (1 << 11) /* symlink erased */ + /* Primary evidence of health problems in a given group. */ #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \ XFS_SICK_FS_UQUOTA | \ @@ -97,6 +102,11 @@ struct xfs_fsop_geom; XFS_SICK_INO_SYMLINK | \ XFS_SICK_INO_PARENT) +#define XFS_SICK_INO_ZAPPED (XFS_SICK_INO_BMBTD_ZAPPED | \ + XFS_SICK_INO_BMBTA_ZAPPED | \ + XFS_SICK_INO_DIR_ZAPPED | \ + XFS_SICK_INO_SYMLINK_ZAPPED) + /* These functions must be provided by the xfs implementation. */ void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask); From patchwork Mon Apr 22 16:26:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638719 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 5C30C1552EC for ; Mon, 22 Apr 2024 16:40: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=1713804007; cv=none; b=tvtSNguN8udcCU3LQD1olgEtgX1prSKnaS2sZW3Yddb6DkNfl0/LrB9yF8M+sMhQVsTxFKSa5Xg33Y+EctvTiZTKUxgbEBcfOj0CqEXZEhDZsStayLgEI39C0k7j+iUrRBlfBl6+ByT5/Upqt8mxlxV12vhWNhHrzVwU+SGVzOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804007; c=relaxed/simple; bh=qR3q8T0eEN5MVdCCIMTCiW/rk0cjZDOL/44wTEwWPVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RZGgkqX6uh62UI2RytexDj+ysYMON/pLEgQbzaQ07UHD5X+EDwZLaOaOlXKgq+Mgi3fMdSg9vP6jGeee1+WHAr4hAfaln8eI0bpTTyLsvsRrYL470qNXcT+3IcJ41zFPaznTm+JjgoL+77UEPo2wWnyfHI7vz/0HuQsNRlRHWfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JedKcz25; 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="JedKcz25" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46D23C116B1; Mon, 22 Apr 2024 16:40:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804007; bh=qR3q8T0eEN5MVdCCIMTCiW/rk0cjZDOL/44wTEwWPVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JedKcz2567VG5FQlZ6y2ZyVDLNMiKUOWdVjoZVMHo6Zf3mVoqyUyQpScv0EsV9Wzu KVygEm4rRt0uJnHUgpSftxw4tq7Z8KYQ4BmEq5/VOPnzOqe3CDY2KC6lTOmf2++Tzv jUeaawtD5bmyw7jyd7YMVSM0RLeKn7rUeQEajNA7qmOG47EjfpLFkjs+kBVykwaX3q 1D+YfPRuQFJPHs3HleWnnMHosdZekEy12Kp6FSH/1WVGJeJHWgQvL3hAa+G2/TQwAT wGIfwHstae+1o9Hx+/3oeZxlbY/ppXcZRaxNKjG0DfyAsAcMkPemfZH7zr7vpi/iR3 L8IymrhaDhcHQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 39/67] xfs: zap broken inode forks Date: Mon, 22 Apr 2024 18:26:01 +0200 Message-ID: <20240422163832.858420-41-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: e744cef206055954517648070d2b3aaa3d2515ba Determine if inode fork damage is responsible for the inode being unable to pass the ifork verifiers in xfs_iget and zap the fork contents if this is true. Once this is done the fork will be empty but we'll be able to construct an in-core inode, and a subsequent call to the inode fork repair ioctl will search the rmapbt to rebuild the records that were in the fork. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr_leaf.c | 13 +++---------- libxfs/xfs_attr_leaf.h | 3 ++- libxfs/xfs_bmap.c | 22 ++++++++++++++++------ libxfs/xfs_bmap.h | 2 ++ libxfs/xfs_dir2_priv.h | 3 ++- libxfs/xfs_dir2_sf.c | 13 +++---------- libxfs/xfs_inode_fork.c | 33 ++++++++++++++++++++++++++------- libxfs/xfs_shared.h | 2 +- libxfs/xfs_symlink_remote.c | 8 ++------ 9 files changed, 57 insertions(+), 42 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index baa168318..8329348eb 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -1037,23 +1037,16 @@ xfs_attr_shortform_allfit( return xfs_attr_shortform_bytesfit(dp, bytes); } -/* Verify the consistency of an inline attribute fork. */ +/* Verify the consistency of a raw inline attribute fork. */ xfs_failaddr_t xfs_attr_shortform_verify( - struct xfs_inode *ip) + struct xfs_attr_shortform *sfp, + size_t size) { - struct xfs_attr_shortform *sfp; struct xfs_attr_sf_entry *sfep; struct xfs_attr_sf_entry *next_sfep; char *endp; - struct xfs_ifork *ifp; int i; - int64_t size; - - ASSERT(ip->i_af.if_format == XFS_DINODE_FMT_LOCAL); - ifp = xfs_ifork_ptr(ip, XFS_ATTR_FORK); - sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; - size = ifp->if_bytes; /* * Give up if the attribute is way too short. diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h index 368f4d9fa..ce6743463 100644 --- a/libxfs/xfs_attr_leaf.h +++ b/libxfs/xfs_attr_leaf.h @@ -56,7 +56,8 @@ int xfs_attr_sf_findname(struct xfs_da_args *args, unsigned int *basep); int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp); int xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes); -xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip); +xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp, + size_t size); void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp); /* diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 6d23c5e3e..534a516b5 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -6162,19 +6162,18 @@ xfs_bmap_finish_one( return error; } -/* Check that an inode's extent does not have invalid flags or bad ranges. */ +/* Check that an extent does not have invalid flags or bad ranges. */ xfs_failaddr_t -xfs_bmap_validate_extent( - struct xfs_inode *ip, +xfs_bmap_validate_extent_raw( + struct xfs_mount *mp, + bool rtfile, int whichfork, struct xfs_bmbt_irec *irec) { - struct xfs_mount *mp = ip->i_mount; - if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount)) return __this_address; - if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) { + if (rtfile && whichfork == XFS_DATA_FORK) { if (!xfs_verify_rtbext(mp, irec->br_startblock, irec->br_blockcount)) return __this_address; @@ -6204,3 +6203,14 @@ xfs_bmap_intent_destroy_cache(void) kmem_cache_destroy(xfs_bmap_intent_cache); xfs_bmap_intent_cache = NULL; } + +/* Check that an inode's extent does not have invalid flags or bad ranges. */ +xfs_failaddr_t +xfs_bmap_validate_extent( + struct xfs_inode *ip, + int whichfork, + struct xfs_bmbt_irec *irec) +{ + return xfs_bmap_validate_extent_raw(ip->i_mount, + XFS_IS_REALTIME_INODE(ip), whichfork, irec); +} diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index e33470e39..8518324db 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -263,6 +263,8 @@ static inline uint32_t xfs_bmap_fork_to_state(int whichfork) } } +xfs_failaddr_t xfs_bmap_validate_extent_raw(struct xfs_mount *mp, bool rtfile, + int whichfork, struct xfs_bmbt_irec *irec); xfs_failaddr_t xfs_bmap_validate_extent(struct xfs_inode *ip, int whichfork, struct xfs_bmbt_irec *irec); int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork, diff --git a/libxfs/xfs_dir2_priv.h b/libxfs/xfs_dir2_priv.h index 7404a9ff1..1db2e60ba 100644 --- a/libxfs/xfs_dir2_priv.h +++ b/libxfs/xfs_dir2_priv.h @@ -175,7 +175,8 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino); extern int xfs_dir2_sf_lookup(struct xfs_da_args *args); extern int xfs_dir2_sf_removename(struct xfs_da_args *args); extern int xfs_dir2_sf_replace(struct xfs_da_args *args); -extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip); +xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_mount *mp, + struct xfs_dir2_sf_hdr *sfp, int64_t size); int xfs_dir2_sf_entsize(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, int len); void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c index 08b36c95c..260eccacf 100644 --- a/libxfs/xfs_dir2_sf.c +++ b/libxfs/xfs_dir2_sf.c @@ -707,11 +707,10 @@ xfs_dir2_sf_check( /* Verify the consistency of an inline directory. */ xfs_failaddr_t xfs_dir2_sf_verify( - struct xfs_inode *ip) + struct xfs_mount *mp, + struct xfs_dir2_sf_hdr *sfp, + int64_t size) { - struct xfs_mount *mp = ip->i_mount; - struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); - struct xfs_dir2_sf_hdr *sfp; struct xfs_dir2_sf_entry *sfep; struct xfs_dir2_sf_entry *next_sfep; char *endp; @@ -719,15 +718,9 @@ xfs_dir2_sf_verify( int i; int i8count; int offset; - int64_t size; int error; uint8_t filetype; - ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - - sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; - size = ifp->if_bytes; - /* * Give up if the directory is way too short. */ diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 5cc056ff7..3e2d7882a 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -700,12 +700,22 @@ xfs_ifork_verify_local_data( xfs_failaddr_t fa = NULL; switch (VFS_I(ip)->i_mode & S_IFMT) { - case S_IFDIR: - fa = xfs_dir2_sf_verify(ip); + case S_IFDIR: { + struct xfs_mount *mp = ip->i_mount; + struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); + struct xfs_dir2_sf_hdr *sfp; + + sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; + fa = xfs_dir2_sf_verify(mp, sfp, ifp->if_bytes); break; - case S_IFLNK: - fa = xfs_symlink_shortform_verify(ip); + } + case S_IFLNK: { + struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); + + fa = xfs_symlink_shortform_verify(ifp->if_u1.if_data, + ifp->if_bytes); break; + } default: break; } @@ -727,11 +737,20 @@ xfs_ifork_verify_local_attr( struct xfs_ifork *ifp = &ip->i_af; xfs_failaddr_t fa; - if (!xfs_inode_has_attr_fork(ip)) + if (!xfs_inode_has_attr_fork(ip)) { fa = __this_address; - else - fa = xfs_attr_shortform_verify(ip); + } else { + struct xfs_attr_shortform *sfp; + struct xfs_ifork *ifp; + int64_t size; + ASSERT(ip->i_af.if_format == XFS_DINODE_FMT_LOCAL); + ifp = xfs_ifork_ptr(ip, XFS_ATTR_FORK); + sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; + size = ifp->if_bytes; + + fa = xfs_attr_shortform_verify(sfp, size); + } if (fa) { xfs_inode_verifier_error(ip, -EFSCORRUPTED, "attr fork", ifp->if_u1.if_data, ifp->if_bytes, fa); diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index c4381388c..4220d3584 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -139,7 +139,7 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, uint32_t size, struct xfs_buf *bp); void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, struct xfs_ifork *ifp); -xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip); +xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); /* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry { diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index 29c9f1cc1..cf894b527 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -199,15 +199,11 @@ xfs_symlink_local_to_remote( */ xfs_failaddr_t xfs_symlink_shortform_verify( - struct xfs_inode *ip) + void *sfp, + int64_t size) { - struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); - char *sfp = (char *)ifp->if_u1.if_data; - int size = ifp->if_bytes; char *endp = sfp + size; - ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - /* * Zero length symlinks should never occur in memory as they are * never allowed to exist on disk. From patchwork Mon Apr 22 16:26:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638720 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 2E88D1552EC for ; Mon, 22 Apr 2024 16:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804009; cv=none; b=N7rxK8OERqg+lQNGhkTwzbLAUogpFSjm+R11MyTinlPBaSXKRLGB8A8f/KCzb1OrM2OYdRoz1tQjJNuF08WG5KKrHNIHzqZa9PxCbOU4R9dKF+paijxr1tYtKLyE2ZBsuW7GlRxHkrt77jrmcn/3JDIcUjbAL5rkxyNdT7iNM8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804009; c=relaxed/simple; bh=p0oxvx9w+zQMwnyXf8t61Rn0ewUU8zURfT6/h6qTjvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l3pWKiW4/RC/1YjzxkzGQrF9NF7y5LhHEMZXQ+eTtUOv1EwE5ZWgwzsz31NHtHlc0QXNh14+1iBf9fAmhod9QCB9vrw6267y5WIUBbvpCZ4MEZ+PUms/4UoW13lU7gaEVmoFWNLDY3cEcCFBTgsm44YsytVh3DW3kJuO2JDMs8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MThRqV6N; 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="MThRqV6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFA3BC32783; Mon, 22 Apr 2024 16:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804008; bh=p0oxvx9w+zQMwnyXf8t61Rn0ewUU8zURfT6/h6qTjvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MThRqV6NFm6k8qASrsna++C10jK/XL7Nghdgi/5xEtaZc4W8HullsJneQgX29l6Wk 9tNCdmLCIcljCl8q98JPGO9C5F6Ze04+ukVz2w6B5EIGVAC+9kLUrRI8KczW+xKaqc 8/rHJcUsymR06VmxE7fVFXt8VxaEmXxBSYyQHfW1s4IvNCEin8v4UiK82IqYj/Z6uc A9l8OXbbXKXI2bRa4qKCVQSUyCdvVGhZKpRbQL1fU1bWn2lMMKVVOIHzzHWhCgAlOb zXVsaqFbK6KlfwVagZ2btzgUak+bELF6AurnvUHhBld5C9u19JqBr5sk8LzXUDs3cu KoLlxdsebmFXA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 40/67] xfs: repair inode fork block mapping data structures Date: Mon, 22 Apr 2024 18:26:02 +0200 Message-ID: <20240422163832.858420-42-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 8f71bede8efd820627ac05c19eac2758214bc896 Use the reverse-mapping btree information to rebuild an inode block map. Update the btree bulk loading code as necessary to support inode rooted btrees and fix some bitrot problems. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_bmap_btree.c | 121 +++++++++++++++++++++++++++++++------ libxfs/xfs_bmap_btree.h | 5 ++ libxfs/xfs_btree_staging.c | 11 +++- libxfs/xfs_btree_staging.h | 2 +- libxfs/xfs_iext_tree.c | 23 ++++--- libxfs/xfs_inode_fork.c | 1 + libxfs/xfs_inode_fork.h | 3 + 7 files changed, 136 insertions(+), 30 deletions(-) diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index c4d5c8a64..73ba067df 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -15,6 +15,7 @@ #include "xfs_trans.h" #include "xfs_alloc.h" #include "xfs_btree.h" +#include "xfs_btree_staging.h" #include "xfs_bmap_btree.h" #include "xfs_bmap.h" #include "xfs_trace.h" @@ -286,10 +287,7 @@ xfs_bmbt_get_minrecs( int level) { if (level == cur->bc_nlevels - 1) { - struct xfs_ifork *ifp; - - ifp = xfs_ifork_ptr(cur->bc_ino.ip, - cur->bc_ino.whichfork); + struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur); return xfs_bmbt_maxrecs(cur->bc_mp, ifp->if_broot_bytes, level == 0) / 2; @@ -304,10 +302,7 @@ xfs_bmbt_get_maxrecs( int level) { if (level == cur->bc_nlevels - 1) { - struct xfs_ifork *ifp; - - ifp = xfs_ifork_ptr(cur->bc_ino.ip, - cur->bc_ino.whichfork); + struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur); return xfs_bmbt_maxrecs(cur->bc_mp, ifp->if_broot_bytes, level == 0); @@ -541,23 +536,19 @@ static const struct xfs_btree_ops xfs_bmbt_ops = { .keys_contiguous = xfs_bmbt_keys_contiguous, }; -/* - * Allocate a new bmap btree cursor. - */ -struct xfs_btree_cur * /* new bmap btree cursor */ -xfs_bmbt_init_cursor( - struct xfs_mount *mp, /* file system mount point */ - struct xfs_trans *tp, /* transaction pointer */ - struct xfs_inode *ip, /* inode owning the btree */ - int whichfork) /* data or attr fork */ +static struct xfs_btree_cur * +xfs_bmbt_init_common( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_inode *ip, + int whichfork) { - struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); struct xfs_btree_cur *cur; + ASSERT(whichfork != XFS_COW_FORK); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP, mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); - cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); cur->bc_ops = &xfs_bmbt_ops; @@ -565,10 +556,30 @@ xfs_bmbt_init_cursor( if (xfs_has_crc(mp)) cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; - cur->bc_ino.forksize = xfs_inode_fork_size(ip, whichfork); cur->bc_ino.ip = ip; cur->bc_ino.allocated = 0; cur->bc_ino.flags = 0; + + return cur; +} + +/* + * Allocate a new bmap btree cursor. + */ +struct xfs_btree_cur * +xfs_bmbt_init_cursor( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_inode *ip, + int whichfork) +{ + struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); + struct xfs_btree_cur *cur; + + cur = xfs_bmbt_init_common(mp, tp, ip, whichfork); + + cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; + cur->bc_ino.forksize = xfs_inode_fork_size(ip, whichfork); cur->bc_ino.whichfork = whichfork; return cur; @@ -585,6 +596,76 @@ xfs_bmbt_block_maxrecs( return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)); } +/* + * Allocate a new bmap btree cursor for reloading an inode block mapping data + * structure. Note that callers can use the staged cursor to reload extents + * format inode forks if they rebuild the iext tree and commit the staged + * cursor immediately. + */ +struct xfs_btree_cur * +xfs_bmbt_stage_cursor( + struct xfs_mount *mp, + struct xfs_inode *ip, + struct xbtree_ifakeroot *ifake) +{ + struct xfs_btree_cur *cur; + struct xfs_btree_ops *ops; + + /* data fork always has larger maxheight */ + cur = xfs_bmbt_init_common(mp, NULL, ip, XFS_DATA_FORK); + cur->bc_nlevels = ifake->if_levels; + cur->bc_ino.forksize = ifake->if_fork_size; + + /* Don't let anyone think we're attached to the real fork yet. */ + cur->bc_ino.whichfork = -1; + xfs_btree_stage_ifakeroot(cur, ifake, &ops); + ops->update_cursor = NULL; + return cur; +} + +/* + * Swap in the new inode fork root. Once we pass this point the newly rebuilt + * mappings are in place and we have to kill off any old btree blocks. + */ +void +xfs_bmbt_commit_staged_btree( + struct xfs_btree_cur *cur, + struct xfs_trans *tp, + int whichfork) +{ + struct xbtree_ifakeroot *ifake = cur->bc_ino.ifake; + struct xfs_ifork *ifp; + static const short brootflag[2] = {XFS_ILOG_DBROOT, XFS_ILOG_ABROOT}; + static const short extflag[2] = {XFS_ILOG_DEXT, XFS_ILOG_AEXT}; + int flags = XFS_ILOG_CORE; + + ASSERT(cur->bc_flags & XFS_BTREE_STAGING); + ASSERT(whichfork != XFS_COW_FORK); + + /* + * Free any resources hanging off the real fork, then shallow-copy the + * staging fork's contents into the real fork to transfer everything + * we just built. + */ + ifp = xfs_ifork_ptr(cur->bc_ino.ip, whichfork); + xfs_idestroy_fork(ifp); + memcpy(ifp, ifake->if_fork, sizeof(struct xfs_ifork)); + + switch (ifp->if_format) { + case XFS_DINODE_FMT_EXTENTS: + flags |= extflag[whichfork]; + break; + case XFS_DINODE_FMT_BTREE: + flags |= brootflag[whichfork]; + break; + default: + ASSERT(0); + break; + } + xfs_trans_log_inode(tp, cur->bc_ino.ip, flags); + xfs_btree_commit_ifakeroot(cur, tp, whichfork, &xfs_bmbt_ops); +} + /* * Calculate number of records in a bmap btree block. */ diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h index 3e7a40a83..151b8491f 100644 --- a/libxfs/xfs_bmap_btree.h +++ b/libxfs/xfs_bmap_btree.h @@ -11,6 +11,7 @@ struct xfs_btree_block; struct xfs_mount; struct xfs_inode; struct xfs_trans; +struct xbtree_ifakeroot; /* * Btree block header size depends on a superblock flag. @@ -106,6 +107,10 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip, extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, struct xfs_trans *, struct xfs_inode *, int); +struct xfs_btree_cur *xfs_bmbt_stage_cursor(struct xfs_mount *mp, + struct xfs_inode *ip, struct xbtree_ifakeroot *ifake); +void xfs_bmbt_commit_staged_btree(struct xfs_btree_cur *cur, + struct xfs_trans *tp, int whichfork); extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp, unsigned long long len); diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index d4164e37b..0ea44dcf1 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -405,7 +405,7 @@ xfs_btree_bload_prep_block( ASSERT(*bpp == NULL); /* Allocate a new incore btree root block. */ - new_size = bbl->iroot_size(cur, nr_this_block, priv); + new_size = bbl->iroot_size(cur, level, nr_this_block, priv); ifp->if_broot = kmem_zalloc(new_size, 0); ifp->if_broot_bytes = (int)new_size; @@ -596,7 +596,14 @@ xfs_btree_bload_level_geometry( unsigned int desired_npb; unsigned int maxnr; - maxnr = cur->bc_ops->get_maxrecs(cur, level); + /* + * Compute the absolute maximum number of records that we can store in + * the ondisk block or inode root. + */ + if (cur->bc_ops->get_dmaxrecs) + maxnr = cur->bc_ops->get_dmaxrecs(cur, level); + else + maxnr = cur->bc_ops->get_maxrecs(cur, level); /* * Compute the number of blocks we need to fill each block with the diff --git a/libxfs/xfs_btree_staging.h b/libxfs/xfs_btree_staging.h index f0a500728..055ea43b1 100644 --- a/libxfs/xfs_btree_staging.h +++ b/libxfs/xfs_btree_staging.h @@ -53,7 +53,7 @@ typedef int (*xfs_btree_bload_get_records_fn)(struct xfs_btree_cur *cur, typedef int (*xfs_btree_bload_claim_block_fn)(struct xfs_btree_cur *cur, union xfs_btree_ptr *ptr, void *priv); typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur, - unsigned int nr_this_level, void *priv); + unsigned int level, unsigned int nr_this_level, void *priv); struct xfs_btree_bload { /* diff --git a/libxfs/xfs_iext_tree.c b/libxfs/xfs_iext_tree.c index 7f5c4f403..5d0be2dc8 100644 --- a/libxfs/xfs_iext_tree.c +++ b/libxfs/xfs_iext_tree.c @@ -622,13 +622,11 @@ static inline void xfs_iext_inc_seq(struct xfs_ifork *ifp) } void -xfs_iext_insert( - struct xfs_inode *ip, +xfs_iext_insert_raw( + struct xfs_ifork *ifp, struct xfs_iext_cursor *cur, - struct xfs_bmbt_irec *irec, - int state) + struct xfs_bmbt_irec *irec) { - struct xfs_ifork *ifp = xfs_iext_state_to_fork(ip, state); xfs_fileoff_t offset = irec->br_startoff; struct xfs_iext_leaf *new = NULL; int nr_entries, i; @@ -662,12 +660,23 @@ xfs_iext_insert( xfs_iext_set(cur_rec(cur), irec); ifp->if_bytes += sizeof(struct xfs_iext_rec); - trace_xfs_iext_insert(ip, cur, state, _RET_IP_); - if (new) xfs_iext_insert_node(ifp, xfs_iext_leaf_key(new, 0), new, 2); } +void +xfs_iext_insert( + struct xfs_inode *ip, + struct xfs_iext_cursor *cur, + struct xfs_bmbt_irec *irec, + int state) +{ + struct xfs_ifork *ifp = xfs_iext_state_to_fork(ip, state); + + xfs_iext_insert_raw(ifp, cur, irec); + trace_xfs_iext_insert(ip, cur, state, _RET_IP_); +} + static struct xfs_iext_node * xfs_iext_rebalance_node( struct xfs_iext_node *parent, diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 3e2d7882a..80f4215d2 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -518,6 +518,7 @@ xfs_idata_realloc( ifp->if_bytes = new_size; } +/* Free all memory and reset a fork back to its initial state. */ void xfs_idestroy_fork( struct xfs_ifork *ifp) diff --git a/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index 96d307784..535be5c03 100644 --- a/libxfs/xfs_inode_fork.h +++ b/libxfs/xfs_inode_fork.h @@ -180,6 +180,9 @@ void xfs_init_local_fork(struct xfs_inode *ip, int whichfork, const void *data, int64_t size); xfs_extnum_t xfs_iext_count(struct xfs_ifork *ifp); +void xfs_iext_insert_raw(struct xfs_ifork *ifp, + struct xfs_iext_cursor *cur, + struct xfs_bmbt_irec *irec); void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *, int); void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *, From patchwork Mon Apr 22 16:26:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638721 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 38179155322 for ; Mon, 22 Apr 2024 16:40: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=1713804010; cv=none; b=aA9I3iiPNHQfeQwCykt9zGRlojVEhBuOGt2xRD3b4gH/RJr4G+p4bmWraXPGXy0e1KLr+ooOoPaFE2/mnl4BDuOi9XgT63bX+uNx2vIYyviWmTlYEMpmrj/PUfRd+Ur3vjnO2rxR1uqB/vPHZJQz0+5fCxLZBzpL7XiTESup6cY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804010; c=relaxed/simple; bh=i43HAKxlcJG4UIWPwjKagi154EE+Cye0UO+fhVDguQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mKWK/ygdrgDms+DZWZ2JcZrehgMXjlhRXAtvEadW4gnPavYLz1HEDo/lWMcjmJ8XpJ+O1ianTKtr8yt9blV2xpEZuBN9yBF+a9OBUQLYuURtuIyd+dAKB55w1+9NF0KeQblM3ye1h9vjH5jt8bSIILhrHn9q/lrDCA0wq+IEELQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lDb4EzLB; 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="lDb4EzLB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2550BC113CC; Mon, 22 Apr 2024 16:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804010; bh=i43HAKxlcJG4UIWPwjKagi154EE+Cye0UO+fhVDguQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDb4EzLBIUh4nDVIyst4iNyLO+6YsYbTFKUPwegpl16uiaVok82j/32pmTewGo6nE W6Z/H+T1LEkaMHiscb0nheBykkGyatgndkfceprEGYRGCCCMY2I11aVfFCz2kpyWcv qT1WuvegeFHMlw9gDle8+j8rdUZYXpJKLWxp7R3TFxDEoMiEcfa6MqBICbwDhT/tux /ckvzMDfUQKMEQeuM+n4Jzn7JzdkHR2JRjAthdYIWx8cRQi7292KbS60r1a0uiIzaF ewqvAIRGO3vaLpz0uWQ2z7iWLn8kxTvuYk3tGTdFSS7mLZax9qaaBCE8Lo1DsizWj4 twWkw6p4PhW4w== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 41/67] xfs: create a ranged query function for refcount btrees Date: Mon, 22 Apr 2024 18:26:03 +0200 Message-ID: <20240422163832.858420-43-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: d12bf8bac87a0d93e6e5fab67f399d1e3d3d5767 Implement ranged queries for refcount records. The next patch will use this to scan refcount data. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_refcount.c | 41 +++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_refcount.h | 10 ++++++++++ 2 files changed, 51 insertions(+) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 3377fac12..de321ab9d 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -2030,6 +2030,47 @@ xfs_refcount_has_records( return xfs_btree_has_records(cur, &low, &high, NULL, outcome); } +struct xfs_refcount_query_range_info { + xfs_refcount_query_range_fn fn; + void *priv; +}; + +/* Format btree record and pass to our callback. */ +STATIC int +xfs_refcount_query_range_helper( + struct xfs_btree_cur *cur, + const union xfs_btree_rec *rec, + void *priv) +{ + struct xfs_refcount_query_range_info *query = priv; + struct xfs_refcount_irec irec; + xfs_failaddr_t fa; + + xfs_refcount_btrec_to_irec(rec, &irec); + fa = xfs_refcount_check_irec(cur->bc_ag.pag, &irec); + if (fa) + return xfs_refcount_complain_bad_rec(cur, fa, &irec); + + return query->fn(cur, &irec, query->priv); +} + +/* Find all refcount records between two keys. */ +int +xfs_refcount_query_range( + struct xfs_btree_cur *cur, + const struct xfs_refcount_irec *low_rec, + const struct xfs_refcount_irec *high_rec, + xfs_refcount_query_range_fn fn, + void *priv) +{ + union xfs_btree_irec low_brec = { .rc = *low_rec }; + union xfs_btree_irec high_brec = { .rc = *high_rec }; + struct xfs_refcount_query_range_info query = { .priv = priv, .fn = fn }; + + return xfs_btree_query_range(cur, &low_brec, &high_brec, + xfs_refcount_query_range_helper, &query); +} + int __init xfs_refcount_intent_init_cache(void) { diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 5c207f1c6..9b56768a5 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -127,4 +127,14 @@ extern struct kmem_cache *xfs_refcount_intent_cache; int __init xfs_refcount_intent_init_cache(void); void xfs_refcount_intent_destroy_cache(void); +typedef int (*xfs_refcount_query_range_fn)( + struct xfs_btree_cur *cur, + const struct xfs_refcount_irec *rec, + void *priv); + +int xfs_refcount_query_range(struct xfs_btree_cur *cur, + const struct xfs_refcount_irec *low_rec, + const struct xfs_refcount_irec *high_rec, + xfs_refcount_query_range_fn fn, void *priv); + #endif /* __XFS_REFCOUNT_H__ */ From patchwork Mon Apr 22 16:26:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638722 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 E6659155322 for ; Mon, 22 Apr 2024 16:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804012; cv=none; b=scRhYZWrrNBunBvfU77BmqYvU61Yabsjx5l+PGCliC7OYyLx6FEVp2/fp7lqZhl5lD4YhHbrzxW3p+dZZ4tTSPeNXm9LjAyKiyu5bsopVg4wnTLtG0xryAwi97iZSMKPT1k9Q+W/zqMksyNHZiHoL9ST2XHvJd/x7U+aWjghGQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804012; c=relaxed/simple; bh=UeTN0MAJcj8UPCvUewdl4rrSNGpewHceTbh9WFAnfOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M+Zhf0w0xenF+jB9GFRVExaCi57zgp2LXUdBJgFrAAA+OpdvqC82muXh7haWK067v2F454lB11RXDrJPqUnyMZUATeOrXzTg8IGRmaLTnMuTmF8rLiuCSp54m+WS86IILeYRPPnDETL6pLHFF9Nc/5kTQBKkBsUDSG+IIbd2Mmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gyy/YASF; 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="gyy/YASF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A1E5C113CC; Mon, 22 Apr 2024 16:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804011; bh=UeTN0MAJcj8UPCvUewdl4rrSNGpewHceTbh9WFAnfOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gyy/YASFsP21Y1F6vwKCv+6NLR/fvDnCaD7LwQ4c3qw5Tie02d4v4DZb0941MiggX PcQlpsv0s85OuLO2EeZuL27dHNNLcHFx0NxABc4ZQcRC8Km6Ihj3ayOGZ3xvcygxQD EdKiCoisRS4KE9KTMzxOrP7vkMWuzevg1iAqj1CbvzM5wmiqg4ImX0KXB5b4kn9FUK +UppMYfsFQCDr8Wz1LuuXU1FgPjZK7tFReYmZxcr1SHHBbEwuzFiynEku3wQKh3x+O BhEScUCeaqmcmAocIqT8pINKlKIPhu9NA/+I7aP+zSMtD2CDjjnTDaIqzVqglGBjKB hw2pHdgRXbzFg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 42/67] xfs: create a new inode fork block unmap helper Date: Mon, 22 Apr 2024 18:26:04 +0200 Message-ID: <20240422163832.858420-44-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: a59eb5fc21b2a6dc160ee6cdf77f20bc186a88fd Create a new helper to unmap blocks from an inode's fork. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_bmap.c | 41 ++++++++++++++++++++++++++++++++++++++++- libxfs/xfs_bmap.h | 5 ++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 534a516b5..3520235b5 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5233,7 +5233,7 @@ xfs_bmap_del_extent_real( * that value. If not all extents in the block range can be removed then * *done is set. */ -int /* error */ +static int __xfs_bunmapi( struct xfs_trans *tp, /* transaction pointer */ struct xfs_inode *ip, /* incore inode */ @@ -6214,3 +6214,42 @@ xfs_bmap_validate_extent( return xfs_bmap_validate_extent_raw(ip->i_mount, XFS_IS_REALTIME_INODE(ip), whichfork, irec); } + +/* + * Used in xfs_itruncate_extents(). This is the maximum number of extents + * freed from a file in a single transaction. + */ +#define XFS_ITRUNC_MAX_EXTENTS 2 + +/* + * Unmap every extent in part of an inode's fork. We don't do any higher level + * invalidation work at all. + */ +int +xfs_bunmapi_range( + struct xfs_trans **tpp, + struct xfs_inode *ip, + uint32_t flags, + xfs_fileoff_t startoff, + xfs_fileoff_t endoff) +{ + xfs_filblks_t unmap_len = endoff - startoff + 1; + int error = 0; + + ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); + + while (unmap_len > 0) { + ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER); + error = __xfs_bunmapi(*tpp, ip, startoff, &unmap_len, flags, + XFS_ITRUNC_MAX_EXTENTS); + if (error) + goto out; + + /* free the just unmapped extents */ + error = xfs_defer_finish(tpp); + if (error) + goto out; + } +out: + return error; +} diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 8518324db..4b83f6148 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -190,9 +190,6 @@ int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno, int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags, xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap); -int __xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, - xfs_fileoff_t bno, xfs_filblks_t *rlen, uint32_t flags, - xfs_extnum_t nexts); int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags, xfs_extnum_t nexts, int *done); @@ -273,6 +270,8 @@ int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork, int xfs_bmapi_remap(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, xfs_fsblock_t startblock, uint32_t flags); +int xfs_bunmapi_range(struct xfs_trans **tpp, struct xfs_inode *ip, + uint32_t flags, xfs_fileoff_t startoff, xfs_fileoff_t endoff); extern struct kmem_cache *xfs_bmap_intent_cache; From patchwork Mon Apr 22 16:26:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638723 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 6408E155322 for ; Mon, 22 Apr 2024 16:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804013; cv=none; b=CR5aw5RaH5U6lPtAI8+1hrD7+3NsyfsT7zfxOvM5T8GcMeJFh4AhCss3E3Wm37cs6MkpkdA4296YKBUDmoG3OJpjjkqce+8GZlCbr/SSznnOGmN8qTQw1VboeSxtQgOUhadKk3RskRktc8Cbs5Sc9dFiqaUpZ+21P0ZR3j1cdqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804013; c=relaxed/simple; bh=EK253xF7BpSn9XIb9FTn/fvEtVKLIcQGi0SfzPLOTiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XbihlNz/WsaOxXo6967b+aiGxG/KuVqLaoyBmVT/UMkDCzCZI1lXhHu5SUX/57ZhWcd+8sD0khebIh3hES38d8g+dJ3GPwNjlFCinn/3bwM3JQrAJLnyOLMVqT0oN+MhyPfedTEsjPNI6MeoZNSEP/kAduyNoKGYNQhBW14gV9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bo98XKXG; 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="Bo98XKXG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0562CC32782; Mon, 22 Apr 2024 16:40:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804013; bh=EK253xF7BpSn9XIb9FTn/fvEtVKLIcQGi0SfzPLOTiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bo98XKXGmLRU30xAABtKhx+oH2HhhqUCLXKaRRxwFSn5kI6W2b82XAbdp7gjRUrGy Jsy+FN0WNc/RnhMD2yzABNUanZH+Ytc8WlkeJ0uFo+5rqPcWjQuDu3oIKICLpA3Uv7 29oueAlLzYB5FLOH/W6+4dmKeAMWK8ZNlsGg+aka2sSes/DHxdgAdGq1DK/hwe8ieS 9kDKnX16NaPXSV3Kd0SzSvHVVrAcCX17juBqo9u9wvXGkTTOfRsAombK0w3hBefw2s HOMySlL7un8vPE91jYtdUWHbzFZWoc8ToEyiM+tBXX/L0XFMzZ0nppwle0w+5DYWL+ z6ys43HxuNLRA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 43/67] xfs: improve dquot iteration for scrub Date: Mon, 22 Apr 2024 18:26:05 +0200 Message-ID: <20240422163832.858420-45-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 21d7500929c8a0b10e22a6755850c6f9a9280284 Upon a closer inspection of the quota record scrubber, I noticed that dqiterate wasn't actually walking all possible dquots for the mapped blocks in the quota file. This is due to xfs_qm_dqget_next skipping all XFS_IS_DQUOT_UNINITIALIZED dquots. For a fsck program, we really want to look at all the dquots, even if all counters and limits in the dquot record are zero. Rewrite the implementation to do this, as well as switching to an iterator paradigm to reduce the number of indirect calls. This enables removal of the old broken dqiterate code from xfs_dquot.c. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino --- libxfs/xfs_format.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index f16974126..e6ca188e2 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1272,6 +1272,9 @@ static inline time64_t xfs_dq_bigtime_to_unix(uint32_t ondisk_seconds) #define XFS_DQ_GRACE_MIN ((int64_t)0) #define XFS_DQ_GRACE_MAX ((int64_t)U32_MAX) +/* Maximum id value for a quota record */ +#define XFS_DQ_ID_MAX (U32_MAX) + /* * This is the main portion of the on-disk representation of quota information * for a user. We pad this with some more expansion room to construct the on From patchwork Mon Apr 22 16:26:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638724 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 E42AE15532C for ; Mon, 22 Apr 2024 16:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804015; cv=none; b=Xu83IteaCDlckZhMsghmT0z3g6mYSkFfqLKLnCTMHuV+zTssCWOVgs4NATFuHr9IYdBDV+9+4p7zdscdn8j/sxX1+8B1mYnbEX4o8WWmHj1h+OnR4WNkSF/O2K4vy8RHgN0kcc38+qhNkgML+ZCp/sZNVLU6orqgVCKemYpS+9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804015; c=relaxed/simple; bh=HuOdS/o33+w9Mpc5xiCPIBPlI7L0jq+HfOPo1LzwERE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hQlt4WgtjZZV227Ff9fOChMMalzFRq0dnVj35lJKA2C1qb5PeTHP9H/MswXUihKtisDkdsp2e8S5wBFhB/DfIj+j4QysO2PWQHNnpEH7Lplnok9U90et4HVNnvKN56HU20diCm2XDEIpaIJQmip3yq8Agr60HrLLdrX2lH+v8kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cXguF37Q; 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="cXguF37Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85B3DC113CC; Mon, 22 Apr 2024 16:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804014; bh=HuOdS/o33+w9Mpc5xiCPIBPlI7L0jq+HfOPo1LzwERE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXguF37QaZvzlrbadISlF8DpJ2Uv1lhLIaZMqvFLftGbK8Adub5JAFI02r3PRu5HO ACd6lKVzM762mUF1bLSS2L/AqE5YQxlOh9lYCbAMomLRl5dsFNj+w2WcreMghfJbyI 5Ahjrkzc57M+S9TRJpcPgWoPa7Wg6Af+v4P6TF8iTAp2FkFwxIDIZnXXNN5fPEckO+ piBaQ8Hb9tPR+6xEktpdx+sQ25lKA8EBxutbc+7deFjU5pXCD900r75b85jeyC1oId caUZPey8tEdSJw014+0QkB4NJOc68Omam+dBxlz1c2DOkdmKbmelScjwVfViPKvCBH EIP1spafLFhlQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 44/67] xfs: add lock protection when remove perag from radix tree Date: Mon, 22 Apr 2024 18:26:06 +0200 Message-ID: <20240422163832.858420-46-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 07afd3173d0c6d24a47441839a835955ec6cf0d4 Take mp->m_perag_lock for deletions from the perag radix tree in xfs_initialize_perag to prevent racing with tagging operations. Lookups are fine - they are RCU protected so already deal with the tree changing shape underneath the lookup - but tagging operations require the tree to be stable while the tags are propagated back up to the root. Right now there's nothing stopping radix tree tagging from operating while a growfs operation is progress and adding/removing new entries into the radix tree. Hence we can have traversals that require a stable tree occurring at the same time we are removing unused entries from the radix tree which causes the shape of the tree to change. Likely this hasn't caused a problem in the past because we are only doing append addition and removal so the active AG part of the tree is not changing shape, but that doesn't mean it is safe. Just making the radix tree modifications serialise against each other is obviously correct. Signed-off-by: Long Li Reviewed-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index bdb8a08bb..1dbc01b97 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -422,13 +422,17 @@ xfs_initialize_perag( out_remove_pag: xfs_defer_drain_free(&pag->pag_intents_drain); + spin_lock(&mp->m_perag_lock); radix_tree_delete(&mp->m_perag_tree, index); + spin_unlock(&mp->m_perag_lock); out_free_pag: kmem_free(pag); out_unwind_new_pags: /* unwind any prior newly initialized pags */ for (index = first_initialised; index < agcount; index++) { + spin_lock(&mp->m_perag_lock); pag = radix_tree_delete(&mp->m_perag_tree, index); + spin_unlock(&mp->m_perag_lock); if (!pag) break; xfs_buf_hash_destroy(pag); From patchwork Mon Apr 22 16:26:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638725 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 1D06115532C for ; Mon, 22 Apr 2024 16:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804016; cv=none; b=CKBikns+t2xUrjczcPX/h3MVpVnmu9l2UPh2uBh2Laxra7wfQONrSmfKIb1Rqipbl2+NdC7zsgrrBdEso56r5K6H3TWZyhOvifxkvDMY4id/zitq7DN+gGrUjebHijMyhniaKxNeozxGt5aUllI8qQaITwjfHVPD9Xab26kiwvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804016; c=relaxed/simple; bh=etCbGVxQf0Sx64up78GHdAXT/fIstmZ/FJLURz1MJvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bWBkGf2YYLgsOr1iqwRqLYaZvTVaQatf9V1SEouBQ/uw4TqxkGlDoh0tjLgMfUxCPLQGBoJhKthhtpnFk0gsJzsNBHDmdzEx9l978OMtBLGxtvMF8QpWXwnPiq1CCCNw4EgR0KyTSjNLQg2eoPSlG4qTOil4vsuu2oEiUBxhCPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GYO3EX1j; 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="GYO3EX1j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE9FC116B1; Mon, 22 Apr 2024 16:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804016; bh=etCbGVxQf0Sx64up78GHdAXT/fIstmZ/FJLURz1MJvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GYO3EX1jmc59EfWH7ntQSXRfgjFwxP0CHx90V61us8Te9zRiRGDFP+nuZ0GPXu85x jhvwkPMYWqZp89eqk51ncrOYjDnUFmphFtywUEwbQobSKFBYxtnnn75fe2GKal1JrZ Q9vXQ/fPdlu14Jgio0am81RTTN1Bo9vSe7WjlKPmnkVcU8YwsP/plC29cLqiTCpoIQ lakv4LvUYfxTV3Gi2RIvFxq7eYDPswReJfmpGB6Bg82eIEpDM8vS34PxNCfeJtOWp8 sGaGT3WPKe7nt34w0K0sEQDHv4AiT69eHi5+qeiCxyiZTvCnlc4YERm9Nu8egbAbfo Y2klocaxXsaDA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 45/67] xfs: fix perag leak when growfs fails Date: Mon, 22 Apr 2024 18:26:07 +0200 Message-ID: <20240422163832.858420-47-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 7823921887750b39d02e6b44faafdd1cc617c651 During growfs, if new ag in memory has been initialized, however sb_agcount has not been updated, if an error occurs at this time it will cause perag leaks as follows, these new AGs will not been freed during umount , because of these new AGs are not visible(that is included in mp->m_sb.sb_agcount). unreferenced object 0xffff88810be40200 (size 512): comm "xfs_growfs", pid 857, jiffies 4294909093 hex dump (first 32 bytes): 00 c0 c1 05 81 88 ff ff 04 00 00 00 00 00 00 00 ................ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace (crc 381741e2): [] __kmalloc+0x386/0x4f0 [] kmem_alloc+0xb5/0x2f0 [] xfs_initialize_perag+0xc5/0x810 [] xfs_growfs_data+0x9bc/0xbc0 [] xfs_file_ioctl+0x5fe/0x14d0 [] __x64_sys_ioctl+0x144/0x1c0 [] do_syscall_64+0x3f/0xe0 [] entry_SYSCALL_64_after_hwframe+0x62/0x6a unreferenced object 0xffff88810be40800 (size 512): comm "xfs_growfs", pid 857, jiffies 4294909093 hex dump (first 32 bytes): 20 00 00 00 00 00 00 00 57 ef be dc 00 00 00 00 .......W....... 10 08 e4 0b 81 88 ff ff 10 08 e4 0b 81 88 ff ff ................ backtrace (crc bde50e2d): [] __kmalloc_node+0x3da/0x540 [] kvmalloc_node+0x99/0x160 [] bucket_table_alloc.isra.0+0x5f/0x400 [] rhashtable_init+0x405/0x760 [] xfs_initialize_perag+0x3a3/0x810 [] xfs_growfs_data+0x9bc/0xbc0 [] xfs_file_ioctl+0x5fe/0x14d0 [] __x64_sys_ioctl+0x144/0x1c0 [] do_syscall_64+0x3f/0xe0 [] entry_SYSCALL_64_after_hwframe+0x62/0x6a Factor out xfs_free_unused_perag_range() from xfs_initialize_perag(), used for freeing unused perag within a specified range in error handling, included in the error path of the growfs failure. Fixes: 1c1c6ebcf528 ("xfs: Replace per-ag array with a radix tree") Signed-off-by: Long Li Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_ag.c | 36 ++++++++++++++++++++++++++---------- libxfs/xfs_ag.h | 2 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 1dbc01b97..0556d5547 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -330,6 +330,31 @@ xfs_agino_range( return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last); } +/* + * Free perag within the specified AG range, it is only used to free unused + * perags under the error handling path. + */ +void +xfs_free_unused_perag_range( + struct xfs_mount *mp, + xfs_agnumber_t agstart, + xfs_agnumber_t agend) +{ + struct xfs_perag *pag; + xfs_agnumber_t index; + + for (index = agstart; index < agend; index++) { + spin_lock(&mp->m_perag_lock); + pag = radix_tree_delete(&mp->m_perag_tree, index); + spin_unlock(&mp->m_perag_lock); + if (!pag) + break; + xfs_buf_hash_destroy(pag); + xfs_defer_drain_free(&pag->pag_intents_drain); + kmem_free(pag); + } +} + int xfs_initialize_perag( struct xfs_mount *mp, @@ -429,16 +454,7 @@ out_free_pag: kmem_free(pag); out_unwind_new_pags: /* unwind any prior newly initialized pags */ - for (index = first_initialised; index < agcount; index++) { - spin_lock(&mp->m_perag_lock); - pag = radix_tree_delete(&mp->m_perag_tree, index); - spin_unlock(&mp->m_perag_lock); - if (!pag) - break; - xfs_buf_hash_destroy(pag); - xfs_defer_drain_free(&pag->pag_intents_drain); - kmem_free(pag); - } + xfs_free_unused_perag_range(mp, first_initialised, agcount); return error; } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 67c3260ee..4b343c4fa 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -143,6 +143,8 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA) __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES) __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) +void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart, + xfs_agnumber_t agend); int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount, xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); From patchwork Mon Apr 22 16:26:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638726 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 4F7D6153823 for ; Mon, 22 Apr 2024 16:40: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=1713804018; cv=none; b=p8R6u2E9Mhv21byZjjOeJR9Ol5wawXsCA2H7UrUYljo3GRghQiflZe/cqDPS+O0DwJ1Bfx7gsBplTaUWRli6vHgK7qVK+58rWQFeNBaR1QTWL0zkQvXVbI/PvHspD+fgmSnbK9f2fA+NPxNPc+r1ZNLe0jD7XObqeJT/1qwIJBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804018; c=relaxed/simple; bh=j0kDHaFOc1jHzTMt4bfQ8fY7fCmtKRZgXyhQ47lLlrs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NFyWAdkMYujJqdSqpo1iXszuFwqf6lU2PK6p5KsW5/ysl5d68OfOx+6uIlgWVekqnWvtSiAzf2s38uIyDYAM/LX4Rt6uHeuXxrM2PpMJEfv3Qe6BBqEtHa8D0JH80T3h35JPVn7f5lykVsaSGvJHscayMgzeGpI57Py2zSdxNdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LfiEOv+/; 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="LfiEOv+/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E2EEC32786; Mon, 22 Apr 2024 16:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804017; bh=j0kDHaFOc1jHzTMt4bfQ8fY7fCmtKRZgXyhQ47lLlrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfiEOv+/VHDQ0SW79Qnk25ggoozSVxrbmu+FeNp12HTHSWvPgrBa0HtaWk+DWvrgt dfNVwdbWsXCeRmFwTkzipqld+a+lyWHnJkov9yI74BbtA6pDUgnWIQJeqtwwm6sjIx YpCEyHuO5wi47PP7ZKqLzG3STh4rfGuan5QL4P3icvoVx2865d8E7wfyV1+QHWxKJQ XjSODn9qh7oYMc6rTqtsb46nKzg66Zw3eedxZm2v+2KUle6Jc5GGKw+vv1clIibgaz bVsgPoHrRqJXfQWm9zri0zFgz0388bNpFLQtx1vaxsLdX9zYP1T5nLw+uVVvBVXGza T4amcSBVIZaog== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 46/67] xfs: remove the xfs_alloc_arg argument to xfs_bmap_btalloc_accounting Date: Mon, 22 Apr 2024 18:26:08 +0200 Message-ID: <20240422163832.858420-48-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: eef519d746bbfb90cbad4077c2d39d7a359c3282 xfs_bmap_btalloc_accounting only uses the len field from args, but that has just been propagated to ap->length field by the caller. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_bmap.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 3520235b5..ad058bb12 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3259,8 +3259,7 @@ xfs_bmap_btalloc_select_lengths( /* Update all inode and quota accounting for the allocation we just did. */ static void xfs_bmap_btalloc_accounting( - struct xfs_bmalloca *ap, - struct xfs_alloc_arg *args) + struct xfs_bmalloca *ap) { if (ap->flags & XFS_BMAPI_COWFORK) { /* @@ -3273,7 +3272,7 @@ xfs_bmap_btalloc_accounting( * yet. */ if (ap->wasdel) { - xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); + xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)ap->length); return; } @@ -3285,22 +3284,22 @@ xfs_bmap_btalloc_accounting( * This essentially transfers the transaction quota reservation * to that of a delalloc extent. */ - ap->ip->i_delayed_blks += args->len; + ap->ip->i_delayed_blks += ap->length; xfs_trans_mod_dquot_byino(ap->tp, ap->ip, XFS_TRANS_DQ_RES_BLKS, - -(long)args->len); + -(long)ap->length); return; } /* data/attr fork only */ - ap->ip->i_nblocks += args->len; + ap->ip->i_nblocks += ap->length; xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); if (ap->wasdel) { - ap->ip->i_delayed_blks -= args->len; - xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); + ap->ip->i_delayed_blks -= ap->length; + xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)ap->length); } xfs_trans_mod_dquot_byino(ap->tp, ap->ip, ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT, - args->len); + ap->length); } static int @@ -3374,7 +3373,7 @@ xfs_bmap_process_allocated_extent( ap->offset = orig_offset; else if (ap->offset + ap->length < orig_offset + orig_length) ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap, args); + xfs_bmap_btalloc_accounting(ap); } #ifdef DEBUG From patchwork Mon Apr 22 16:26:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638727 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 CC3ED153823 for ; Mon, 22 Apr 2024 16:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804019; cv=none; b=DYX4i+P1XmvXFhM1LM5rlTP06BrnL8sYcQgzjKl8yZ81gyZMP4V/cIz4Ihr9462pBXSpNNBbZyLXy3PriBxbmKfmymP9seyzOrNMO5aliYscenbPmTjENmh7Ek7mV0sdLyyXUnQx2BgJfe01p2YGENH71RlsbeJrwbBiEVUHuko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804019; c=relaxed/simple; bh=qGFsOEfgcHU4+rSFtBwbYdRJdqBPhF6/elGWXKnS0WM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dyD1vY2nYIHxTnaNloS/KsYJLjD6jVK6Lv6xVf+MsgaHj9hSRoV5yYdWSoa1nuFuLjLJEyWkdbY3doCa/Uk6QLltM3oL4dJ2YS3sc3ZOmt9QRA1AJp8O8QwzR/K5qD3IARtUdYRi8hDtZArGZNL/SW+dyI1CpJVGSyjTKSUc0+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d2mmR2jk; 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="d2mmR2jk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5844EC113CC; Mon, 22 Apr 2024 16:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804019; bh=qGFsOEfgcHU4+rSFtBwbYdRJdqBPhF6/elGWXKnS0WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2mmR2jk5APtmd9OYca/NwrKQu96NSIyXqKQOlxfzukGD8kJiHs3/Oce970R5S5oI 0zCQ242mV46IyHmPK2KSfQwl0YSzT+uVUt95bjRxc5HCDyIxS8FPktWKissnxAI7fi M8/UY7n1oXCw0vKSnjweVweoJlMR2kfpRSqXGvo3ZBMzeSzyZFtEtVd0WGbKFMKTlf jDhxNUNVwFbXSolsrGQG8cTUle0F6mB8+zBUVv5vRHs4lXKkF+/ctGYA/UTxCRYqKF cR3TbexbGcqDS1CgPcgJp0UKAwJ+nmfnpRxIY5mbxq38yBzBbV/47fBjbMyiEZnj1v 3KzKA3bDPl//A== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 47/67] xfs: also use xfs_bmap_btalloc_accounting for RT allocations Date: Mon, 22 Apr 2024 18:26:09 +0200 Message-ID: <20240422163832.858420-49-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 58643460546da1dc61593fc6fd78762798b4534f Make xfs_bmap_btalloc_accounting more generic by handling the RT quota reservations and then also use it from xfs_bmap_rtalloc instead of open coding the accounting logic there. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/libxfs_priv.h | 8 +++++++- libxfs/xfs_bmap.c | 21 ++++++++++++++------- libxfs/xfs_bmap.h | 2 ++ libxfs/xfs_bmap_btree.c | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 30ff8dba9..3ba6b0e55 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -434,7 +434,13 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa); #define xfs_filestream_select_ag(...) (-ENOSYS) /* quota bits */ -#define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0) + +/* Silence GCC unused variable warning on xfs_bmap.c */ +#define xfs_trans_mod_dquot_byino(t,i,f,d) ({ \ + uint _f = (f); \ + _f = _f; \ +}) + #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0) /* hack too silence gcc */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index ad058bb12..4f6bd8dff 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3257,10 +3257,14 @@ xfs_bmap_btalloc_select_lengths( } /* Update all inode and quota accounting for the allocation we just did. */ -static void -xfs_bmap_btalloc_accounting( +void +xfs_bmap_alloc_account( struct xfs_bmalloca *ap) { + bool isrt = XFS_IS_REALTIME_INODE(ap->ip) && + (ap->flags & XFS_BMAPI_ATTRFORK); + uint fld; + if (ap->flags & XFS_BMAPI_COWFORK) { /* * COW fork blocks are in-core only and thus are treated as @@ -3285,7 +3289,8 @@ xfs_bmap_btalloc_accounting( * to that of a delalloc extent. */ ap->ip->i_delayed_blks += ap->length; - xfs_trans_mod_dquot_byino(ap->tp, ap->ip, XFS_TRANS_DQ_RES_BLKS, + xfs_trans_mod_dquot_byino(ap->tp, ap->ip, isrt ? + XFS_TRANS_DQ_RES_RTBLKS : XFS_TRANS_DQ_RES_BLKS, -(long)ap->length); return; } @@ -3296,10 +3301,12 @@ xfs_bmap_btalloc_accounting( if (ap->wasdel) { ap->ip->i_delayed_blks -= ap->length; xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)ap->length); + fld = isrt ? XFS_TRANS_DQ_DELRTBCOUNT : XFS_TRANS_DQ_DELBCOUNT; + } else { + fld = isrt ? XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT; } - xfs_trans_mod_dquot_byino(ap->tp, ap->ip, - ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT, - ap->length); + + xfs_trans_mod_dquot_byino(ap->tp, ap->ip, fld, ap->length); } static int @@ -3373,7 +3380,7 @@ xfs_bmap_process_allocated_extent( ap->offset = orig_offset; else if (ap->offset + ap->length < orig_offset + orig_length) ap->offset = orig_offset + orig_length - ap->length; - xfs_bmap_btalloc_accounting(ap); + xfs_bmap_alloc_account(ap); } #ifdef DEBUG diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 4b83f6148..f6b73f1ba 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -116,6 +116,8 @@ static inline int xfs_bmapi_whichfork(uint32_t bmapi_flags) return XFS_DATA_FORK; } +void xfs_bmap_alloc_account(struct xfs_bmalloca *ap); + /* * Special values for xfs_bmbt_irec_t br_startblock field. */ diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 73ba067df..887ba56f3 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -21,6 +21,7 @@ #include "xfs_trace.h" #include "xfs_rmap.h" #include "xfs_ag.h" +#include "xfs_quota_defs.h" static struct kmem_cache *xfs_bmbt_cur_cache; From patchwork Mon Apr 22 16:26:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638728 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 DB8CE153838 for ; Mon, 22 Apr 2024 16:40: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=1713804020; cv=none; b=tgxFE4Qi1f0jXNQZd4wZl+wIZKCQ3j1v6w0n1g8Efc9rn6s+ananF6LuNDPHQGL+1YshnMtxn4V+aF1Kt7AWdoqGmDah8IPGVNbGsL8GJk+gKfUuRbFlG3LE+g7hqZmR+9MpTn63G1hrak2WWSVCenFXSq3UoRgk20QSufPZg/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804020; c=relaxed/simple; bh=JqcGK5wYBKVfXYsLskMhXkUeb+090lqZtOyoBpp4wf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZwvCqjuChZfXHi+P/NEe7L8RuBxcS3+PkkvFaRgdNtvjhj+vC43aGLZCHlGnrgiE2b8EyB67QnM/2dKLJ9UtWa2dmBBgt1dSMm+W6L9Ogygnd6fybk0/5jAoBJePCDBudBzoKDNZnDBWG5GWwOZlnfSIkIzyfTz1XMPZDc+X2FE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2AxytcM; 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="l2AxytcM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4B0AC32781; Mon, 22 Apr 2024 16:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804020; bh=JqcGK5wYBKVfXYsLskMhXkUeb+090lqZtOyoBpp4wf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l2AxytcMRytF3H6YMtIGE17UvpmodkCEzyPGXMcU3VpA9RLA8ARV6ArTAF35sRPhO oZJrB9cil0WUmDOBT/X0775rytLz6mBf9LyXVwujzb39a+lUnkYHxVPzg+MHoLpHLg tDFr3BC++epMND9ml/uN4U6PJFzivLKv+YzqFNnkLDFvQZx1uvbARjVMvjIgorx0st 309+FsFtI/3iSbDdRmsjZC+A76gONTiOrlYx4SBRWKNJNk2vXKD8yUuqvXQyA2dCbV tTtEgB2mGNDWpFAIGxMxir4A8292R3N0VhuhL71Ga1oZnZ7+lcwhMvNVPILxeBI/8s A6TziPeSnA4zw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 48/67] xfs: return -ENOSPC from xfs_rtallocate_* Date: Mon, 22 Apr 2024 18:26:10 +0200 Message-ID: <20240422163832.858420-50-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: ce42b5d37527b282d38413c1b5f7283253f6562d Just return -ENOSPC instead of returning 0 and setting the return rt extent number to NULLRTEXTNO. This is turn removes all users of NULLRTEXTNO, so remove that as well. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_types.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index 035bf703d..20b5375f2 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -51,7 +51,6 @@ typedef void * xfs_failaddr_t; #define NULLRFSBLOCK ((xfs_rfsblock_t)-1) #define NULLRTBLOCK ((xfs_rtblock_t)-1) #define NULLFILEOFF ((xfs_fileoff_t)-1) -#define NULLRTEXTNO ((xfs_rtxnum_t)-1) #define NULLAGBLOCK ((xfs_agblock_t)-1) #define NULLAGNUMBER ((xfs_agnumber_t)-1) From patchwork Mon Apr 22 16:26:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638729 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 6939315381C for ; Mon, 22 Apr 2024 16:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804022; cv=none; b=OynzbXRPvNHbqvvOxILcAY8hWbKVeJlzTivjUW3qO1tlR1j8kjTctTDHN7x+O2qX7jf498/fehhsjksZffna2D2FzJfEIEAMBam8pqDBQtj3ZqYDE+rAdfAhEIfxo2VbULUwVZh2ecNeMwWnbHRjHzo3qzyCwtn4Qzi1C/QxwBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804022; c=relaxed/simple; bh=P54o824N1PjamxFOK4ata08tWArrCHw6v+E6IyhbzSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=blJGg8h6U6n0Tid5JMuQPjJ3yolg9KLxiZVumwziNkEIOD9ESzuJhGDk0Njtbuqiw9wmjVZr7su5G/mjdQAv1LPGcIPFoJ4xhstKK9Q6R3MkvYmh0CpOkQzMzrGXPdK6RLOtd1rSMJTesP7SXF11LP27fmNaQq5UrnH+0XKxrqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RSjkTlEA; 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="RSjkTlEA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50B56C116B1; Mon, 22 Apr 2024 16:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804022; bh=P54o824N1PjamxFOK4ata08tWArrCHw6v+E6IyhbzSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RSjkTlEA/qhybr8VRy46HMduht8FHONuIoJBifzOLTGOFhd/hMNzxa6vMgZ2H/7OX 2fI79P9AdfTFz4nG+fhv/uK+pqLzjgPLGBG2YL/Y9mZ0efVlkCoz8Xa+xZd+no5ZFO CrOMfWpzf57TLsn6/hDloKxBBYm9FaTDPefCYP2778zJNeG6YCLEmHUdvuFM0iwBwT T3Wg42FDXY29dut9jZ+XWS/YCafeMzXHXZeKiHqA6GILdAU257bvKZp8gh38cKFEG2 j0/bQHRj/y4IwGUxBCvTGYftTCF2mYRvFsFWv9D0+hUzts//TzQPz9WrmB+ZuKKNWe tj70UxSRbtIVA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 49/67] xfs: indicate if xfs_bmap_adjacent changed ap->blkno Date: Mon, 22 Apr 2024 18:26:11 +0200 Message-ID: <20240422163832.858420-51-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 676544c27e710aee7f8357f57abd348d98b1ccd4 Add a return value to xfs_bmap_adjacent to indicate if it did change ap->blkno or not. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/libxfs_priv.h | 2 +- libxfs/xfs_bmap.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 3ba6b0e55..ae01b076c 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -568,7 +568,7 @@ int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp, struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz, int rt, int eof, int delay, int convert, xfs_fileoff_t *offp, xfs_extlen_t *lenp); -void xfs_bmap_adjacent(struct xfs_bmalloca *ap); +bool xfs_bmap_adjacent(struct xfs_bmalloca *ap); int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork, struct xfs_bmbt_irec *rec, int *is_empty); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 4f6bd8dff..b977032d8 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3038,7 +3038,8 @@ xfs_bmap_extsize_align( #define XFS_ALLOC_GAP_UNITS 4 -void +/* returns true if ap->blkno was modified */ +bool xfs_bmap_adjacent( struct xfs_bmalloca *ap) /* bmap alloc argument struct */ { @@ -3073,13 +3074,14 @@ xfs_bmap_adjacent( if (adjust && ISVALID(ap->blkno + adjust, ap->prev.br_startblock)) ap->blkno += adjust; + return true; } /* * If not at eof, then compare the two neighbor blocks. * Figure out whether either one gives us a good starting point, * and pick the better one. */ - else if (!ap->eof) { + if (!ap->eof) { xfs_fsblock_t gotbno; /* right side block number */ xfs_fsblock_t gotdiff=0; /* right side difference */ xfs_fsblock_t prevbno; /* left side block number */ @@ -3159,14 +3161,21 @@ xfs_bmap_adjacent( * If both valid, pick the better one, else the only good * one, else ap->blkno is already set (to 0 or the inode block). */ - if (prevbno != NULLFSBLOCK && gotbno != NULLFSBLOCK) + if (prevbno != NULLFSBLOCK && gotbno != NULLFSBLOCK) { ap->blkno = prevdiff <= gotdiff ? prevbno : gotbno; - else if (prevbno != NULLFSBLOCK) + return true; + } + if (prevbno != NULLFSBLOCK) { ap->blkno = prevbno; - else if (gotbno != NULLFSBLOCK) + return true; + } + if (gotbno != NULLFSBLOCK) { ap->blkno = gotbno; + return true; + } } #undef ISVALID + return false; } int From patchwork Mon Apr 22 16:26:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638730 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 EE20415381C for ; Mon, 22 Apr 2024 16:40: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=1713804024; cv=none; b=iblbzLB8kS2NUBRN6Jgy7T4EMUrJSAyjktdvyVqBFTduYFCSsgMdXNpOYf68DUmhz7Kv7NivQwhwQhykAqQ4Wv0y0mc2R6QI8RuwW1jYftMxMDP6UsAkmbuxYSKZUxww8/WLj9HvG3e/+un3yiQbuJVtRrnYOYoxw40ON8k9piE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804024; c=relaxed/simple; bh=LtvFK+XjmBa1pyC2AmAVTKKzbkA+sjg6mj1jT3WDKV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=noPNoT7Gbopgz/Q9NRn72v6gxnxDH5Vs9Hdm/J+2+QM/Ymf9PfCgK9rMpw3JnZDqpXVUBuup4r3f8CcHGfdyw5gC7pnFq+3Pa8YvTdJrpKnEDSy5UvD4emuTGcB4AYn1yKY94QSR0TtxseI1G/ihk2pggshOvUJZKleNC4NuizQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DHqqE67X; 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="DHqqE67X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D398AC32786; Mon, 22 Apr 2024 16:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804023; bh=LtvFK+XjmBa1pyC2AmAVTKKzbkA+sjg6mj1jT3WDKV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DHqqE67X5ncPX+WKUWgGU7ILz6NhfgmVPdNKy1aMtzu0XXDoSSZODJ1pPaXUtKJjU SEsrJTFZwBafNOemFkJk9K6lgIezc1pnyL0boNL6vrNgCbLc//fu6OKHc/hnD7BakA 7IzUr6aBH3abuwolJh62krJPRShg6J5k8r7sqfeQHg/6gVGWuhslSDz259ydouq8VO ENCFs1tzMDQCZhvr2fPJAHU7PKWuZVXALS63kElcOMNRFfauP57cb4kBuSl5xxHdLs frnV++mynb1TBCkQHCCKPQf2h208qPQvbAIYmCSH+N1o6fePXGidbJ63dDxA9KGN+9 MhCXZ4SksJoXg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 50/67] xfs: move xfs_rtget_summary to xfs_rtbitmap.c Date: Mon, 22 Apr 2024 18:26:12 +0200 Message-ID: <20240422163832.858420-52-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: c2adcfa31ff606264fab6e69129d6d45c9ddb7cb xfs_rtmodify_summary_int is only used inside xfs_rtbitmap.c and to implement xfs_rtget_summary. Move xfs_rtget_summary to xfs_rtbitmap.c as the exported API and mark xfs_rtmodify_summary_int static. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.c | 14 ++++++++++++++ libxfs/xfs_rtbitmap.h | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 726543abb..adeaffed7 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -517,6 +517,20 @@ xfs_rtmodify_summary( return xfs_rtmodify_summary_int(args, log, bbno, delta, NULL); } +/* + * Read and return the summary information for a given extent size, bitmap block + * combination. + */ +int +xfs_rtget_summary( + struct xfs_rtalloc_args *args, + int log, /* log2 of extent size */ + xfs_fileoff_t bbno, /* bitmap block number */ + xfs_suminfo_t *sum) /* out: summary info for this block */ +{ + return xfs_rtmodify_summary_int(args, log, bbno, 0, sum); +} + /* Log rtbitmap block from the word @from to the byte before @next. */ static inline void xfs_trans_log_rtbitmap( diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 1c84b52de..274dc7dae 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -321,8 +321,8 @@ int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock); int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, xfs_rtxlen_t len, int val); -int xfs_rtmodify_summary_int(struct xfs_rtalloc_args *args, int log, - xfs_fileoff_t bbno, int delta, xfs_suminfo_t *sum); +int xfs_rtget_summary(struct xfs_rtalloc_args *args, int log, + xfs_fileoff_t bbno, xfs_suminfo_t *sum); int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log, xfs_fileoff_t bbno, int delta); int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, From patchwork Mon Apr 22 16:26:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638731 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 617A115381C for ; Mon, 22 Apr 2024 16:40: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=1713804025; cv=none; b=o+CC19cfhQbXp4PWcH/MlZsV/FqrzNRkYnyyMn78/+pclEwgCcCSRJk0hIzrdN/+RUCzMl9JcuklyKjySwn93leWmkUmqwe014RYXwapu9IHTLr928D2U98r6qru9WGwQLJdfcQQrcNhX3CsN2Al00A2Ph6qDB/wAQwjJ37y9JE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804025; c=relaxed/simple; bh=lB+HOlwXXEe/nQVHNzD6NLpo9SAiN8nPQYgY+0G3wAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jT6vc0ApY5nq+BVp0Q9029y3NlYCr+CRjVJq51EEVcxhc2QxWOf4XjEP9UYArT6JhAWDKVP2ynjaQSt8j5XOOyJ/Woq3Iz0il/fHfAqF/Ghibsf91Kvzdk3u5UV5p/nvkj3g8+Q9BMQa+Zd7S9eNUADAhWMc4oIdDdO6syD7/0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lMh4Jv6F; 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="lMh4Jv6F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F134C32781; Mon, 22 Apr 2024 16:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804025; bh=lB+HOlwXXEe/nQVHNzD6NLpo9SAiN8nPQYgY+0G3wAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMh4Jv6FyhFZ3I8dmJx2mBReisv6Ipvkdc96Vp7kftA9OB1Tg8NAcWfnCgVaOsZ1P yAU1ne/ZxJQApgxl5w6uWMV5VcMbHlldWTQf3Vwt33w+ylaCbK5GJdZ2jP/U8t/wYp mzpSjeQ7yvzUhXMsRGXULUXgMCrwuaJv04fZL6BcBLrOtm+oGsf+qyebovNZ2R9Yje sk4XfKwy4Xcl0jMfRHK6ZSSPp2colRIvGbmf/xZ+JCbuCk1WMKaHJ5BRsCLqnkolmK VIgofQ0AJ/aT1E/BlJLclb1AWmnZQYuMY6LT9gGk5StGzIp/MjL/EMya1NKKqjX5S/ mDwWagpWLjNRg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 51/67] xfs: split xfs_rtmodify_summary_int Date: Mon, 22 Apr 2024 18:26:13 +0200 Message-ID: <20240422163832.858420-53-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: b271b314119eca1fb98a2c4e15304ce562802f0c Inline the logic of xfs_rtmodify_summary_int into xfs_rtmodify_summary and xfs_rtget_summary instead of having a somewhat awkward helper to share a little bit of code. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.c | 76 ++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 51 deletions(-) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index adeaffed7..bbf955be8 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -450,71 +450,38 @@ xfs_trans_log_rtsummary( } /* - * Read and/or modify the summary information for a given extent size, - * bitmap block combination. - * Keeps track of a current summary block, so we don't keep reading - * it from the buffer cache. - * - * Summary information is returned in *sum if specified. - * If no delta is specified, returns summary only. + * Modify the summary information for a given extent size, bitmap block + * combination. */ int -xfs_rtmodify_summary_int( +xfs_rtmodify_summary( struct xfs_rtalloc_args *args, int log, /* log2 of extent size */ xfs_fileoff_t bbno, /* bitmap block number */ - int delta, /* change to make to summary info */ - xfs_suminfo_t *sum) /* out: summary info for this block */ + int delta) /* in/out: summary block number */ { struct xfs_mount *mp = args->mp; - int error; - xfs_fileoff_t sb; /* summary fsblock */ - xfs_rtsumoff_t so; /* index into the summary file */ + xfs_rtsumoff_t so = xfs_rtsumoffs(mp, log, bbno); unsigned int infoword; + xfs_suminfo_t val; + int error; - /* - * Compute entry number in the summary file. - */ - so = xfs_rtsumoffs(mp, log, bbno); - /* - * Compute the block number in the summary file. - */ - sb = xfs_rtsumoffs_to_block(mp, so); - - error = xfs_rtsummary_read_buf(args, sb); + error = xfs_rtsummary_read_buf(args, xfs_rtsumoffs_to_block(mp, so)); if (error) return error; - /* - * Point to the summary information, modify/log it, and/or copy it out. - */ infoword = xfs_rtsumoffs_to_infoword(mp, so); - if (delta) { - xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta); - - if (mp->m_rsum_cache) { - if (val == 0 && log + 1 == mp->m_rsum_cache[bbno]) - mp->m_rsum_cache[bbno] = log; - if (val != 0 && log >= mp->m_rsum_cache[bbno]) - mp->m_rsum_cache[bbno] = log + 1; - } - xfs_trans_log_rtsummary(args, infoword); - if (sum) - *sum = val; - } else if (sum) { - *sum = xfs_suminfo_get(args, infoword); + val = xfs_suminfo_add(args, infoword, delta); + + if (mp->m_rsum_cache) { + if (val == 0 && log + 1 == mp->m_rsum_cache[bbno]) + mp->m_rsum_cache[bbno] = log; + if (val != 0 && log >= mp->m_rsum_cache[bbno]) + mp->m_rsum_cache[bbno] = log + 1; } - return 0; -} -int -xfs_rtmodify_summary( - struct xfs_rtalloc_args *args, - int log, /* log2 of extent size */ - xfs_fileoff_t bbno, /* bitmap block number */ - int delta) /* in/out: summary block number */ -{ - return xfs_rtmodify_summary_int(args, log, bbno, delta, NULL); + xfs_trans_log_rtsummary(args, infoword); + return 0; } /* @@ -528,7 +495,14 @@ xfs_rtget_summary( xfs_fileoff_t bbno, /* bitmap block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ { - return xfs_rtmodify_summary_int(args, log, bbno, 0, sum); + struct xfs_mount *mp = args->mp; + xfs_rtsumoff_t so = xfs_rtsumoffs(mp, log, bbno); + int error; + + error = xfs_rtsummary_read_buf(args, xfs_rtsumoffs_to_block(mp, so)); + if (!error) + *sum = xfs_suminfo_get(args, xfs_rtsumoffs_to_infoword(mp, so)); + return error; } /* Log rtbitmap block from the word @from to the byte before @next. */ From patchwork Mon Apr 22 16:26:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638732 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 CB8C01514CA for ; Mon, 22 Apr 2024 16:40: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=1713804026; cv=none; b=XJdm2L7Ga0Ob+ANJTUkAUFBpWjat5S21HR//vm2kP0IQHU6sPpiX5kpM1OkfGnCQeKgk0SJdXyRZXAbgfVEP3ph8INedy0Z9syuK4HnLv9vkX5Eoq/lWdBf4mollfwaCt+aYz2Ywe6Z3RXPfsLWD13FfSEcB938d39mEhN9mGDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804026; c=relaxed/simple; bh=fzOFol4cvr8odkknKZN2uyJTaiTxNXYam+nrknXWAwI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TLdzLcI2CTk7OE+8UEiG+ItncNrIjJRid3tvQM8wEwW5dfLFOkVptEPgdzMVSwg1m/IQGlFrgToQ5XsOwDXjqvXFp2FCAzwmRt09UzjVQYAjcPcV8kViUcjJJa/uCxWzlyRFL3jJRSW3Rn9HOr8JLAvJGOP0eFcKhkcVML1cKC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I7crmtNf; 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="I7crmtNf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5AB8C113CC; Mon, 22 Apr 2024 16:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804026; bh=fzOFol4cvr8odkknKZN2uyJTaiTxNXYam+nrknXWAwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I7crmtNfhv0/vZfU3O9oBb72iR9xd0lQj8irTug4wM/E06y/0EM/Yxej3XNZIWkes Xh6waqVQgoZxEYDp9T+OB4iU3WnBeK4rMacqZzmQ5KTWiEK7J/HTYmvojT5noDPpjh 7Bxr2Lw7GgSfbZZTLYDb9cSeluvQlTI9L2Tk1dvYknNLgFLX7vywlJNiIKPqqyctUf A6Oo1mLMQGYx+jaiBm1d1EReQpoFZtcmusNFnwXweS+BFtIvH5zujfQ4vBgnwHsyYu N8cSzMchq1jq0w2S7FK+VU/7nUK+w3UXutckgUGa2qJ3mu6QBdmMr+fSKlH2Ywa4v9 99Gkstar9ywsA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 52/67] xfs: remove rt-wrappers from xfs_format.h Date: Mon, 22 Apr 2024 18:26:14 +0200 Message-ID: <20240422163832.858420-54-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 3abfe6c2759e2e3000b13f8ce8a1a325e80987a1 xfs_format.h has a bunch odd wrappers for helper functions and mount structure access using RT* prefixes. Replace them with their open coded versions (for those that weren't entirely unused) and remove the wrappers. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- db/check.c | 4 ++-- libxfs/xfs_format.h | 8 -------- libxfs/xfs_rtbitmap.c | 24 ++++++++++++------------ repair/rt.c | 6 ++---- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/db/check.c b/db/check.c index a47a5d9cb..36d82af0a 100644 --- a/db/check.c +++ b/db/check.c @@ -3647,7 +3647,7 @@ process_rtbitmap( } else if (prevbit == 1) { len = ((int)bmbno - start_bmbno) * bitsperblock + (bit - start_bit); - log = XFS_RTBLOCKLOG(len); + log = xfs_highbit64(len); offs = xfs_rtsumoffs(mp, log, start_bmbno); sumcompute[offs]++; prevbit = 0; @@ -3660,7 +3660,7 @@ process_rtbitmap( if (prevbit == 1) { len = ((int)bmbno - start_bmbno) * bitsperblock + (bit - start_bit); - log = XFS_RTBLOCKLOG(len); + log = xfs_highbit64(len); offs = xfs_rtsumoffs(mp, log, start_bmbno); sumcompute[offs]++; } diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index e6ca188e2..7d2873a79 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1156,20 +1156,12 @@ static inline bool xfs_dinode_has_large_extent_counts( #define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */ #define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */ -#define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize) -#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask) - /* * RT bit manipulation macros. */ #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) -#define XFS_RTLOBIT(w) xfs_lowbit32(w) -#define XFS_RTHIBIT(w) xfs_highbit32(w) - -#define XFS_RTBLOCKLOG(b) xfs_highbit64(b) - /* * Dquot and dquot block format definitions */ diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index bbf955be8..eefc45c64 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -193,7 +193,7 @@ xfs_rtfind_back( /* * Different. Mark where we are and return. */ - i = bit - XFS_RTHIBIT(wdiff); + i = bit - xfs_highbit32(wdiff); *rtx = start - i + 1; return 0; } @@ -231,7 +231,7 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); + i += XFS_NBWORD - 1 - xfs_highbit32(wdiff); *rtx = start - i + 1; return 0; } @@ -270,7 +270,7 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); + i += XFS_NBWORD - 1 - xfs_highbit32(wdiff); *rtx = start - i + 1; return 0; } else @@ -346,7 +346,7 @@ xfs_rtfind_forw( /* * Different. Mark where we are and return. */ - i = XFS_RTLOBIT(wdiff) - bit; + i = xfs_lowbit32(wdiff) - bit; *rtx = start + i - 1; return 0; } @@ -384,7 +384,7 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - i += XFS_RTLOBIT(wdiff); + i += xfs_lowbit32(wdiff); *rtx = start + i - 1; return 0; } @@ -421,7 +421,7 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - i += XFS_RTLOBIT(wdiff); + i += xfs_lowbit32(wdiff); *rtx = start + i - 1; return 0; } else @@ -706,7 +706,7 @@ xfs_rtfree_range( */ if (preblock < start) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(start - preblock), + xfs_highbit64(start - preblock), xfs_rtx_to_rbmblock(mp, preblock), -1); if (error) { return error; @@ -718,7 +718,7 @@ xfs_rtfree_range( */ if (postblock > end) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock - end), + xfs_highbit64(postblock - end), xfs_rtx_to_rbmblock(mp, end + 1), -1); if (error) { return error; @@ -729,7 +729,7 @@ xfs_rtfree_range( * (new) free extent. */ return xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock + 1 - preblock), + xfs_highbit64(postblock + 1 - preblock), xfs_rtx_to_rbmblock(mp, preblock), 1); } @@ -798,7 +798,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - i = XFS_RTLOBIT(wdiff) - bit; + i = xfs_lowbit32(wdiff) - bit; *new = start + i; *stat = 0; return 0; @@ -837,7 +837,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - i += XFS_RTLOBIT(wdiff); + i += xfs_lowbit32(wdiff); *new = start + i; *stat = 0; return 0; @@ -875,7 +875,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - i += XFS_RTLOBIT(wdiff); + i += xfs_lowbit32(wdiff); *new = start + i; *stat = 0; return 0; diff --git a/repair/rt.c b/repair/rt.c index 9f3bc8d53..d5283c57f 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -14,8 +14,6 @@ #include "err_protos.h" #include "rt.h" -#define xfs_highbit64 libxfs_highbit64 /* for XFS_RTBLOCKLOG macro */ - void rtinit(xfs_mount_t *mp) { @@ -90,7 +88,7 @@ generate_rtinfo(xfs_mount_t *mp, } } else if (in_extent == 1) { len = (int) (extno - start_ext); - log = XFS_RTBLOCKLOG(len); + log = libxfs_highbit64(len); offs = xfs_rtsumoffs(mp, log, start_bmbno); sumcompute[offs]++; in_extent = 0; @@ -106,7 +104,7 @@ generate_rtinfo(xfs_mount_t *mp, } if (in_extent == 1) { len = (int) (extno - start_ext); - log = XFS_RTBLOCKLOG(len); + log = libxfs_highbit64(len); offs = xfs_rtsumoffs(mp, log, start_bmbno); sumcompute[offs]++; } From patchwork Mon Apr 22 16:26:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638733 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 73C271514CA for ; Mon, 22 Apr 2024 16:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804028; cv=none; b=QSZElBvxlEYrSu3cP6H7Plbmk4uEOZmqVnyRKUvuITddM3t0aCgKp+hxzTlnws2v8iNxHqsQrlcLupvxe/bAe1ejaYJ5yVGfyFoAYtPJ6eNKoGxYIq36mLtGH01YnuQdBw+JqxH1mqvFTAAghkTayEWWM0+ABwRWIEFh6rpreYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804028; c=relaxed/simple; bh=vVDmQmPSVw2PG6AWXYnniLPSDpzqhEraqZL2YmoLUWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kX8XZ5pEG5E+DZFQkJKmJD9yhCJLdiSBCQcXaLQtHoaBV6uBAgJMOtHME4U88ehce/TBQ+JQ1c58iFoUmxxFNx1GT6GS26ur5rZvPATmT6jAYXt+1a7IS0J4ORPYaY6RtYywUeJAYV1nacMdl5PykGzF2z49LE5vJB5/sewg2Yc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tQRWxV7E; 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="tQRWxV7E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4306DC113CC; Mon, 22 Apr 2024 16:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804028; bh=vVDmQmPSVw2PG6AWXYnniLPSDpzqhEraqZL2YmoLUWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQRWxV7E4mBkrHxW09lkxVgSZZgv19+glCyRJWuqWomi48RN/SxIZEhqiIYDQbhvT jk/CS3vd6RgrVJLsGI7JctBGzrkIAbH9Q+9pTOI2zAbFZKRVnjFfcSzXgAo87xuhDy WgJv/3X4RU/78NrZa6elX7byV92fZ7dJb9DHvEb/FGUzjWFtaamLji2hqmeAaSSPd5 Ica5cGY2OZ+tPGZ4HNjpZLdorPO/W1UvxKOBlwIWP1OWmoBJ91rU554fxVuhJahnHo zavJ+HOy0vBFmGKRwJdrI7zwoVCOlRqZm28y+rf1Mhvn320ufRKxdOoiCutvj+aMn/ SfCIJ0+Sz5BRg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 53/67] xfs: remove XFS_RTMIN/XFS_RTMAX Date: Mon, 22 Apr 2024 18:26:15 +0200 Message-ID: <20240422163832.858420-55-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: a39f5ccc30d5a00b7e6d921aa387ad17d1e6d168 Use the kernel min/max helpers instead. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_format.h | 6 ------ libxfs/xfs_rtbitmap.c | 8 ++++---- mkfs/proto.c | 3 +-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 7d2873a79..382ab1e71 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1156,12 +1156,6 @@ static inline bool xfs_dinode_has_large_extent_counts( #define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */ #define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */ -/* - * RT bit manipulation macros. - */ -#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) -#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) - /* * Dquot and dquot block format definitions */ diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index eefc45c64..79af7cda3 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -182,7 +182,7 @@ xfs_rtfind_back( * Calculate first (leftmost) bit number to look at, * and mask for all the relevant bits in this word. */ - firstbit = XFS_RTMAX((xfs_srtblock_t)(bit - len + 1), 0); + firstbit = max_t(xfs_srtblock_t, bit - len + 1, 0); mask = (((xfs_rtword_t)1 << (bit - firstbit + 1)) - 1) << firstbit; /* @@ -336,7 +336,7 @@ xfs_rtfind_forw( * Calculate last (rightmost) bit number to look at, * and mask for all the relevant bits in this word. */ - lastbit = XFS_RTMIN(bit + len, XFS_NBWORD); + lastbit = min(bit + len, XFS_NBWORD); mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; /* * Calculate the difference between the value there @@ -571,7 +571,7 @@ xfs_rtmodify_range( /* * Compute first bit not changed and mask of relevant bits. */ - lastbit = XFS_RTMIN(bit + len, XFS_NBWORD); + lastbit = min(bit + len, XFS_NBWORD); mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; /* * Set/clear the active bits. @@ -785,7 +785,7 @@ xfs_rtcheck_range( /* * Compute first bit not examined. */ - lastbit = XFS_RTMIN(bit + len, XFS_NBWORD); + lastbit = min(bit + len, XFS_NBWORD); /* * Mask of relevant bits. */ diff --git a/mkfs/proto.c b/mkfs/proto.c index e9c633ed3..ec28728d4 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -780,8 +780,7 @@ rtinit( if (i) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); - ebno = XFS_RTMIN(mp->m_sb.sb_rextents, - bno + NBBY * mp->m_sb.sb_blocksize); + ebno = min(mp->m_sb.sb_rextents, bno + NBBY * mp->m_sb.sb_blocksize); error = -libxfs_rtfree_extent(tp, bno, (xfs_extlen_t)(ebno-bno)); if (error) { fail(_("Error initializing the realtime space"), From patchwork Mon Apr 22 16:26:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638734 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 1A24B2EB11 for ; Mon, 22 Apr 2024 16:40: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=1713804030; cv=none; b=jGJKIl1WF6jisfrIyAtrZrgwdAlS4CkbpJG9R5Nk8QkwnIUT0nMpSl6vUNxlZuhNuSVV6S8JFrN7TFe+uPuqBfBkpgt3OOeMMgvE8TJ3ay2MZVYeuQdSkCm2EU9eFjFymlFWucyL/5en9gbK3i7QWVP4o1vp4TEJh5aPe8Ff3vo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804030; c=relaxed/simple; bh=2WiAZNmJGN4e3pC4PhDd4BbbZIR3BpBNHTdWXPG4ly0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BAT7cBbEdGdETpm2FARhXgbeT0g5Hx0t3YVb/C8G05mr2AYmtz1pFj8AGaEYXJr9iKhpYG4OqQCYO71zX84g0GrrwGYdYELXXwdAdXCqogbp6aYfIMpmuSBpEc5BBIDRuKQN/gXN6/HduGewJ0WOzdkdal5uh198tXq02sTvgio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gEDEbM6A; 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="gEDEbM6A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C81BEC113CC; Mon, 22 Apr 2024 16:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804030; bh=2WiAZNmJGN4e3pC4PhDd4BbbZIR3BpBNHTdWXPG4ly0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gEDEbM6AKn3wdZXN5BLQ0VoAfjAmuZfrf/mvOKENGkbIflYg+dbZmKzTvx9xw18r8 FiIth6HchOScn5KCTELhO013v93FkuglZD/F7OXC5gN7vvvLK3TyCTXDk65as/nILa D1HFix5ioAM8mOj1rxtQTSX1em9cB0sw2OQQY9Vj9RgJO9KDRyeYHl351MKUJcEt1U WJq8OW7mhQoaE0o5NHTktjviclxCozfQ5f6xH+lorHhLE5bdfRVzoExl8AmczsHc9U 2C0WwPXJL6ITs1EGdFcneEWGDWLV/iiNSl3ERf9kxuiPwbkp5vgPzlAfAUAmDqetDB pkDukZShLqv3Q== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 54/67] xfs: make if_data a void pointer Date: Mon, 22 Apr 2024 18:26:16 +0200 Message-ID: <20240422163832.858420-56-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 6e145f943bd86be47e54101fa5939f9ed0cb73e5 The xfs_ifork structure currently has a union of the if_root void pointer and the if_data char pointer. In either case it is an opaque pointer that depends on the fork format. Replace the union with a single if_data void pointer as that is what almost all callers want. Only the symlink NULL termination code in xfs_init_local_fork actually needs a new local variable now. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- db/namei.c | 3 +- libxfs/util.c | 2 +- libxfs/xfs_attr.c | 3 +- libxfs/xfs_attr_leaf.c | 62 ++++++++++++++----------------------- libxfs/xfs_bmap.c | 4 +-- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2_block.c | 6 ++-- libxfs/xfs_dir2_sf.c | 61 ++++++++++++++---------------------- libxfs/xfs_iext_tree.c | 36 ++++++++++----------- libxfs/xfs_inode_fork.c | 53 ++++++++++++++----------------- libxfs/xfs_inode_fork.h | 8 ++--- libxfs/xfs_symlink_remote.c | 4 +-- repair/phase6.c | 9 +++--- 13 files changed, 107 insertions(+), 146 deletions(-) diff --git a/db/namei.c b/db/namei.c index 063721ca9..80252b902 100644 --- a/db/namei.c +++ b/db/namei.c @@ -290,13 +290,12 @@ list_sfdir( struct xfs_mount *mp = dp->i_mount; struct xfs_da_geometry *geo = args->geo; struct xfs_dir2_sf_entry *sfep; - struct xfs_dir2_sf_hdr *sfp; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; xfs_ino_t ino; xfs_dir2_dataptr_t off; unsigned int i; uint8_t filetype; - sfp = (struct xfs_dir2_sf_hdr *)dp->i_df.if_u1.if_data; /* . and .. entries */ off = xfs_dir2_db_off_to_dataptr(geo, geo->datablk, diff --git a/libxfs/util.c b/libxfs/util.c index 8517bfb64..8cea0c150 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -316,7 +316,7 @@ libxfs_init_new_inode( case S_IFLNK: ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; ip->i_df.if_bytes = 0; - ip->i_df.if_u1.if_root = NULL; + ip->i_df.if_data = NULL; break; default: ASSERT(0); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index cb6c8d081..d7512efd4 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1047,9 +1047,8 @@ out_trans_cancel: static inline int xfs_attr_sf_totsize(struct xfs_inode *dp) { - struct xfs_attr_shortform *sf; + struct xfs_attr_shortform *sf = dp->i_af.if_data; - sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data; return be16_to_cpu(sf->hdr.totsize); } diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 8329348eb..5ab52bf1a 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -688,7 +688,7 @@ xfs_attr_shortform_create( if (ifp->if_format == XFS_DINODE_FMT_EXTENTS) ifp->if_format = XFS_DINODE_FMT_LOCAL; xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK); - hdr = (struct xfs_attr_sf_hdr *)ifp->if_u1.if_data; + hdr = ifp->if_data; memset(hdr, 0, sizeof(*hdr)); hdr->totsize = cpu_to_be16(sizeof(*hdr)); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); @@ -709,14 +709,13 @@ xfs_attr_sf_findname( struct xfs_attr_sf_entry **sfep, unsigned int *basep) { - struct xfs_attr_shortform *sf; + struct xfs_attr_shortform *sf = args->dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; unsigned int base = sizeof(struct xfs_attr_sf_hdr); int size = 0; int end; int i; - sf = (struct xfs_attr_shortform *)args->dp->i_af.if_u1.if_data; sfe = &sf->list[0]; end = sf->hdr.count; for (i = 0; i < end; sfe = xfs_attr_sf_nextentry(sfe), @@ -748,29 +747,25 @@ xfs_attr_shortform_add( struct xfs_da_args *args, int forkoff) { - struct xfs_attr_shortform *sf; + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_ifork *ifp = &dp->i_af; + struct xfs_attr_shortform *sf = ifp->if_data; struct xfs_attr_sf_entry *sfe; int offset, size; - struct xfs_mount *mp; - struct xfs_inode *dp; - struct xfs_ifork *ifp; trace_xfs_attr_sf_add(args); - dp = args->dp; - mp = dp->i_mount; dp->i_forkoff = forkoff; - ifp = &dp->i_af; ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; if (xfs_attr_sf_findname(args, &sfe, NULL) == -EEXIST) ASSERT(0); offset = (char *)sfe - (char *)sf; size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); xfs_idata_realloc(dp, size, XFS_ATTR_FORK); - sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; + sf = ifp->if_data; sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset); sfe->namelen = args->namelen; @@ -808,20 +803,16 @@ int xfs_attr_sf_removename( struct xfs_da_args *args) { - struct xfs_attr_shortform *sf; + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_attr_shortform *sf = dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; int size = 0, end, totsize; unsigned int base; - struct xfs_mount *mp; - struct xfs_inode *dp; int error; trace_xfs_attr_sf_remove(args); - dp = args->dp; - mp = dp->i_mount; - sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data; - error = xfs_attr_sf_findname(args, &sfe, &base); /* @@ -875,18 +866,17 @@ xfs_attr_sf_removename( */ /*ARGSUSED*/ int -xfs_attr_shortform_lookup(xfs_da_args_t *args) +xfs_attr_shortform_lookup( + struct xfs_da_args *args) { - struct xfs_attr_shortform *sf; - struct xfs_attr_sf_entry *sfe; - int i; - struct xfs_ifork *ifp; + struct xfs_ifork *ifp = &args->dp->i_af; + struct xfs_attr_shortform *sf = ifp->if_data; + struct xfs_attr_sf_entry *sfe; + int i; trace_xfs_attr_sf_lookup(args); - ifp = &args->dp->i_af; ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; sfe = &sf->list[0]; for (i = 0; i < sf->hdr.count; sfe = xfs_attr_sf_nextentry(sfe), i++) { @@ -906,14 +896,13 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args) */ int xfs_attr_shortform_getvalue( - struct xfs_da_args *args) + struct xfs_da_args *args) { - struct xfs_attr_shortform *sf; - struct xfs_attr_sf_entry *sfe; - int i; + struct xfs_attr_shortform *sf = args->dp->i_af.if_data; + struct xfs_attr_sf_entry *sfe; + int i; ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL); - sf = (struct xfs_attr_shortform *)args->dp->i_af.if_u1.if_data; sfe = &sf->list[0]; for (i = 0; i < sf->hdr.count; sfe = xfs_attr_sf_nextentry(sfe), i++) { @@ -930,25 +919,22 @@ int xfs_attr_shortform_to_leaf( struct xfs_da_args *args) { - struct xfs_inode *dp; - struct xfs_attr_shortform *sf; + struct xfs_inode *dp = args->dp; + struct xfs_ifork *ifp = &dp->i_af; + struct xfs_attr_shortform *sf = ifp->if_data; struct xfs_attr_sf_entry *sfe; struct xfs_da_args nargs; char *tmpbuffer; int error, i, size; xfs_dablk_t blkno; struct xfs_buf *bp; - struct xfs_ifork *ifp; trace_xfs_attr_sf_to_leaf(args); - dp = args->dp; - ifp = &dp->i_af; - sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; size = be16_to_cpu(sf->hdr.totsize); tmpbuffer = kmem_alloc(size, 0); ASSERT(tmpbuffer != NULL); - memcpy(tmpbuffer, ifp->if_u1.if_data, size); + memcpy(tmpbuffer, ifp->if_data, size); sf = (struct xfs_attr_shortform *)tmpbuffer; xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index b977032d8..5e6a5e1f3 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -741,7 +741,7 @@ xfs_bmap_local_to_extents_empty( ASSERT(ifp->if_nextents == 0); xfs_bmap_forkoff_reset(ip, whichfork); - ifp->if_u1.if_root = NULL; + ifp->if_data = NULL; ifp->if_height = 0; ifp->if_format = XFS_DINODE_FMT_EXTENTS; xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); @@ -826,7 +826,7 @@ xfs_bmap_local_to_extents( xfs_bmap_local_to_extents_empty(tp, ip, whichfork); flags |= XFS_ILOG_CORE; - ifp->if_u1.if_root = NULL; + ifp->if_data = NULL; ifp->if_height = 0; rec.br_startoff = 0; diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index c19684b34..a781520c8 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -195,7 +195,7 @@ xfs_dir_isempty( return 1; if (dp->i_disk_size > xfs_inode_data_fork_size(dp)) return 0; - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; return !sfp->count; } diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index bb9301b76..bf950c700 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -1086,7 +1086,7 @@ xfs_dir2_sf_to_block( int newoffset; /* offset from current entry */ unsigned int offset = geo->data_entry_offset; xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */ - xfs_dir2_sf_hdr_t *oldsfp; /* old shortform header */ + struct xfs_dir2_sf_hdr *oldsfp = ifp->if_data; xfs_dir2_sf_hdr_t *sfp; /* shortform header */ __be16 *tagp; /* end of data entry */ struct xfs_name name; @@ -1096,10 +1096,8 @@ xfs_dir2_sf_to_block( ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); - oldsfp = (xfs_dir2_sf_hdr_t *)ifp->if_u1.if_data; - ASSERT(ifp->if_bytes == dp->i_disk_size); - ASSERT(ifp->if_u1.if_data != NULL); + ASSERT(oldsfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count)); ASSERT(dp->i_df.if_nextents == 0); diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c index 260eccacf..b2b43e937 100644 --- a/libxfs/xfs_dir2_sf.c +++ b/libxfs/xfs_dir2_sf.c @@ -364,25 +364,23 @@ int /* error */ xfs_dir2_sf_addname( xfs_da_args_t *args) /* operation arguments */ { - xfs_inode_t *dp; /* incore directory inode */ + struct xfs_inode *dp = args->dp; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int error; /* error return value */ int incr_isize; /* total change in size */ int new_isize; /* size after adding name */ int objchange; /* changing to 8-byte inodes */ xfs_dir2_data_aoff_t offset = 0; /* offset for new entry */ int pick; /* which algorithm to use */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ xfs_dir2_sf_entry_t *sfep = NULL; /* shortform entry */ trace_xfs_dir2_sf_addname(args); ASSERT(xfs_dir2_sf_lookup(args) == -ENOENT); - dp = args->dp; ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(dp->i_df.if_u1.if_data != NULL); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* * Compute entry (and change in) size. @@ -462,11 +460,9 @@ xfs_dir2_sf_addname_easy( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; - int byteoff; /* byte offset in sf dir */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; + int byteoff = (int)((char *)sfep - (char *)sfp); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; - byteoff = (int)((char *)sfep - (char *)sfp); /* * Grow the in-inode space. */ @@ -475,7 +471,7 @@ xfs_dir2_sf_addname_easy( /* * Need to set up again due to realloc of the inode data. */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff); /* * Fill in the new entry. @@ -528,11 +524,10 @@ xfs_dir2_sf_addname_hard( /* * Copy the old directory to the stack buffer. */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; old_isize = (int)dp->i_disk_size; buf = kmem_alloc(old_isize, 0); oldsfp = (xfs_dir2_sf_hdr_t *)buf; - memcpy(oldsfp, sfp, old_isize); + memcpy(oldsfp, dp->i_df.if_data, old_isize); /* * Loop over the old directory finding the place we're going * to insert the new entry. @@ -560,7 +555,7 @@ xfs_dir2_sf_addname_hard( /* * Reset the pointer since the buffer was reallocated. */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; /* * Copy the first part of the directory, including the header. */ @@ -610,11 +605,10 @@ xfs_dir2_sf_addname_pick( int i; /* entry number */ xfs_dir2_data_aoff_t offset; /* data block offset */ xfs_dir2_sf_entry_t *sfep; /* shortform entry */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int size; /* entry's data size */ int used; /* data bytes used */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; size = xfs_dir2_data_entsize(mp, args->namelen); offset = args->geo->data_first_offset; sfep = xfs_dir2_sf_firstentry(sfp); @@ -673,14 +667,13 @@ xfs_dir2_sf_check( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int i; /* entry number */ int i8count; /* number of big inode#s */ xfs_ino_t ino; /* entry inode number */ int offset; /* data offset */ xfs_dir2_sf_entry_t *sfep; /* shortform dir entry */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; offset = args->geo->data_first_offset; ino = xfs_dir2_sf_get_parent_ino(sfp); i8count = ino > XFS_DIR2_MAX_SHORT_INUM; @@ -834,7 +827,7 @@ xfs_dir2_sf_create( /* * Fill in the header, */ - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; sfp->i8count = i8count; /* * Now can put in the inode number, since i8count is set. @@ -857,9 +850,9 @@ xfs_dir2_sf_lookup( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int i; /* entry index */ xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ enum xfs_dacmp cmp; /* comparison result */ xfs_dir2_sf_entry_t *ci_sfep; /* case-insens. entry */ @@ -870,8 +863,7 @@ xfs_dir2_sf_lookup( ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(dp->i_df.if_u1.if_data != NULL); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* * Special case for . @@ -933,13 +925,13 @@ xfs_dir2_sf_removename( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int byteoff; /* offset of removed entry */ int entsize; /* this entry's size */ int i; /* shortform entry index */ int newsize; /* new inode size */ int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ trace_xfs_dir2_sf_removename(args); @@ -947,8 +939,7 @@ xfs_dir2_sf_removename( oldsize = (int)dp->i_disk_size; ASSERT(oldsize >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == oldsize); - ASSERT(dp->i_df.if_u1.if_data != NULL); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + ASSERT(sfp != NULL); ASSERT(oldsize >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* * Loop over the old directory entries. @@ -989,7 +980,7 @@ xfs_dir2_sf_removename( * Reallocate, making it smaller. */ xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; /* * Are we changing inode number size? */ @@ -1012,13 +1003,12 @@ xfs_dir2_sf_replace_needblock( struct xfs_inode *dp, xfs_ino_t inum) { + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int newsize; - struct xfs_dir2_sf_hdr *sfp; if (dp->i_df.if_format != XFS_DINODE_FMT_LOCAL) return false; - sfp = (struct xfs_dir2_sf_hdr *)dp->i_df.if_u1.if_data; newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF; return inum > XFS_DIR2_MAX_SHORT_INUM && @@ -1034,19 +1024,18 @@ xfs_dir2_sf_replace( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; int i; /* entry index */ xfs_ino_t ino=0; /* entry old inode number */ int i8elevated; /* sf_toino8 set i8count=1 */ xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ - xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ trace_xfs_dir2_sf_replace(args); ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(dp->i_df.if_u1.if_data != NULL); - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* @@ -1069,7 +1058,7 @@ xfs_dir2_sf_replace( */ xfs_dir2_sf_toino8(args); i8elevated = 1; - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; } else i8elevated = 0; @@ -1150,11 +1139,11 @@ xfs_dir2_sf_toino4( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *oldsfp = dp->i_df.if_data; char *buf; /* old dir's buffer */ int i; /* entry index */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ - xfs_dir2_sf_hdr_t *oldsfp; /* old sf directory */ int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ @@ -1168,7 +1157,6 @@ xfs_dir2_sf_toino4( */ oldsize = dp->i_df.if_bytes; buf = kmem_alloc(oldsize, 0); - oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; ASSERT(oldsfp->i8count == 1); memcpy(buf, oldsfp, oldsize); /* @@ -1181,7 +1169,7 @@ xfs_dir2_sf_toino4( * Reset our pointers, the data has moved. */ oldsfp = (xfs_dir2_sf_hdr_t *)buf; - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; /* * Fill in the new header. */ @@ -1223,11 +1211,11 @@ xfs_dir2_sf_toino8( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *oldsfp = dp->i_df.if_data; char *buf; /* old dir's buffer */ int i; /* entry index */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ - xfs_dir2_sf_hdr_t *oldsfp; /* old sf directory */ int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ @@ -1241,7 +1229,6 @@ xfs_dir2_sf_toino8( */ oldsize = dp->i_df.if_bytes; buf = kmem_alloc(oldsize, 0); - oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; ASSERT(oldsfp->i8count == 0); memcpy(buf, oldsfp, oldsize); /* @@ -1254,7 +1241,7 @@ xfs_dir2_sf_toino8( * Reset our pointers, the data has moved. */ oldsfp = (xfs_dir2_sf_hdr_t *)buf; - sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; + sfp = dp->i_df.if_data; /* * Fill in the new header. */ diff --git a/libxfs/xfs_iext_tree.c b/libxfs/xfs_iext_tree.c index 5d0be2dc8..24124039f 100644 --- a/libxfs/xfs_iext_tree.c +++ b/libxfs/xfs_iext_tree.c @@ -158,7 +158,7 @@ static void * xfs_iext_find_first_leaf( struct xfs_ifork *ifp) { - struct xfs_iext_node *node = ifp->if_u1.if_root; + struct xfs_iext_node *node = ifp->if_data; int height; if (!ifp->if_height) @@ -176,7 +176,7 @@ static void * xfs_iext_find_last_leaf( struct xfs_ifork *ifp) { - struct xfs_iext_node *node = ifp->if_u1.if_root; + struct xfs_iext_node *node = ifp->if_data; int height, i; if (!ifp->if_height) @@ -306,7 +306,7 @@ xfs_iext_find_level( xfs_fileoff_t offset, int level) { - struct xfs_iext_node *node = ifp->if_u1.if_root; + struct xfs_iext_node *node = ifp->if_data; int height, i; if (!ifp->if_height) @@ -402,12 +402,12 @@ xfs_iext_grow( int i; if (ifp->if_height == 1) { - struct xfs_iext_leaf *prev = ifp->if_u1.if_root; + struct xfs_iext_leaf *prev = ifp->if_data; node->keys[0] = xfs_iext_leaf_key(prev, 0); node->ptrs[0] = prev; } else { - struct xfs_iext_node *prev = ifp->if_u1.if_root; + struct xfs_iext_node *prev = ifp->if_data; ASSERT(ifp->if_height > 1); @@ -418,7 +418,7 @@ xfs_iext_grow( for (i = 1; i < KEYS_PER_NODE; i++) node->keys[i] = XFS_IEXT_KEY_INVALID; - ifp->if_u1.if_root = node; + ifp->if_data = node; ifp->if_height++; } @@ -430,7 +430,7 @@ xfs_iext_update_node( int level, void *ptr) { - struct xfs_iext_node *node = ifp->if_u1.if_root; + struct xfs_iext_node *node = ifp->if_data; int height, i; for (height = ifp->if_height; height > level; height--) { @@ -583,11 +583,11 @@ xfs_iext_alloc_root( { ASSERT(ifp->if_bytes == 0); - ifp->if_u1.if_root = kmem_zalloc(sizeof(struct xfs_iext_rec), KM_NOFS); + ifp->if_data = kmem_zalloc(sizeof(struct xfs_iext_rec), KM_NOFS); ifp->if_height = 1; /* now that we have a node step into it */ - cur->leaf = ifp->if_u1.if_root; + cur->leaf = ifp->if_data; cur->pos = 0; } @@ -603,9 +603,9 @@ xfs_iext_realloc_root( if (new_size / sizeof(struct xfs_iext_rec) == RECS_PER_LEAF) new_size = NODE_SIZE; - new = krealloc(ifp->if_u1.if_root, new_size, GFP_NOFS | __GFP_NOFAIL); + new = krealloc(ifp->if_data, new_size, GFP_NOFS | __GFP_NOFAIL); memset(new + ifp->if_bytes, 0, new_size - ifp->if_bytes); - ifp->if_u1.if_root = new; + ifp->if_data = new; cur->leaf = new; } @@ -786,8 +786,8 @@ again: * If we are at the root and only one entry is left we can just * free this node and update the root pointer. */ - ASSERT(node == ifp->if_u1.if_root); - ifp->if_u1.if_root = node->ptrs[0]; + ASSERT(node == ifp->if_data); + ifp->if_data = node->ptrs[0]; ifp->if_height--; kmem_free(node); } @@ -863,8 +863,8 @@ xfs_iext_free_last_leaf( struct xfs_ifork *ifp) { ifp->if_height--; - kmem_free(ifp->if_u1.if_root); - ifp->if_u1.if_root = NULL; + kmem_free(ifp->if_data); + ifp->if_data = NULL; } void @@ -881,7 +881,7 @@ xfs_iext_remove( trace_xfs_iext_remove(ip, cur, state, _RET_IP_); ASSERT(ifp->if_height > 0); - ASSERT(ifp->if_u1.if_root != NULL); + ASSERT(ifp->if_data != NULL); ASSERT(xfs_iext_valid(ifp, cur)); xfs_iext_inc_seq(ifp); @@ -1051,9 +1051,9 @@ void xfs_iext_destroy( struct xfs_ifork *ifp) { - xfs_iext_destroy_node(ifp->if_u1.if_root, ifp->if_height); + xfs_iext_destroy_node(ifp->if_data, ifp->if_height); ifp->if_bytes = 0; ifp->if_height = 0; - ifp->if_u1.if_root = NULL; + ifp->if_data = NULL; } diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 80f4215d2..fbcda5f54 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -48,12 +48,15 @@ xfs_init_local_fork( mem_size++; if (size) { - ifp->if_u1.if_data = kmem_alloc(mem_size, KM_NOFS); - memcpy(ifp->if_u1.if_data, data, size); + char *new_data = kmem_alloc(mem_size, KM_NOFS); + + memcpy(new_data, data, size); if (zero_terminate) - ifp->if_u1.if_data[size] = '\0'; + new_data[size] = '\0'; + + ifp->if_data = new_data; } else { - ifp->if_u1.if_data = NULL; + ifp->if_data = NULL; } ifp->if_bytes = size; @@ -123,7 +126,7 @@ xfs_iformat_extents( } ifp->if_bytes = 0; - ifp->if_u1.if_root = NULL; + ifp->if_data = NULL; ifp->if_height = 0; if (size) { dp = (xfs_bmbt_rec_t *) XFS_DFORK_PTR(dip, whichfork); @@ -210,7 +213,7 @@ xfs_iformat_btree( ifp->if_broot, size); ifp->if_bytes = 0; - ifp->if_u1.if_root = NULL; + ifp->if_data = NULL; ifp->if_height = 0; return 0; } @@ -507,14 +510,14 @@ xfs_idata_realloc( return; if (new_size == 0) { - kmem_free(ifp->if_u1.if_data); - ifp->if_u1.if_data = NULL; + kmem_free(ifp->if_data); + ifp->if_data = NULL; ifp->if_bytes = 0; return; } - ifp->if_u1.if_data = krealloc(ifp->if_u1.if_data, new_size, - GFP_NOFS | __GFP_NOFAIL); + ifp->if_data = krealloc(ifp->if_data, new_size, + GFP_NOFS | __GFP_NOFAIL); ifp->if_bytes = new_size; } @@ -530,8 +533,8 @@ xfs_idestroy_fork( switch (ifp->if_format) { case XFS_DINODE_FMT_LOCAL: - kmem_free(ifp->if_u1.if_data); - ifp->if_u1.if_data = NULL; + kmem_free(ifp->if_data); + ifp->if_data = NULL; break; case XFS_DINODE_FMT_EXTENTS: case XFS_DINODE_FMT_BTREE: @@ -624,9 +627,9 @@ xfs_iflush_fork( case XFS_DINODE_FMT_LOCAL: if ((iip->ili_fields & dataflag[whichfork]) && (ifp->if_bytes > 0)) { - ASSERT(ifp->if_u1.if_data != NULL); + ASSERT(ifp->if_data != NULL); ASSERT(ifp->if_bytes <= xfs_inode_fork_size(ip, whichfork)); - memcpy(cp, ifp->if_u1.if_data, ifp->if_bytes); + memcpy(cp, ifp->if_data, ifp->if_bytes); } break; @@ -704,17 +707,15 @@ xfs_ifork_verify_local_data( case S_IFDIR: { struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); - struct xfs_dir2_sf_hdr *sfp; + struct xfs_dir2_sf_hdr *sfp = ifp->if_data; - sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; fa = xfs_dir2_sf_verify(mp, sfp, ifp->if_bytes); break; } case S_IFLNK: { struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); - fa = xfs_symlink_shortform_verify(ifp->if_u1.if_data, - ifp->if_bytes); + fa = xfs_symlink_shortform_verify(ifp->if_data, ifp->if_bytes); break; } default: @@ -723,7 +724,7 @@ xfs_ifork_verify_local_data( if (fa) { xfs_inode_verifier_error(ip, -EFSCORRUPTED, "data fork", - ip->i_df.if_u1.if_data, ip->i_df.if_bytes, fa); + ip->i_df.if_data, ip->i_df.if_bytes, fa); return -EFSCORRUPTED; } @@ -741,20 +742,14 @@ xfs_ifork_verify_local_attr( if (!xfs_inode_has_attr_fork(ip)) { fa = __this_address; } else { - struct xfs_attr_shortform *sfp; - struct xfs_ifork *ifp; - int64_t size; - - ASSERT(ip->i_af.if_format == XFS_DINODE_FMT_LOCAL); - ifp = xfs_ifork_ptr(ip, XFS_ATTR_FORK); - sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; - size = ifp->if_bytes; + struct xfs_ifork *ifp = &ip->i_af; - fa = xfs_attr_shortform_verify(sfp, size); + ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); + fa = xfs_attr_shortform_verify(ifp->if_data, ifp->if_bytes); } if (fa) { xfs_inode_verifier_error(ip, -EFSCORRUPTED, "attr fork", - ifp->if_u1.if_data, ifp->if_bytes, fa); + ifp->if_data, ifp->if_bytes, fa); return -EFSCORRUPTED; } diff --git a/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index 535be5c03..7edcf0e8c 100644 --- a/libxfs/xfs_inode_fork.h +++ b/libxfs/xfs_inode_fork.h @@ -13,14 +13,12 @@ struct xfs_dinode; * File incore extent information, present for each of data & attr forks. */ struct xfs_ifork { - int64_t if_bytes; /* bytes in if_u1 */ + int64_t if_bytes; /* bytes in if_data */ struct xfs_btree_block *if_broot; /* file's incore btree root */ unsigned int if_seq; /* fork mod counter */ int if_height; /* height of the extent tree */ - union { - void *if_root; /* extent tree root */ - char *if_data; /* inline file data */ - } if_u1; + void *if_data; /* extent tree root or + inline data */ xfs_extnum_t if_nextents; /* # of extents in this fork */ short if_broot_bytes; /* bytes allocated for root */ int8_t if_format; /* format of this fork */ diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index cf894b527..fa90b1793 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -172,7 +172,7 @@ xfs_symlink_local_to_remote( if (!xfs_has_crc(mp)) { bp->b_ops = NULL; - memcpy(bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); + memcpy(bp->b_addr, ifp->if_data, ifp->if_bytes); xfs_trans_log_buf(tp, bp, 0, ifp->if_bytes - 1); return; } @@ -188,7 +188,7 @@ xfs_symlink_local_to_remote( buf = bp->b_addr; buf += xfs_symlink_hdr_set(mp, ip->i_ino, 0, ifp->if_bytes, bp); - memcpy(buf, ifp->if_u1.if_data, ifp->if_bytes); + memcpy(buf, ifp->if_data, ifp->if_bytes); xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsymlink_hdr) + ifp->if_bytes - 1); } diff --git a/repair/phase6.c b/repair/phase6.c index 3870c5c93..1b4ec6f90 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -515,7 +515,7 @@ mk_rbmino(xfs_mount_t *mp) * now the ifork */ ip->i_df.if_bytes = 0; - ip->i_df.if_u1.if_root = NULL; + ip->i_df.if_data = NULL; ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; @@ -754,7 +754,7 @@ mk_rsumino(xfs_mount_t *mp) * now the ifork */ ip->i_df.if_bytes = 0; - ip->i_df.if_u1.if_root = NULL; + ip->i_df.if_data = NULL; ip->i_disk_size = mp->m_rsumsize; @@ -854,7 +854,7 @@ mk_root_dir(xfs_mount_t *mp) * now the ifork */ ip->i_df.if_bytes = 0; - ip->i_df.if_u1.if_root = NULL; + ip->i_df.if_data = NULL; /* * initialize the directory @@ -2456,7 +2456,7 @@ shortform_dir2_entry_check( { xfs_ino_t lino; xfs_ino_t parent; - struct xfs_dir2_sf_hdr *sfp; + struct xfs_dir2_sf_hdr *sfp = ip->i_df.if_data; struct xfs_dir2_sf_entry *sfep; struct xfs_dir2_sf_entry *next_sfep; struct xfs_ifork *ifp; @@ -2471,7 +2471,6 @@ shortform_dir2_entry_check( int i8; ifp = &ip->i_df; - sfp = (struct xfs_dir2_sf_hdr *) ifp->if_u1.if_data; *ino_dirty = 0; bytes_deleted = 0; From patchwork Mon Apr 22 16:26:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638735 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 9E1252EB11 for ; Mon, 22 Apr 2024 16: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=1713804031; cv=none; b=RzDSRSgyrDZ7ph64HUsmMXDSDKj0UsANlaPBKRIcZGAfPFeY2/e0zmdRYMK7oK+PjaQbnJOG/DzbM6UaYm/OXZJqwd7vF1BwcUanI6n+mLHB10wTB1RIaM8NQnSS36gnyPD+Al9YCyBhVIXOxvqjYzVeqpArZ069/efNib6y5gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804031; c=relaxed/simple; bh=8Um9wyQH4bEoYP7NbHAWkQ175jHXlsQzyyH7UNBR5PM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RecUf4bRaTAc7w+0K2NK9GiEaxDkb5v9OO93his3c+oUi5GvsFf1ArBYbDd7U1bLa5POf4jaKJzt1jvAsTFTfAE0OcYMizUx978N3hZsR/aqVzAnzciIfY9WwuVzrHl8GYWjR5sGwom62C60/pRguaMxI5Wf/CMx4LTGSmFEewU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fcbj8gQX; 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="fcbj8gQX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85276C116B1; Mon, 22 Apr 2024 16:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804031; bh=8Um9wyQH4bEoYP7NbHAWkQ175jHXlsQzyyH7UNBR5PM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcbj8gQX/fOyNKIMdvRlwgriCc5wiB/pJEpaGdtReaaPdSOUZaR1KjgsoUPDA01rC gVKzMFa4PZs9CpM/XU38FyWOaLY6fcifOn1BeSuNDBL4jJ+R94OL/r20ZXpjGkbAWx aTIogLcL/BkmTle1vEZIQPQLJgsCmINK8ju45fNX11eV1s0hlN2VXtIn9AZmXMBlbl cdnabkzu/oIVwxovCvrxbxhbXkP9FO8usA7ngGTdRkHf5BuU4QEzvAzIhHaxCKYqAa VKKXUU7+5gygrz+6zbnmPK6wR9LEsx6WV/ob+IFXMaGXauqkQ96/o7LIMdx/aleQep DA03TwxyPigIg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 55/67] xfs: return if_data from xfs_idata_realloc Date: Mon, 22 Apr 2024 18:26:17 +0200 Message-ID: <20240422163832.858420-57-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 45c76a2add55b332d965c901e14004ae0134a67e Many of the xfs_idata_realloc callers need to set a local pointer to the just reallocated if_data memory. Return the pointer to simplify them a bit and use the opportunity to re-use krealloc for freeing if_data if the size hits 0. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr_leaf.c | 7 +++---- libxfs/xfs_dir2_sf.c | 25 ++++++++++--------------- libxfs/xfs_inode_fork.c | 20 ++++++++------------ libxfs/xfs_inode_fork.h | 2 +- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 5ab52bf1a..a21740a87 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -687,8 +687,8 @@ xfs_attr_shortform_create( ASSERT(ifp->if_bytes == 0); if (ifp->if_format == XFS_DINODE_FMT_EXTENTS) ifp->if_format = XFS_DINODE_FMT_LOCAL; - xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK); - hdr = ifp->if_data; + + hdr = xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK); memset(hdr, 0, sizeof(*hdr)); hdr->totsize = cpu_to_be16(sizeof(*hdr)); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); @@ -764,8 +764,7 @@ xfs_attr_shortform_add( offset = (char *)sfe - (char *)sf; size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); - xfs_idata_realloc(dp, size, XFS_ATTR_FORK); - sf = ifp->if_data; + sf = xfs_idata_realloc(dp, size, XFS_ATTR_FORK); sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset); sfe->namelen = args->namelen; diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c index b2b43e937..37c7e1d5c 100644 --- a/libxfs/xfs_dir2_sf.c +++ b/libxfs/xfs_dir2_sf.c @@ -466,12 +466,11 @@ xfs_dir2_sf_addname_easy( /* * Grow the in-inode space. */ - xfs_idata_realloc(dp, xfs_dir2_sf_entsize(mp, sfp, args->namelen), + sfp = xfs_idata_realloc(dp, xfs_dir2_sf_entsize(mp, sfp, args->namelen), XFS_DATA_FORK); /* * Need to set up again due to realloc of the inode data. */ - sfp = dp->i_df.if_data; sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff); /* * Fill in the new entry. @@ -551,11 +550,8 @@ xfs_dir2_sf_addname_hard( * the data. */ xfs_idata_realloc(dp, -old_isize, XFS_DATA_FORK); - xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK); - /* - * Reset the pointer since the buffer was reallocated. - */ - sfp = dp->i_df.if_data; + sfp = xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK); + /* * Copy the first part of the directory, including the header. */ @@ -820,15 +816,13 @@ xfs_dir2_sf_create( ASSERT(dp->i_df.if_bytes == 0); i8count = pino > XFS_DIR2_MAX_SHORT_INUM; size = xfs_dir2_sf_hdr_size(i8count); + /* - * Make a buffer for the data. - */ - xfs_idata_realloc(dp, size, XFS_DATA_FORK); - /* - * Fill in the header, + * Make a buffer for the data and fill in the header. */ - sfp = dp->i_df.if_data; + sfp = xfs_idata_realloc(dp, size, XFS_DATA_FORK); sfp->i8count = i8count; + /* * Now can put in the inode number, since i8count is set. */ @@ -976,11 +970,12 @@ xfs_dir2_sf_removename( */ sfp->count--; dp->i_disk_size = newsize; + /* * Reallocate, making it smaller. */ - xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK); - sfp = dp->i_df.if_data; + sfp = xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK); + /* * Are we changing inode number size? */ diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index fbcda5f54..c95abd43a 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -494,7 +494,7 @@ xfs_iroot_realloc( * byte_diff -- the change in the number of bytes, positive or negative, * requested for the if_data array. */ -void +void * xfs_idata_realloc( struct xfs_inode *ip, int64_t byte_diff, @@ -506,19 +506,15 @@ xfs_idata_realloc( ASSERT(new_size >= 0); ASSERT(new_size <= xfs_inode_fork_size(ip, whichfork)); - if (byte_diff == 0) - return; - - if (new_size == 0) { - kmem_free(ifp->if_data); - ifp->if_data = NULL; - ifp->if_bytes = 0; - return; + if (byte_diff) { + ifp->if_data = krealloc(ifp->if_data, new_size, + GFP_NOFS | __GFP_NOFAIL); + if (new_size == 0) + ifp->if_data = NULL; + ifp->if_bytes = new_size; } - ifp->if_data = krealloc(ifp->if_data, new_size, - GFP_NOFS | __GFP_NOFAIL); - ifp->if_bytes = new_size; + return ifp->if_data; } /* Free all memory and reset a fork back to its initial state. */ diff --git a/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index 7edcf0e8c..96303249d 100644 --- a/libxfs/xfs_inode_fork.h +++ b/libxfs/xfs_inode_fork.h @@ -168,7 +168,7 @@ int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *); void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, struct xfs_inode_log_item *, int); void xfs_idestroy_fork(struct xfs_ifork *ifp); -void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff, +void * xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff, int whichfork); void xfs_iroot_realloc(struct xfs_inode *, int, int); int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int); From patchwork Mon Apr 22 16:26:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638736 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 37B3E153BE1 for ; Mon, 22 Apr 2024 16:40: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=1713804033; cv=none; b=o4k4QnjZSGAU8rgT5P3dCFtoWBI7kXDT+/JJVaNGvZBiph4IojG7j++7bVA9Lzu4AUyY5whHSQqYrHA2qA6jxu+uGA+tSM/jsy5biJ5ne2EiFKLNlTnP7m0fo1cjC5LH6asYv0qWMqthj6qtuW96qLQiRPJm0+eD8nV3ekGk4/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804033; c=relaxed/simple; bh=S0k5fynd21uvt7V2Hhzd+kFXzr16pFilgu8vtJb3/x4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IhW55HEyQpo7SDAZc9oXGe0RCTzB7N6ii1p/5E08Y6jpF6hG4LJOrvizLVyDAbKgB2W1WugYsSMEpSu0hhvxxvFPY9yFopferigCRs8Xj1WKJI1S8U5YCWXR6nXWrHPuAQIFMJp6M8+EA+MpeAN1vhFyy7kB/mMQxUQXaEn4MAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dTbP0o8A; 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="dTbP0o8A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 141DBC116B1; Mon, 22 Apr 2024 16:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804033; bh=S0k5fynd21uvt7V2Hhzd+kFXzr16pFilgu8vtJb3/x4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTbP0o8AxY8Im4w4fnMIb67YBEJ5ukfj394SXcUcXG5eO6hkhCuGCl//3v9ODdei+ 2tENIcEmXM8ulp/tSVV+z8FkDYi7VOWxjxVOin9Pvwyfp96LQGygetBoB6iDEx0QQE anzTNZpMMjVYi0lhJDhCOGTx5lzjyKQeo61Qs/9YiUlCXzJyoq4yUiU9ipAnvNkAbz Vc2Zfp4Sl/Yb6TAW3d6XXghe0pnkAZM1KVf3Qz4WX3ZUpQr9KA3EBqn6UHSFqUarxf NFFXq5E6IwLdHKF7cNFJ3YtfxW45y79hSPWUfHBqv5h8QvEfHUAWXEpDAoh0y9BL7I BFbi3kxjVSMHg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 56/67] xfs: move the xfs_attr_sf_lookup tracepoint Date: Mon, 22 Apr 2024 18:26:18 +0200 Message-ID: <20240422163832.858420-58-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 14f2e4ab5d0310c2bb231941d9884fa5bae47fab trace_xfs_attr_sf_lookup is currently only called by xfs_attr_shortform_lookup, which despit it's name is a simple helper for xfs_attr_shortform_addname, which has it's own tracing. Move the callsite to xfs_attr_shortform_getvalue, which is the closest thing to a high level lookup we have for the Linux xattr API. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr_leaf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index a21740a87..10ed518f3 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -873,8 +873,6 @@ xfs_attr_shortform_lookup( struct xfs_attr_sf_entry *sfe; int i; - trace_xfs_attr_sf_lookup(args); - ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); sfe = &sf->list[0]; for (i = 0; i < sf->hdr.count; @@ -902,6 +900,9 @@ xfs_attr_shortform_getvalue( int i; ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL); + + trace_xfs_attr_sf_lookup(args); + sfe = &sf->list[0]; for (i = 0; i < sf->hdr.count; sfe = xfs_attr_sf_nextentry(sfe), i++) { From patchwork Mon Apr 22 16:26:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638737 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 A5AA8846F for ; Mon, 22 Apr 2024 16:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804034; cv=none; b=Ap+KXAKqarUftH63//264UD2wH9egNtu1S+2EpelRlDc/pXQLcyt/3LJw96RQx25PyH1kTOcq8JzHVLpn9GCbOy+5OYBKbyPapYzjh1SCebuROgXhZcDsBGMdC4nmAO2tY1nD+p8GeKVSrWsHF8bGVGyJMgY8K9ySJrCTQMIdQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804034; c=relaxed/simple; bh=6B9t/pzuM0HyJd03Rxmloqd3SZxzprcoXyUhdg0X0XI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BIDwFra4x2F70sX67yox/byhNyHz2++OzE45l9GgQY2xwNv7pjDazMToywoAXVHKeKFVsqSNciMjgG6M8usyxHWDuQKwJet+QM/f++8XaeZP4v9iLHTRXnWvhK4vX2OR/DjuGO3Q4Pu+9LxcjDcZFTQD8gjfR88XM8qjkBRcQHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wy6T2pBF; 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="Wy6T2pBF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97219C32782; Mon, 22 Apr 2024 16:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804034; bh=6B9t/pzuM0HyJd03Rxmloqd3SZxzprcoXyUhdg0X0XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wy6T2pBFz0T8xsFUev2mkGJnqZ/vNdtZWqCqdpdDwhvSFj3RcgBdKJCnTMRkEYJv9 4e4mQWO9eNgQf5PjMxLmPShbs/RaSmqoPPoBHETLV/VeDGHhK5jPT3o8yor9JzE0qF dw8BsLMDGUqztUq/EOqNKKB50MqlpHcFNizBz+uf9JeLcXkHMRHNcq3LnYNsBTI9Mf wmv32XINHEnis/vr51zP6jBnKIlE2Ir3yXIc8v0C5sKLweZ8yp+7cTXgffY643TBMs QT3G15vSovSqAz9NQ01L2UFuy3xydZLUtcpBbPySsia8iuF07n0TgXNTfuEfMc2k4W tWYj53e6wYjMA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 57/67] xfs: simplify xfs_attr_sf_findname Date: Mon, 22 Apr 2024 18:26:19 +0200 Message-ID: <20240422163832.858420-59-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 6c8d169bbd51fc10d1d0029d495962881315b4c2 xfs_attr_sf_findname has the simple job of finding a xfs_attr_sf_entry in the attr fork, but the convoluted calling convention obfuscates that. Return the found entry as the return value instead of an pointer argument, as the -ENOATTR/-EEXIST can be trivally derived from that, and remove the basep argument, as it is equivalent of the offset of sfe in the data for if an sfe was found, or an offset of totsize if not was found. To simplify the totsize computation add a xfs_attr_sf_endptr helper that returns the imaginative xfs_attr_sf_entry at the end of the current attrs. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr.c | 7 ++- libxfs/xfs_attr_leaf.c | 96 +++++++++++++++--------------------------- libxfs/xfs_attr_leaf.h | 4 +- libxfs/xfs_attr_sf.h | 7 +++ 4 files changed, 48 insertions(+), 66 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index d7512efd4..d5a5ae6e2 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -860,8 +860,11 @@ xfs_attr_lookup( if (!xfs_inode_hasattr(dp)) return -ENOATTR; - if (dp->i_af.if_format == XFS_DINODE_FMT_LOCAL) - return xfs_attr_sf_findname(args, NULL, NULL); + if (dp->i_af.if_format == XFS_DINODE_FMT_LOCAL) { + if (xfs_attr_sf_findname(args)) + return -EEXIST; + return -ENOATTR; + } if (xfs_attr_is_leaf(dp)) { error = xfs_attr_leaf_hasname(args, &bp); diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 10ed518f3..6ea364059 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -695,47 +695,24 @@ xfs_attr_shortform_create( } /* - * Return -EEXIST if attr is found, or -ENOATTR if not - * args: args containing attribute name and namelen - * sfep: If not null, pointer will be set to the last attr entry found on - -EEXIST. On -ENOATTR pointer is left at the last entry in the list - * basep: If not null, pointer is set to the byte offset of the entry in the - * list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of - * the last entry in the list + * Return the entry if the attr in args is found, or NULL if not. */ -int +struct xfs_attr_sf_entry * xfs_attr_sf_findname( - struct xfs_da_args *args, - struct xfs_attr_sf_entry **sfep, - unsigned int *basep) + struct xfs_da_args *args) { - struct xfs_attr_shortform *sf = args->dp->i_af.if_data; - struct xfs_attr_sf_entry *sfe; - unsigned int base = sizeof(struct xfs_attr_sf_hdr); - int size = 0; - int end; - int i; + struct xfs_attr_shortform *sf = args->dp->i_af.if_data; + struct xfs_attr_sf_entry *sfe; - sfe = &sf->list[0]; - end = sf->hdr.count; - for (i = 0; i < end; sfe = xfs_attr_sf_nextentry(sfe), - base += size, i++) { - size = xfs_attr_sf_entsize(sfe); - if (!xfs_attr_match(args, sfe->namelen, sfe->nameval, - sfe->flags)) - continue; - break; + for (sfe = &sf->list[0]; + sfe < xfs_attr_sf_endptr(sf); + sfe = xfs_attr_sf_nextentry(sfe)) { + if (xfs_attr_match(args, sfe->namelen, sfe->nameval, + sfe->flags)) + return sfe; } - if (sfep != NULL) - *sfep = sfe; - - if (basep != NULL) - *basep = base; - - if (i == end) - return -ENOATTR; - return -EEXIST; + return NULL; } /* @@ -752,21 +729,19 @@ xfs_attr_shortform_add( struct xfs_ifork *ifp = &dp->i_af; struct xfs_attr_shortform *sf = ifp->if_data; struct xfs_attr_sf_entry *sfe; - int offset, size; + int size; trace_xfs_attr_sf_add(args); dp->i_forkoff = forkoff; ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - if (xfs_attr_sf_findname(args, &sfe, NULL) == -EEXIST) - ASSERT(0); + ASSERT(!xfs_attr_sf_findname(args)); - offset = (char *)sfe - (char *)sf; size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); sf = xfs_idata_realloc(dp, size, XFS_ATTR_FORK); - sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset); + sfe = xfs_attr_sf_endptr(sf); sfe->namelen = args->namelen; sfe->valuelen = args->valuelen; sfe->flags = args->attr_filter; @@ -806,39 +781,38 @@ xfs_attr_sf_removename( struct xfs_mount *mp = dp->i_mount; struct xfs_attr_shortform *sf = dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; - int size = 0, end, totsize; - unsigned int base; - int error; + uint16_t totsize = be16_to_cpu(sf->hdr.totsize); + void *next, *end; + int size = 0; trace_xfs_attr_sf_remove(args); - error = xfs_attr_sf_findname(args, &sfe, &base); - - /* - * If we are recovering an operation, finding nothing to - * remove is not an error - it just means there was nothing - * to clean up. - */ - if (error == -ENOATTR && (args->op_flags & XFS_DA_OP_RECOVERY)) - return 0; - if (error != -EEXIST) - return error; - size = xfs_attr_sf_entsize(sfe); + sfe = xfs_attr_sf_findname(args); + if (!sfe) { + /* + * If we are recovering an operation, finding nothing to remove + * is not an error, it just means there was nothing to clean up. + */ + if (args->op_flags & XFS_DA_OP_RECOVERY) + return 0; + return -ENOATTR; + } /* * Fix up the attribute fork data, covering the hole */ - end = base + size; - totsize = be16_to_cpu(sf->hdr.totsize); - if (end != totsize) - memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end); + size = xfs_attr_sf_entsize(sfe); + next = xfs_attr_sf_nextentry(sfe); + end = xfs_attr_sf_endptr(sf); + if (next < end) + memmove(sfe, next, end - next); sf->hdr.count--; - be16_add_cpu(&sf->hdr.totsize, -size); + totsize -= size; + sf->hdr.totsize = cpu_to_be16(totsize); /* * Fix up the start offset of the attribute fork */ - totsize -= size; if (totsize == sizeof(xfs_attr_sf_hdr_t) && xfs_has_attr2(mp) && (dp->i_df.if_format != XFS_DINODE_FMT_BTREE) && !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE))) { diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h index ce6743463..56fcd689e 100644 --- a/libxfs/xfs_attr_leaf.h +++ b/libxfs/xfs_attr_leaf.h @@ -51,9 +51,7 @@ int xfs_attr_shortform_lookup(struct xfs_da_args *args); int xfs_attr_shortform_getvalue(struct xfs_da_args *args); int xfs_attr_shortform_to_leaf(struct xfs_da_args *args); int xfs_attr_sf_removename(struct xfs_da_args *args); -int xfs_attr_sf_findname(struct xfs_da_args *args, - struct xfs_attr_sf_entry **sfep, - unsigned int *basep); +struct xfs_attr_sf_entry *xfs_attr_sf_findname(struct xfs_da_args *args); int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp); int xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes); xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp, diff --git a/libxfs/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h index 37578b369..a774d4d87 100644 --- a/libxfs/xfs_attr_sf.h +++ b/libxfs/xfs_attr_sf.h @@ -48,4 +48,11 @@ xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep) return (void *)sfep + xfs_attr_sf_entsize(sfep); } +/* pointer to the space after the last entry, e.g. for adding a new one */ +static inline struct xfs_attr_sf_entry * +xfs_attr_sf_endptr(struct xfs_attr_shortform *sf) +{ + return (void *)sf + be16_to_cpu(sf->hdr.totsize); +} + #endif /* __XFS_ATTR_SF_H__ */ From patchwork Mon Apr 22 16:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638738 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 1F389846F for ; Mon, 22 Apr 2024 16:40: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=1713804036; cv=none; b=OJ8qVKDqgbqqx1XsuTwJgK2CdUkQ760fdUr7bavrjyBc1mN5VUEhIUnEcMEwV4pzFRTuKv4WefcQeOtuI6SXQ/RgR1qjzAVz9hrSVx3byxt4WwD9OAnIa4yqeXtEsSVYY+mAYwOspK0OFat6GZlS6UGpAQNJH6GtlhNpOIVjavc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804036; c=relaxed/simple; bh=v8tflW5pRmo4mktX0td1SaMPWikCVb3ejTJ4YaGdJUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IOmyyqTkCJZx5gtDbyOVJF0EZz5dQHxzOHJNf9d7iWb4KDNz0rq0rFDW5biWjACUdEJFYR2pzw4NGySeE0itZC2uCBnoipUGx1V6EwyqS3IG2OqIg+gchbo22KoAohbJYbVcRJYevJOSay0q/hojgjDI3diil5vk333NNc1of00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hH0NyRDk; 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="hH0NyRDk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CA64C113CC; Mon, 22 Apr 2024 16:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804036; bh=v8tflW5pRmo4mktX0td1SaMPWikCVb3ejTJ4YaGdJUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hH0NyRDkG7eazDQXdQSAc68DJKkU0+cOQxyH0lMZlIiJzZoLA0W7LHtjOinD5nMMH 90n6+tNmQjS+rJdtjV7UiThpXZnZunnpKOZIbwe/gQUbMUdMx1M1L7Y9Zb+/qz5dju A5CKgPOmdLV5zDm5vFqOIAY5Dqsu9wk2EqUWghIgyGNsFXLpQCWgpee57LJbwl3DZv xlmQRjUQc5d3YD9zBBKT6vx/bkyTwXHcxOnw0avDk6shMnCNWv/F5ufJCjYl6oHCOe VzDXtt4JwvoKFF4lUkCwMLM2ZJIP9mo3eYn3eE+kxVtoROCXql9skrwBjZSBtxvkEI Y8tHCEv8rSMaw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 58/67] xfs: remove xfs_attr_shortform_lookup Date: Mon, 22 Apr 2024 18:26:20 +0200 Message-ID: <20240422163832.858420-60-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 22b7b1f597a6a21fb7b3791a55f3a7ae54d2dfe4 xfs_attr_shortform_lookup is only used by xfs_attr_shortform_addname, which is much better served by calling xfs_attr_sf_findname. Switch it over and remove xfs_attr_shortform_lookup. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr.c | 21 +++++++-------------- libxfs/xfs_attr_leaf.c | 24 ------------------------ libxfs/xfs_attr_leaf.h | 1 - 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index d5a5ae6e2..a383024db 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1064,19 +1064,14 @@ xfs_attr_shortform_addname( struct xfs_da_args *args) { int newsize, forkoff; - int error; trace_xfs_attr_sf_addname(args); - error = xfs_attr_shortform_lookup(args); - switch (error) { - case -ENOATTR: - if (args->op_flags & XFS_DA_OP_REPLACE) - return error; - break; - case -EEXIST: + if (xfs_attr_sf_findname(args)) { + int error; + if (!(args->op_flags & XFS_DA_OP_REPLACE)) - return error; + return -EEXIST; error = xfs_attr_sf_removename(args); if (error) @@ -1089,11 +1084,9 @@ xfs_attr_shortform_addname( * around. */ args->op_flags &= ~XFS_DA_OP_REPLACE; - break; - case 0: - break; - default: - return error; + } else { + if (args->op_flags & XFS_DA_OP_REPLACE) + return -ENOATTR; } if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX || diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 6ea364059..8f1678d29 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -834,30 +834,6 @@ xfs_attr_sf_removename( return 0; } -/* - * Look up a name in a shortform attribute list structure. - */ -/*ARGSUSED*/ -int -xfs_attr_shortform_lookup( - struct xfs_da_args *args) -{ - struct xfs_ifork *ifp = &args->dp->i_af; - struct xfs_attr_shortform *sf = ifp->if_data; - struct xfs_attr_sf_entry *sfe; - int i; - - ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - sfe = &sf->list[0]; - for (i = 0; i < sf->hdr.count; - sfe = xfs_attr_sf_nextentry(sfe), i++) { - if (xfs_attr_match(args, sfe->namelen, sfe->nameval, - sfe->flags)) - return -EEXIST; - } - return -ENOATTR; -} - /* * Retrieve the attribute value and length. * diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h index 56fcd689e..35e668ae7 100644 --- a/libxfs/xfs_attr_leaf.h +++ b/libxfs/xfs_attr_leaf.h @@ -47,7 +47,6 @@ struct xfs_attr3_icleaf_hdr { */ void xfs_attr_shortform_create(struct xfs_da_args *args); void xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff); -int xfs_attr_shortform_lookup(struct xfs_da_args *args); int xfs_attr_shortform_getvalue(struct xfs_da_args *args); int xfs_attr_shortform_to_leaf(struct xfs_da_args *args); int xfs_attr_sf_removename(struct xfs_da_args *args); From patchwork Mon Apr 22 16:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638739 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 A8BBC15381B for ; Mon, 22 Apr 2024 16:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804037; cv=none; b=R8yPPh1TahpHf/G+KV1mfEdyqFCEqNiSz6jWeaSBQ35T4OzSJ95T5j0FzICfGBfNRyTGgZXIw2XvS03Rdrl5hUNNu92EphhVMcWfNDUURegkwjQlCSYV50Krp/ctD6eJLU8Fh3mG/rjMvUgyAaOik4w9hMlUYX4yVMb/WZZBvs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804037; c=relaxed/simple; bh=oF03DLwISG1prDAiIQXsFBh/32NfQqJDWtv8zvjnMj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uI0sOKbwFCu0ljMPAr6dMqw1KOUzO38KN1X8XMaVJg8qJjTCejqls5e+ASR6mSksNyiXZG2wHUj/vvSPzNwY/qtgAwPaC704Ey4NPHFcXm1CwbxxGrYV9SxuxH5MzERl/ODRQYNGPUfC0s5R6IO0j2njYt+67d7KqaSQMqL+Zbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vCFBZPA7; 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="vCFBZPA7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F881C113CC; Mon, 22 Apr 2024 16:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804037; bh=oF03DLwISG1prDAiIQXsFBh/32NfQqJDWtv8zvjnMj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vCFBZPA7w9hHt+a4Pes2TYjqfsqlK7r3wn+dxAUZTZzsOZQv5oR2qEskxDejhLXiN AD4rDGIWjfaHY5c/DQud4COvs9CNM9PxZGiIc+yx6OJyrLq2zrLugL4ftR5TY4rXGS 7clBxw331Gs++zsCVz5uZ/0hwM1o/uRLuKnm+hf2t0IBJuZxPW1iiST7d9cKFkGX0t +ByEFHgvFVg1vBnnAzvrB0FZo88fiQQcLba20RjdIMcJYXsTGrzE5kZCcOfum2z7ED MUlALE5sD77mk8FQdo5YNMyT2HYIVLLKZUw9zS5YO9kHVAyvuJsVrLu4cMdcoQ4rEi 8b3rUqwzU2sCQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 59/67] xfs: use xfs_attr_sf_findname in xfs_attr_shortform_getvalue Date: Mon, 22 Apr 2024 18:26:21 +0200 Message-ID: <20240422163832.858420-61-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 1fb4b0def7b5a5bf91ad62a112d8d3f6dc76585f xfs_attr_shortform_getvalue duplicates the logic in xfs_attr_sf_findname. Use the helper instead. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr_leaf.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 8f1678d29..9b6dcff34 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -845,23 +845,17 @@ int xfs_attr_shortform_getvalue( struct xfs_da_args *args) { - struct xfs_attr_shortform *sf = args->dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; - int i; ASSERT(args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL); trace_xfs_attr_sf_lookup(args); - sfe = &sf->list[0]; - for (i = 0; i < sf->hdr.count; - sfe = xfs_attr_sf_nextentry(sfe), i++) { - if (xfs_attr_match(args, sfe->namelen, sfe->nameval, - sfe->flags)) - return xfs_attr_copy_value(args, - &sfe->nameval[args->namelen], sfe->valuelen); - } - return -ENOATTR; + sfe = xfs_attr_sf_findname(args); + if (!sfe) + return -ENOATTR; + return xfs_attr_copy_value(args, &sfe->nameval[args->namelen], + sfe->valuelen); } /* Convert from using the shortform to the leaf format. */ From patchwork Mon Apr 22 16:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638740 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 3FCAD15381B for ; Mon, 22 Apr 2024 16:40: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=1713804039; cv=none; b=OB/ttxG8YORd+5qVSneCZfCmifl51YqnknzTZ+tySEjV3VvVZIRqkfX3jO//2Yctd46M6fMZdIaJ7FCCsjN2Cw4e2t07e+PFgbRYqRM58z/GIpvppY5tG5ss9riogQ8JllIo52CMJJ5W0PvMDBpZkxafyNVYAbM05aGn4ssNLMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804039; c=relaxed/simple; bh=DN07br84uLPKft20MfoE9108nOqSODblBJEdljh2X/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXdUWt+rkjK/Y73xClsNl1symfOxhqBqRWZgq0SI64pvGzYblNgKsbVkS+4b7Upq6pRpHlEvYFHhlD1aOzZREuh5kNLHFKyo4X4kRWV5WdD4ocg9YF2id/hMiOihFU2SI1HVda6kM52x6VHI0HuwgzSiabYyZuJv+ZBABCFMU7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nfks2ktk; 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="nfks2ktk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E2A2C32781; Mon, 22 Apr 2024 16:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804039; bh=DN07br84uLPKft20MfoE9108nOqSODblBJEdljh2X/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nfks2ktkG+mgsfZ1cejp54ZVqftWmPEc4X++ZpnGXLzjtGk2SraKWUQMjEuo9b/FT dSWwLjAmXKaGGc/k/Fg45Uky9LVWmvantejOwito640685WNdL2SMfXOA+FPd9M7kY JoVHMHLUH/tZE/y35csLSG3a6au3fS/o/dYvwsKyKS1quou3fIY/+7Yul4c3hzTWdJ o+cdAeezjNRCmJe6/rGaEhJcHyx20q4YlC4DOjHEdnZeM1lPlycAFxNga8rpRbqN8a W+QzSjz0vP6bzF4J3pnfb+LAENwyAoZJN3M7KTugQhOUA3A+INtMuAx3ljRxayUFGi WR9xuDWLC/KZQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 60/67] xfs: remove struct xfs_attr_shortform Date: Mon, 22 Apr 2024 18:26:22 +0200 Message-ID: <20240422163832.858420-62-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 414147225400a0c4562ebfb0fdd40f065099ede4 sparse complains about struct xfs_attr_shortform because it embeds a structure with a variable sized array in a variable sized array. Given that xfs_attr_shortform is not a very useful structure, and the dir2 equivalent has been removed a long time ago, remove it as well. Provide a xfs_attr_sf_firstentry helper that returns the first xfs_attr_sf_entry behind a xfs_attr_sf_hdr to replace the structure dereference. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- db/attrshort.c | 33 +++++++++++++++--------------- db/check.c | 8 ++++---- db/inode.c | 6 +++--- db/metadump.c | 16 +++++++-------- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_attr.c | 4 ++-- libxfs/xfs_attr_leaf.c | 37 +++++++++++++++++----------------- libxfs/xfs_attr_leaf.h | 2 +- libxfs/xfs_attr_sf.h | 13 +++++++++--- libxfs/xfs_da_format.h | 33 +++++++++++++++++------------- libxfs/xfs_inode_fork.c | 5 ++--- libxfs/xfs_ondisk.h | 14 ++++++------- repair/attr_repair.c | 43 ++++++++++++++++++++-------------------- repair/dinode.c | 21 ++++++++++---------- 14 files changed, 121 insertions(+), 115 deletions(-) diff --git a/db/attrshort.c b/db/attrshort.c index e234fbd83..c98b90be3 100644 --- a/db/attrshort.c +++ b/db/attrshort.c @@ -18,9 +18,8 @@ static int attr_sf_entry_value_offset(void *obj, int startoff, int idx); static int attr_shortform_list_count(void *obj, int startoff); static int attr_shortform_list_offset(void *obj, int startoff, int idx); -#define OFF(f) bitize(offsetof(struct xfs_attr_shortform, f)) const field_t attr_shortform_flds[] = { - { "hdr", FLDT_ATTR_SF_HDR, OI(OFF(hdr)), C1, 0, TYP_NONE }, + { "hdr", FLDT_ATTR_SF_HDR, OI(0), C1, 0, TYP_NONE }, { "list", FLDT_ATTR_SF_ENTRY, attr_shortform_list_offset, attr_shortform_list_count, FLD_ARRAY|FLD_COUNT|FLD_OFFSET, TYP_NONE }, { NULL } @@ -71,11 +70,11 @@ attr_sf_entry_size( { struct xfs_attr_sf_entry *e; int i; - struct xfs_attr_shortform *sf; + struct xfs_attr_sf_hdr *hdr; ASSERT(bitoffs(startoff) == 0); - sf = (struct xfs_attr_shortform *)((char *)obj + byteize(startoff)); - e = &sf->list[0]; + hdr = (struct xfs_attr_sf_hdr *)((char *)obj + byteize(startoff)); + e = libxfs_attr_sf_firstentry(hdr); for (i = 0; i < idx; i++) e = xfs_attr_sf_nextentry(e); return bitize((int)xfs_attr_sf_entsize(e)); @@ -113,11 +112,11 @@ attr_shortform_list_count( void *obj, int startoff) { - struct xfs_attr_shortform *sf; + struct xfs_attr_sf_hdr *hdr; ASSERT(bitoffs(startoff) == 0); - sf = (struct xfs_attr_shortform *)((char *)obj + byteize(startoff)); - return sf->hdr.count; + hdr = (struct xfs_attr_sf_hdr *)((char *)obj + byteize(startoff)); + return hdr->count; } static int @@ -128,14 +127,14 @@ attr_shortform_list_offset( { struct xfs_attr_sf_entry *e; int i; - struct xfs_attr_shortform *sf; + struct xfs_attr_sf_hdr *hdr; ASSERT(bitoffs(startoff) == 0); - sf = (struct xfs_attr_shortform *)((char *)obj + byteize(startoff)); - e = &sf->list[0]; + hdr = (struct xfs_attr_sf_hdr *)((char *)obj + byteize(startoff)); + e = libxfs_attr_sf_firstentry(hdr); for (i = 0; i < idx; i++) e = xfs_attr_sf_nextentry(e); - return bitize((int)((char *)e - (char *)sf)); + return bitize((int)((char *)e - (char *)hdr)); } /*ARGSUSED*/ @@ -147,13 +146,13 @@ attrshort_size( { struct xfs_attr_sf_entry *e; int i; - struct xfs_attr_shortform *sf; + struct xfs_attr_sf_hdr *hdr; ASSERT(bitoffs(startoff) == 0); ASSERT(idx == 0); - sf = (struct xfs_attr_shortform *)((char *)obj + byteize(startoff)); - e = &sf->list[0]; - for (i = 0; i < sf->hdr.count; i++) + hdr = (struct xfs_attr_sf_hdr *)((char *)obj + byteize(startoff)); + e = libxfs_attr_sf_firstentry(hdr); + for (i = 0; i < hdr->count; i++) e = xfs_attr_sf_nextentry(e); - return bitize((int)((char *)e - (char *)sf)); + return bitize((int)((char *)e - (char *)hdr)); } diff --git a/db/check.c b/db/check.c index 36d82af0a..c29c661b7 100644 --- a/db/check.c +++ b/db/check.c @@ -3055,7 +3055,7 @@ process_lclinode( blkmap_t **blkmapp, int whichfork) { - struct xfs_attr_shortform *asf; + struct xfs_attr_sf_hdr *hdr; xfs_fsblock_t bno; bno = XFS_INO_TO_FSB(mp, id->ino); @@ -3068,12 +3068,12 @@ process_lclinode( error++; } else if (whichfork == XFS_ATTR_FORK) { - asf = (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip); - if (be16_to_cpu(asf->hdr.totsize) > XFS_DFORK_ASIZE(dip, mp)) { + hdr = XFS_DFORK_APTR(dip); + if (be16_to_cpu(hdr->totsize) > XFS_DFORK_ASIZE(dip, mp)) { if (!sflag || id->ilist || CHECK_BLIST(bno)) dbprintf(_("local inode %lld attr is too large " "(size %d)\n"), - id->ino, be16_to_cpu(asf->hdr.totsize)); + id->ino, be16_to_cpu(hdr->totsize)); error++; } } diff --git a/db/inode.c b/db/inode.c index c9b506b90..d5e4be0ad 100644 --- a/db/inode.c +++ b/db/inode.c @@ -356,7 +356,7 @@ inode_a_size( int startoff, int idx) { - struct xfs_attr_shortform *asf; + struct xfs_attr_sf_hdr *hdr; struct xfs_dinode *dip; ASSERT(startoff == 0); @@ -364,8 +364,8 @@ inode_a_size( dip = obj; switch (dip->di_aformat) { case XFS_DINODE_FMT_LOCAL: - asf = (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip); - return bitize(be16_to_cpu(asf->hdr.totsize)); + hdr = (struct xfs_attr_sf_hdr *)XFS_DFORK_APTR(dip); + return bitize(be16_to_cpu(hdr->totsize)); case XFS_DINODE_FMT_EXTENTS: return (int)xfs_dfork_attr_extents(dip) * bitsz(xfs_bmbt_rec_t); case XFS_DINODE_FMT_BTREE: diff --git a/db/metadump.c b/db/metadump.c index bac35b9cc..536d089fb 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -1035,16 +1035,15 @@ process_sf_attr( * values with 'v' (to see a valid string length, as opposed to NULLs) */ - struct xfs_attr_shortform *asfp; - struct xfs_attr_sf_entry *asfep; + struct xfs_attr_sf_hdr *hdr = XFS_DFORK_APTR(dip); + struct xfs_attr_sf_entry *asfep = libxfs_attr_sf_firstentry(hdr); int ino_attr_size; int i; - asfp = (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip); - if (asfp->hdr.count == 0) + if (hdr->count == 0) return; - ino_attr_size = be16_to_cpu(asfp->hdr.totsize); + ino_attr_size = be16_to_cpu(hdr->totsize); if (ino_attr_size > XFS_DFORK_ASIZE(dip, mp)) { ino_attr_size = XFS_DFORK_ASIZE(dip, mp); if (metadump.show_warnings) @@ -1052,9 +1051,8 @@ process_sf_attr( (long long)metadump.cur_ino); } - asfep = &asfp->list[0]; - for (i = 0; (i < asfp->hdr.count) && - ((char *)asfep - (char *)asfp < ino_attr_size); i++) { + for (i = 0; (i < hdr->count) && + ((char *)asfep - (char *)hdr < ino_attr_size); i++) { int namelen = asfep->namelen; @@ -1063,7 +1061,7 @@ process_sf_attr( print_warning("zero length attr entry in inode " "%llu", (long long)metadump.cur_ino); break; - } else if ((char *)asfep - (char *)asfp + + } else if ((char *)asfep - (char *)hdr + xfs_attr_sf_entsize(asfep) > ino_attr_size) { if (metadump.show_warnings) print_warning("attr entry length in inode %llu " diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 4edc8a7e1..c38ccc5f8 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -40,6 +40,7 @@ #define xfs_attr_leaf_newentsize libxfs_attr_leaf_newentsize #define xfs_attr_namecheck libxfs_attr_namecheck #define xfs_attr_set libxfs_attr_set +#define xfs_attr_sf_firstentry libxfs_attr_sf_firstentry #define __xfs_bmap_add_free __libxfs_bmap_add_free #define xfs_bmapi_read libxfs_bmapi_read diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index a383024db..055d20410 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1050,9 +1050,9 @@ out_trans_cancel: static inline int xfs_attr_sf_totsize(struct xfs_inode *dp) { - struct xfs_attr_shortform *sf = dp->i_af.if_data; + struct xfs_attr_sf_hdr *sf = dp->i_af.if_data; - return be16_to_cpu(sf->hdr.totsize); + return be16_to_cpu(sf->totsize); } /* diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 9b6dcff34..cf172b6ea 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -701,10 +701,10 @@ struct xfs_attr_sf_entry * xfs_attr_sf_findname( struct xfs_da_args *args) { - struct xfs_attr_shortform *sf = args->dp->i_af.if_data; + struct xfs_attr_sf_hdr *sf = args->dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; - for (sfe = &sf->list[0]; + for (sfe = xfs_attr_sf_firstentry(sf); sfe < xfs_attr_sf_endptr(sf); sfe = xfs_attr_sf_nextentry(sfe)) { if (xfs_attr_match(args, sfe->namelen, sfe->nameval, @@ -727,7 +727,7 @@ xfs_attr_shortform_add( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_ifork *ifp = &dp->i_af; - struct xfs_attr_shortform *sf = ifp->if_data; + struct xfs_attr_sf_hdr *sf = ifp->if_data; struct xfs_attr_sf_entry *sfe; int size; @@ -747,8 +747,8 @@ xfs_attr_shortform_add( sfe->flags = args->attr_filter; memcpy(sfe->nameval, args->name, args->namelen); memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen); - sf->hdr.count++; - be16_add_cpu(&sf->hdr.totsize, size); + sf->count++; + be16_add_cpu(&sf->totsize, size); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); xfs_sbversion_add_attr2(mp, args->trans); @@ -779,9 +779,9 @@ xfs_attr_sf_removename( { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; - struct xfs_attr_shortform *sf = dp->i_af.if_data; + struct xfs_attr_sf_hdr *sf = dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; - uint16_t totsize = be16_to_cpu(sf->hdr.totsize); + uint16_t totsize = be16_to_cpu(sf->totsize); void *next, *end; int size = 0; @@ -806,9 +806,9 @@ xfs_attr_sf_removename( end = xfs_attr_sf_endptr(sf); if (next < end) memmove(sfe, next, end - next); - sf->hdr.count--; + sf->count--; totsize -= size; - sf->hdr.totsize = cpu_to_be16(totsize); + sf->totsize = cpu_to_be16(totsize); /* * Fix up the start offset of the attribute fork @@ -865,21 +865,21 @@ xfs_attr_shortform_to_leaf( { struct xfs_inode *dp = args->dp; struct xfs_ifork *ifp = &dp->i_af; - struct xfs_attr_shortform *sf = ifp->if_data; + struct xfs_attr_sf_hdr *sf = ifp->if_data; struct xfs_attr_sf_entry *sfe; + int size = be16_to_cpu(sf->totsize); struct xfs_da_args nargs; char *tmpbuffer; - int error, i, size; + int error, i; xfs_dablk_t blkno; struct xfs_buf *bp; trace_xfs_attr_sf_to_leaf(args); - size = be16_to_cpu(sf->hdr.totsize); tmpbuffer = kmem_alloc(size, 0); ASSERT(tmpbuffer != NULL); memcpy(tmpbuffer, ifp->if_data, size); - sf = (struct xfs_attr_shortform *)tmpbuffer; + sf = (struct xfs_attr_sf_hdr *)tmpbuffer; xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK); @@ -902,8 +902,8 @@ xfs_attr_shortform_to_leaf( nargs.trans = args->trans; nargs.op_flags = XFS_DA_OP_OKNOENT; - sfe = &sf->list[0]; - for (i = 0; i < sf->hdr.count; i++) { + sfe = xfs_attr_sf_firstentry(sf); + for (i = 0; i < sf->count; i++) { nargs.name = sfe->nameval; nargs.namelen = sfe->namelen; nargs.value = &sfe->nameval[nargs.namelen]; @@ -970,10 +970,10 @@ xfs_attr_shortform_allfit( /* Verify the consistency of a raw inline attribute fork. */ xfs_failaddr_t xfs_attr_shortform_verify( - struct xfs_attr_shortform *sfp, + struct xfs_attr_sf_hdr *sfp, size_t size) { - struct xfs_attr_sf_entry *sfep; + struct xfs_attr_sf_entry *sfep = xfs_attr_sf_firstentry(sfp); struct xfs_attr_sf_entry *next_sfep; char *endp; int i; @@ -987,8 +987,7 @@ xfs_attr_shortform_verify( endp = (char *)sfp + size; /* Check all reported entries */ - sfep = &sfp->list[0]; - for (i = 0; i < sfp->hdr.count; i++) { + for (i = 0; i < sfp->count; i++) { /* * struct xfs_attr_sf_entry has a variable length. * Check the fixed-offset parts of the structure are diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h index 35e668ae7..9b9948639 100644 --- a/libxfs/xfs_attr_leaf.h +++ b/libxfs/xfs_attr_leaf.h @@ -53,7 +53,7 @@ int xfs_attr_sf_removename(struct xfs_da_args *args); struct xfs_attr_sf_entry *xfs_attr_sf_findname(struct xfs_da_args *args); int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp); int xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes); -xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp, +xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_sf_hdr *sfp, size_t size); void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp); diff --git a/libxfs/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h index a774d4d87..9abf7de95 100644 --- a/libxfs/xfs_attr_sf.h +++ b/libxfs/xfs_attr_sf.h @@ -41,7 +41,14 @@ static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep) return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen); } -/* next entry in struct */ +/* first entry in the SF attr fork */ +static inline struct xfs_attr_sf_entry * +xfs_attr_sf_firstentry(struct xfs_attr_sf_hdr *hdr) +{ + return (struct xfs_attr_sf_entry *)(hdr + 1); +} + +/* next entry after sfep */ static inline struct xfs_attr_sf_entry * xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep) { @@ -50,9 +57,9 @@ xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep) /* pointer to the space after the last entry, e.g. for adding a new one */ static inline struct xfs_attr_sf_entry * -xfs_attr_sf_endptr(struct xfs_attr_shortform *sf) +xfs_attr_sf_endptr(struct xfs_attr_sf_hdr *sf) { - return (void *)sf + be16_to_cpu(sf->hdr.totsize); + return (void *)sf + be16_to_cpu(sf->totsize); } #endif /* __XFS_ATTR_SF_H__ */ diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index f9015f88e..24f9d1461 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -578,20 +578,25 @@ xfs_dir2_block_leaf_p(struct xfs_dir2_block_tail *btp) #define XFS_ATTR_LEAF_MAPSIZE 3 /* how many freespace slots */ /* - * Entries are packed toward the top as tight as possible. - */ -struct xfs_attr_shortform { - struct xfs_attr_sf_hdr { /* constant-structure header block */ - __be16 totsize; /* total bytes in shortform list */ - __u8 count; /* count of active entries */ - __u8 padding; - } hdr; - struct xfs_attr_sf_entry { - uint8_t namelen; /* actual length of name (no NULL) */ - uint8_t valuelen; /* actual length of value (no NULL) */ - uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ - uint8_t nameval[]; /* name & value bytes concatenated */ - } list[]; /* variable sized array */ + * Attribute storage when stored inside the inode. + * + * Small attribute lists are packed as tightly as possible so as to fit into the + * literal area of the inode. + * + * These "shortform" attribute forks consist of a single xfs_attr_sf_hdr header + * followed by zero or more xfs_attr_sf_entry structures. + */ +struct xfs_attr_sf_hdr { /* constant-structure header block */ + __be16 totsize; /* total bytes in shortform list */ + __u8 count; /* count of active entries */ + __u8 padding; +}; + +struct xfs_attr_sf_entry { + __u8 namelen; /* actual length of name (no NULL) */ + __u8 valuelen; /* actual length of value (no NULL) */ + __u8 flags; /* flags bits (XFS_ATTR_*) */ + __u8 nameval[]; /* name & value bytes concatenated */ }; typedef struct xfs_attr_leaf_map { /* RLE map of free bytes */ diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index c95abd43a..208b283ba 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -277,10 +277,9 @@ static uint16_t xfs_dfork_attr_shortform_size( struct xfs_dinode *dip) { - struct xfs_attr_shortform *atp = - (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip); + struct xfs_attr_sf_hdr *sf = XFS_DFORK_APTR(dip); - return be16_to_cpu(atp->hdr.totsize); + return be16_to_cpu(sf->totsize); } void diff --git a/libxfs/xfs_ondisk.h b/libxfs/xfs_ondisk.h index d9c988c5a..81885a6a0 100644 --- a/libxfs/xfs_ondisk.h +++ b/libxfs/xfs_ondisk.h @@ -93,13 +93,13 @@ xfs_check_ondisk_structs(void) XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, namelen, 8); XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, name, 9); XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t, 32); - XFS_CHECK_STRUCT_SIZE(struct xfs_attr_shortform, 4); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.totsize, 0); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.count, 2); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].namelen, 4); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].valuelen, 5); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].flags, 6); - XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].nameval, 7); + XFS_CHECK_STRUCT_SIZE(struct xfs_attr_sf_hdr, 4); + XFS_CHECK_OFFSET(struct xfs_attr_sf_hdr, totsize, 0); + XFS_CHECK_OFFSET(struct xfs_attr_sf_hdr, count, 2); + XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, namelen, 0); + XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, valuelen, 1); + XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, flags, 2); + XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, nameval, 3); XFS_CHECK_STRUCT_SIZE(xfs_da_blkinfo_t, 12); XFS_CHECK_STRUCT_SIZE(xfs_da_intnode_t, 16); XFS_CHECK_STRUCT_SIZE(xfs_da_node_entry_t, 8); diff --git a/repair/attr_repair.c b/repair/attr_repair.c index c3a6d5026..b65b28a20 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -210,27 +210,27 @@ process_shortform_attr( struct xfs_dinode *dip, int *repair) { - struct xfs_attr_shortform *asf; + struct xfs_attr_sf_hdr *hdr; struct xfs_attr_sf_entry *currententry, *nextentry, *tempentry; int i, junkit; int currentsize, remainingspace; *repair = 0; - asf = (struct xfs_attr_shortform *) XFS_DFORK_APTR(dip); + hdr = XFS_DFORK_APTR(dip); /* Assumption: hdr.totsize is less than a leaf block and was checked * by lclinode for valid sizes. Check the count though. */ - if (asf->hdr.count == 0) + if (hdr->count == 0) /* then the total size should just be the header length */ - if (be16_to_cpu(asf->hdr.totsize) != sizeof(xfs_attr_sf_hdr_t)) { + if (be16_to_cpu(hdr->totsize) != sizeof(xfs_attr_sf_hdr_t)) { /* whoops there's a discrepancy. Clear the hdr */ if (!no_modify) { do_warn( _("there are no attributes in the fork for inode %" PRIu64 "\n"), ino); - asf->hdr.totsize = + hdr->totsize = cpu_to_be16(sizeof(xfs_attr_sf_hdr_t)); *repair = 1; return(1); @@ -243,15 +243,15 @@ process_shortform_attr( } currentsize = sizeof(xfs_attr_sf_hdr_t); - remainingspace = be16_to_cpu(asf->hdr.totsize) - currentsize; - nextentry = &asf->list[0]; - for (i = 0; i < asf->hdr.count; i++) { + remainingspace = be16_to_cpu(hdr->totsize) - currentsize; + nextentry = libxfs_attr_sf_firstentry(hdr); + for (i = 0; i < hdr->count; i++) { currententry = nextentry; junkit = 0; /* don't go off the end if the hdr.count was off */ if ((currentsize + (sizeof(struct xfs_attr_sf_entry) - 1)) > - be16_to_cpu(asf->hdr.totsize)) + be16_to_cpu(hdr->totsize)) break; /* get out and reset count and totSize */ /* if the namelen is 0, can't get to the rest of the entries */ @@ -326,7 +326,7 @@ process_shortform_attr( ((intptr_t) currententry + xfs_attr_sf_entsize(currententry)); memmove(currententry,tempentry,remainingspace); - asf->hdr.count -= 1; + hdr->count -= 1; i--; /* no worries, it will wrap back to 0 */ *repair = 1; continue; /* go back up now */ @@ -344,33 +344,33 @@ process_shortform_attr( } /* end the loop */ - if (asf->hdr.count != i) { + if (hdr->count != i) { if (no_modify) { do_warn( _("would have corrected attribute entry count in inode %" PRIu64 " from %d to %d\n"), - ino, asf->hdr.count, i); + ino, hdr->count, i); } else { do_warn( _("corrected attribute entry count in inode %" PRIu64 ", was %d, now %d\n"), - ino, asf->hdr.count, i); - asf->hdr.count = i; + ino, hdr->count, i); + hdr->count = i; *repair = 1; } } /* ASSUMPTION: currentsize <= totsize */ - if (be16_to_cpu(asf->hdr.totsize) != currentsize) { + if (be16_to_cpu(hdr->totsize) != currentsize) { if (no_modify) { do_warn( _("would have corrected attribute totsize in inode %" PRIu64 " from %d to %d\n"), - ino, be16_to_cpu(asf->hdr.totsize), + ino, be16_to_cpu(hdr->totsize), currentsize); } else { do_warn( _("corrected attribute entry totsize in inode %" PRIu64 ", was %d, now %d\n"), - ino, be16_to_cpu(asf->hdr.totsize), + ino, be16_to_cpu(hdr->totsize), currentsize); - asf->hdr.totsize = cpu_to_be16(currentsize); + hdr->totsize = cpu_to_be16(currentsize); *repair = 1; } } @@ -1232,14 +1232,13 @@ process_attributes( int err; __u8 aformat = dip->di_aformat; #ifdef DEBUG - struct xfs_attr_shortform *asf; + struct xfs_attr_sf_hdr *hdr; - asf = (struct xfs_attr_shortform *) XFS_DFORK_APTR(dip); + hdr = XFS_DFORK_APTR(dip); #endif if (aformat == XFS_DINODE_FMT_LOCAL) { - ASSERT(be16_to_cpu(asf->hdr.totsize) <= - XFS_DFORK_ASIZE(dip, mp)); + ASSERT(be16_to_cpu(hdr->totsize) <= XFS_DFORK_ASIZE(dip, mp)); err = process_shortform_attr(mp, ino, dip, repair); } else if (aformat == XFS_DINODE_FMT_EXTENTS || aformat == XFS_DINODE_FMT_BTREE) { diff --git a/repair/dinode.c b/repair/dinode.c index c10dd1fa3..f4398c0df 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -99,11 +99,10 @@ _("would have cleared inode %" PRIu64 " attributes\n"), ino_num); */ if (!no_modify) { - struct xfs_attr_shortform *asf = (struct xfs_attr_shortform *) - XFS_DFORK_APTR(dino); - asf->hdr.totsize = cpu_to_be16(sizeof(xfs_attr_sf_hdr_t)); - asf->hdr.count = 0; - dino->di_forkoff = 0; /* got to do this after asf is set */ + struct xfs_attr_sf_hdr *hdr = XFS_DFORK_APTR(dino); + hdr->totsize = cpu_to_be16(sizeof(xfs_attr_sf_hdr_t)); + hdr->count = 0; + dino->di_forkoff = 0; /* got to do this after hdr is set */ } /* @@ -990,7 +989,7 @@ process_lclinode( struct xfs_dinode *dip, int whichfork) { - struct xfs_attr_shortform *asf; + struct xfs_attr_sf_hdr *hdr; xfs_ino_t lino; lino = XFS_AGINO_TO_INO(mp, agno, ino); @@ -1002,18 +1001,18 @@ process_lclinode( XFS_DFORK_DSIZE(dip, mp)); return(1); } else if (whichfork == XFS_ATTR_FORK) { - asf = (struct xfs_attr_shortform *)XFS_DFORK_APTR(dip); - if (be16_to_cpu(asf->hdr.totsize) > XFS_DFORK_ASIZE(dip, mp)) { + hdr = XFS_DFORK_APTR(dip); + if (be16_to_cpu(hdr->totsize) > XFS_DFORK_ASIZE(dip, mp)) { do_warn( _("local inode %" PRIu64 " attr fork too large (size %d, max = %zu)\n"), - lino, be16_to_cpu(asf->hdr.totsize), + lino, be16_to_cpu(hdr->totsize), XFS_DFORK_ASIZE(dip, mp)); return(1); } - if (be16_to_cpu(asf->hdr.totsize) < sizeof(xfs_attr_sf_hdr_t)) { + if (be16_to_cpu(hdr->totsize) < sizeof(xfs_attr_sf_hdr_t)) { do_warn( _("local inode %" PRIu64 " attr too small (size = %d, min size = %zd)\n"), - lino, be16_to_cpu(asf->hdr.totsize), + lino, be16_to_cpu(hdr->totsize), sizeof(xfs_attr_sf_hdr_t)); return(1); } From patchwork Mon Apr 22 16:26:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638741 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 BC1A115381E for ; Mon, 22 Apr 2024 16:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804040; cv=none; b=dWBpzaKe71Z2mTMmshnOU0nrww833L/bAZJf3c06tmqVWr5CoPR583oaIRJrVAOS/u1JkYIhaotNWe0LPQhOb/JIlXWTe8NvTnRGi1Fm/4Tde5iRShXsnd4PtBroTtpJOdKiFSEK9cMQTPV+uIAbKJNNycCP+NH3jgarF04U6CQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804040; c=relaxed/simple; bh=0KEXvLgylqoJ81b4/0NMS259VN31vqag+i5G/AHx5tQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ya59E0miG9xKMJ3ptmKYUT0k9QLLKrioUqPfg+0dXHcatFc0q8v9uKTbCsdmaqu7jc8xq4XXfVry2T817/ogL2/yOeX6KQ7asVIcROiSnyZoOS7RZfW2MxTHvdWInnk3Hu+YS1flHL6IkdPbBwEABuiRwWLveRSo+TMNhB3GEYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LXeqklei; 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="LXeqklei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91F1EC116B1; Mon, 22 Apr 2024 16:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804040; bh=0KEXvLgylqoJ81b4/0NMS259VN31vqag+i5G/AHx5tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LXeqkleiR4ATqEuA+598qImTcVz0aTrOotPVLaJA8uObb5MtOHbMVu+FRVqTdK2Sw yNqfhH/VM6S5+NBS0AxUeGKaqP+lHdgEt2zXkOpYdsb0cEqIERyHVQs5pAnarvoxIQ FNTjo6oFkOqfctWxxnPC+ZiCcXZ1nnwpZ00Ihf5TUUrw7wRD3VWIH2qB1cUUNG107U Y6pz9LGFi1uTFOZ99IET7GXE/pW44HZ8bu8CSS7PCI+pwjw37BOEyk3o/yVF5N6KZA gpoaAOVkAqNlPKWO+g2AkeS2FQJRwYoFJ4QPqr8e/CW4pPqaraGTHiPZEBDwApD3oZ JwrBGJPgnOlCw== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 61/67] xfs: remove xfs_attr_sf_hdr_t Date: Mon, 22 Apr 2024 18:26:23 +0200 Message-ID: <20240422163832.858420-63-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 074aea4be1a4074be49a7ec41c674cc02b52fd60 Remove the last two users of the typedef. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- db/attrshort.c | 2 +- libxfs/xfs_attr_leaf.c | 4 ++-- libxfs/xfs_attr_sf.h | 8 -------- repair/attr_repair.c | 6 +++--- repair/dinode.c | 6 +++--- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/db/attrshort.c b/db/attrshort.c index c98b90be3..7c386d46f 100644 --- a/db/attrshort.c +++ b/db/attrshort.c @@ -25,7 +25,7 @@ const field_t attr_shortform_flds[] = { { NULL } }; -#define HOFF(f) bitize(offsetof(xfs_attr_sf_hdr_t, f)) +#define HOFF(f) bitize(offsetof(struct xfs_attr_sf_hdr, f)) const field_t attr_sf_hdr_flds[] = { { "totsize", FLDT_UINT16D, OI(HOFF(totsize)), C1, 0, TYP_NONE }, { "count", FLDT_UINT8D, OI(HOFF(count)), C1, 0, TYP_NONE }, diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index cf172b6ea..e3f8f67b5 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -813,7 +813,7 @@ xfs_attr_sf_removename( /* * Fix up the start offset of the attribute fork */ - if (totsize == sizeof(xfs_attr_sf_hdr_t) && xfs_has_attr2(mp) && + if (totsize == sizeof(struct xfs_attr_sf_hdr) && xfs_has_attr2(mp) && (dp->i_df.if_format != XFS_DINODE_FMT_BTREE) && !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE))) { xfs_attr_fork_remove(dp, args->trans); @@ -821,7 +821,7 @@ xfs_attr_sf_removename( xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); dp->i_forkoff = xfs_attr_shortform_bytesfit(dp, totsize); ASSERT(dp->i_forkoff); - ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || + ASSERT(totsize > sizeof(struct xfs_attr_sf_hdr) || (args->op_flags & XFS_DA_OP_ADDNAME) || !xfs_has_attr2(mp) || dp->i_df.if_format == XFS_DINODE_FMT_BTREE); diff --git a/libxfs/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h index 9abf7de95..bc4422223 100644 --- a/libxfs/xfs_attr_sf.h +++ b/libxfs/xfs_attr_sf.h @@ -6,14 +6,6 @@ #ifndef __XFS_ATTR_SF_H__ #define __XFS_ATTR_SF_H__ -/* - * Attribute storage when stored inside the inode. - * - * Small attribute lists are packed as tightly as possible so as - * to fit into the literal area of the inode. - */ -typedef struct xfs_attr_sf_hdr xfs_attr_sf_hdr_t; - /* * We generate this then sort it, attr_list() must return things in hash-order. */ diff --git a/repair/attr_repair.c b/repair/attr_repair.c index b65b28a20..0d22feb4f 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -224,14 +224,14 @@ process_shortform_attr( */ if (hdr->count == 0) /* then the total size should just be the header length */ - if (be16_to_cpu(hdr->totsize) != sizeof(xfs_attr_sf_hdr_t)) { + if (be16_to_cpu(hdr->totsize) != sizeof(struct xfs_attr_sf_hdr)) { /* whoops there's a discrepancy. Clear the hdr */ if (!no_modify) { do_warn( _("there are no attributes in the fork for inode %" PRIu64 "\n"), ino); hdr->totsize = - cpu_to_be16(sizeof(xfs_attr_sf_hdr_t)); + cpu_to_be16(sizeof(struct xfs_attr_sf_hdr)); *repair = 1; return(1); } else { @@ -242,7 +242,7 @@ process_shortform_attr( } } - currentsize = sizeof(xfs_attr_sf_hdr_t); + currentsize = sizeof(struct xfs_attr_sf_hdr); remainingspace = be16_to_cpu(hdr->totsize) - currentsize; nextentry = libxfs_attr_sf_firstentry(hdr); for (i = 0; i < hdr->count; i++) { diff --git a/repair/dinode.c b/repair/dinode.c index f4398c0df..cc3f07dda 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -100,7 +100,7 @@ _("would have cleared inode %" PRIu64 " attributes\n"), ino_num); if (!no_modify) { struct xfs_attr_sf_hdr *hdr = XFS_DFORK_APTR(dino); - hdr->totsize = cpu_to_be16(sizeof(xfs_attr_sf_hdr_t)); + hdr->totsize = cpu_to_be16(sizeof(struct xfs_attr_sf_hdr)); hdr->count = 0; dino->di_forkoff = 0; /* got to do this after hdr is set */ } @@ -1009,11 +1009,11 @@ process_lclinode( XFS_DFORK_ASIZE(dip, mp)); return(1); } - if (be16_to_cpu(hdr->totsize) < sizeof(xfs_attr_sf_hdr_t)) { + if (be16_to_cpu(hdr->totsize) < sizeof(struct xfs_attr_sf_hdr)) { do_warn( _("local inode %" PRIu64 " attr too small (size = %d, min size = %zd)\n"), lino, be16_to_cpu(hdr->totsize), - sizeof(xfs_attr_sf_hdr_t)); + sizeof(struct xfs_attr_sf_hdr)); return(1); } } From patchwork Mon Apr 22 16:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638742 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 80B83153BF7 for ; Mon, 22 Apr 2024 16:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804042; cv=none; b=MtyOEnkBl52shoVusPJTaZ8u1wPKmyAdCOopnOQ8UQCHyTgbr5mhl26LH76Ahrf8kSuB2rtBOvS+iVw3l4JDmik/xRwYGv6eepRZQHAcN/PxRT/MfPwdjrdheTsK3b+q9v7T92msRNbSRUVcmbj9YVCxk8/XuVr+HcsAadWVzT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804042; c=relaxed/simple; bh=jEoFC4aM18HUrTM8+QOIFOXGfB4V2prlJjGz46dLOfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PbXfH1BWRVDhFEae6qTY5sMEFUkfuhUIlV4O4wqd2I++qv9L4PIsx4aLeW9vUq0seZvyHi3mNzlACnGnffVW7EVK76BxKfC1zNyPouC76vS3n2MQFbWT+JcmmhgEo4kyeei0PwhT2bZlfENubTcMhsGlq5PbiR3VCZVhMT7/M1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dYY0fXyE; 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="dYY0fXyE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16D6FC113CC; Mon, 22 Apr 2024 16:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804042; bh=jEoFC4aM18HUrTM8+QOIFOXGfB4V2prlJjGz46dLOfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dYY0fXyExOo3UWlOFjbrrSo+u3mQJ4KIC1Turwk+BHZ4hzzc3C0M8Fbt02eIGy6lX CJLXeuIsiUnWmf1WIlGofSGg5rI3rk5ISuB/PMcCbHy7Pcv5ZOGPeYSUa9qrO83H31 OiJm9d6LVMfiQXWaBEpEhr8tDMpX1cbiEgb6gtzVcWIunZhkYeYEGYCpKiBdrhE54f AclAUSvJYNJhv2ZhxeJ/6BEzuqlM6HCAs3IIwOgxf7ZbqCbdSqFVLq7suTNqgCFJov ZIASbC7oMVJkrCJfEOPyJEaSc78e5kAgxBBjej6ThTTTTa6I69bIz3fg7iC3bEZyDm WgePpWwAU5SSg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 62/67] xfs: turn the XFS_DA_OP_REPLACE checks in xfs_attr_shortform_addname into asserts Date: Mon, 22 Apr 2024 18:26:24 +0200 Message-ID: <20240422163832.858420-64-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 378b6aef9de0f7c3d0de309ecc61c11eb29e57da Since commit deed9512872d ("xfs: Check for -ENOATTR or -EEXIST"), the high-level attr code does a lookup for any attr we're trying to set, and does the checks to handle the create vs replace cases, which thus never hit the low-level attr code. Turn the checks in xfs_attr_shortform_addname as they must never trip. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 055d20410..1419846bd 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1070,8 +1070,7 @@ xfs_attr_shortform_addname( if (xfs_attr_sf_findname(args)) { int error; - if (!(args->op_flags & XFS_DA_OP_REPLACE)) - return -EEXIST; + ASSERT(args->op_flags & XFS_DA_OP_REPLACE); error = xfs_attr_sf_removename(args); if (error) @@ -1085,8 +1084,7 @@ xfs_attr_shortform_addname( */ args->op_flags &= ~XFS_DA_OP_REPLACE; } else { - if (args->op_flags & XFS_DA_OP_REPLACE) - return -ENOATTR; + ASSERT(!(args->op_flags & XFS_DA_OP_REPLACE)); } if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX || From patchwork Mon Apr 22 16:26:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638743 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 B3129153BFB for ; Mon, 22 Apr 2024 16:40: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=1713804043; cv=none; b=k+eyFF3ZNDogQsQi3cyZPJsJxtzUlBmM058lKyYT1YR/DRVTZB/vuAZGY5o7zdnGEaGqSYvEWRdj2CEK//EbIKlOpChsaDDxvALBoziuKd4Vb0ZDHR1FEfOwUXp7It1nFHr0DhC4x+ouMM69iAwqFwpClOqzQIq82EJtiXZJpEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804043; c=relaxed/simple; bh=ftz1jEtiHbhcvz4RBiJZwh7BMm9+3il6XPTF5OC4vXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eKxWy6lPjZ6ksAqe/Bgh2qhUuTwlEmbtB86UgquASM3dUdD/6L/I9GqJA+xgjOLE/r7m/DtTFLfSw4Hr3g7nPvP2JigQEt5heYyN1owVfIhyAqSugT4ikcSFSyNDt8cZcQMznUOOQgOAw44Xz/T++WscB0i5nir+IMWtjP9IgzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jsy6OL4k; 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="Jsy6OL4k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9978CC116B1; Mon, 22 Apr 2024 16:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804043; bh=ftz1jEtiHbhcvz4RBiJZwh7BMm9+3il6XPTF5OC4vXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jsy6OL4kbCjWimzrf+045t9zYgEFB5MuznWv8/R8ei34dhWI8OiwQ+F6cQjYhxND9 oY/IGiDpLO/A7yZG326snWObvEd4E+4GdfaU6fVAwA6cYdaIyl7WOuQGpUSJ1nOoU/ G+zO1eQ+ctRf60682C83K5gyCGlYwTEEURY2PMu6n1n6XkEo9F/yv1IRCW9KBwq6D6 3QQofBQIzx77Yn0bNY16k9pqrtvGAYd0XB5Rqz8kkZny/uuCt0A1pH6OIHxEtvdtuY eIZZnCZ0Nx5ChiUeZIOR7qxzrKgxmwKhoZlWndWuTJyFmywd/t4sIbRHZgWjB9IWIc EB8gJARpwXMKA== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 63/67] xfs: fix a use after free in xfs_defer_finish_recovery Date: Mon, 22 Apr 2024 18:26:25 +0200 Message-ID: <20240422163832.858420-65-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 4f6ac47b55e3ce6e982807928d6074ec105ab66e dfp will be freed by ->recover_work and thus the tracepoint in case of an error can lead to a use after free. Store the defer ops in a local variable to avoid that. Fixes: 7f2f7531e0d4 ("xfs: store an ops pointer in struct xfs_defer_pending") Reported-by: kernel test robot Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 077e99298..5bdc8f5a2 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -909,12 +909,14 @@ xfs_defer_finish_recovery( struct xfs_defer_pending *dfp, struct list_head *capture_list) { + const struct xfs_defer_op_type *ops = dfp->dfp_ops; int error; - error = dfp->dfp_ops->recover_work(dfp, capture_list); + /* dfp is freed by recover_work and must not be accessed afterwards */ + error = ops->recover_work(dfp, capture_list); if (error) trace_xlog_intent_recovery_failed(mp, error, - dfp->dfp_ops->recover_work); + ops->recover_work); return error; } From patchwork Mon Apr 22 16:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638744 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 5CB1F15381B for ; Mon, 22 Apr 2024 16:40:45 +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=1713804045; cv=none; b=fCzBPLeFQeJ4kab1q1PzmtDypEoUe5ZlsC8OoA5bJ1lkJNV+po0bJPDJa/RBGR0GzS6O/ZEpuh1ZTRLO1M5iaizLYpjyhilzT5RVrkTChj4nPTa2RopVCARvInGGMrV6SxroypXsqRm4rsw88ERBLSRP0ctBq6ux1NiHMgnofjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804045; c=relaxed/simple; bh=xRNHjvWn5Og4xBVEKdmGXR6/2SCdprMCyu8SEUdqwB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RBRtj+I/T9XQ+2Jdnelei7npcDG8wzlmOOx4lt0QAnw+iOTBSlPGcfscB2BYYpvkTO+CNuneZcpdXaZW6mIqiVzeqGJCco/T+K85WZKK//AC0MfkohNRPxV0DyWXYOMEp6ycYnwMfaV4+v+19tzVF1pWZ//VyP26OUXn0Akt53A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OmFUXjVw; 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="OmFUXjVw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28739C116B1; Mon, 22 Apr 2024 16:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804045; bh=xRNHjvWn5Og4xBVEKdmGXR6/2SCdprMCyu8SEUdqwB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OmFUXjVwTICMdWAUP6nOSJ02Iuebbkb5dDmRYvNKPHmCJdbyEbtwc7te0UY6tksX4 yfUnWNiN5ImGm1pLmI7ICi8sCrw4SEbFar/wOen4P48NMlmCUTNL3GkosA8jZLhrcV 5jLSb4b/5f/LJjy2xE3LiRvWWY51oWtAboXm0FmLK0+SGE3Li1m0BcdPAQUbPG4llO drnqDnAGHd9H8a8ZV6X4ii5WxEJP9jk36fp5YPVOVJXPsiEJARaiRM0BAgr3NM+bnB KMj5fBf12/Vqr/CtHOr02A/S3bedszi02IrvD7HNn10HRzrLQj551f9pfsYKA8L4uH 5dc7TTRWJd+ng== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 64/67] xfs: use the op name in trace_xlog_intent_recovery_failed Date: Mon, 22 Apr 2024 18:26:26 +0200 Message-ID: <20240422163832.858420-66-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: bcdfae6ee520b665385020fa3e47633a8af84f12 Instead of tracing the address of the recovery handler, use the name in the defer op, similar to other defer ops related tracepoints. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_defer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 5bdc8f5a2..bf1d1e06a 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -915,8 +915,7 @@ xfs_defer_finish_recovery( /* dfp is freed by recover_work and must not be accessed afterwards */ error = ops->recover_work(dfp, capture_list); if (error) - trace_xlog_intent_recovery_failed(mp, error, - ops->recover_work); + trace_xlog_intent_recovery_failed(mp, ops, error); return error; } From patchwork Mon Apr 22 16:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638745 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 DD7FC154421 for ; Mon, 22 Apr 2024 16: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=1713804046; cv=none; b=c0VqNuHl5TRk7yTIn2Vzt7yBShpElSWQVJ9mG++jypWtJFnX7fwF7KjzTygi8A6Mbj4LygHRW5mlvE1UYGKqVC2wlt3/gQ1YHYeQGKvn6Wk9nZ+yIZxjk7QBTjRIwlo4sNxGrHx3Bv1isjDzeoL8lnCz6dA6JeC8hwAHoJC57n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804046; c=relaxed/simple; bh=AGNKdTVyTgNmz+670NjkqefCRRTgfQ5gywL7vW+xgT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOjsQhNwIsYy7wdK+982Cnpu0nLaaK/BUsnqydmtN4JgXYYcCLDGpQOVwAo3+f6YApSXIGqiSmyQTR5Rsl3FAWfUzo0U94w1Q2WGezphavbp2dKnPbe/pIbOWVglJq1mzrci2n7paAR7WS4kb8iVFozzxLTQ3RDDRfwqrK2nN5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vKvXn0fc; 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="vKvXn0fc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C428BC113CC; Mon, 22 Apr 2024 16:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804046; bh=AGNKdTVyTgNmz+670NjkqefCRRTgfQ5gywL7vW+xgT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vKvXn0fcCi3Lh4fX0qzDMGL2zJqY6N7dpYFpGXfeSLLQi5fax/mdQMzkDHUt0qLKq uxKZGiP+sV9LBX7rOwNThp3w1yDD6L3UD0V0+kjTn9I0AWLg3n8wunMgiKFpuagfgj qnOAg7fUmC0h3dPN6AXCFefpb8LJX85GoLJCQWiCcAeVxp/6e+IfXTr4LtX+zZJ82S ixT3c8lC6SbJr4BA9waYKhriix/kFumqqTnti/9WbCtWUQ11b1Q2naxKdmO/RgxZPa 7GQOr8C6gPImk9Ok7udZgLcl/BBU6r7UWWTIPQHaSzI3P54TDkCOt2VE7/0i4+lFo8 ErbDnRn+NZcpQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 65/67] xfs: fix backwards logic in xfs_bmap_alloc_account Date: Mon, 22 Apr 2024 18:26:27 +0200 Message-ID: <20240422163832.858420-67-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: d61b40bf15ce453f3aa71f6b423938e239e7f8f8 We're only allocating from the realtime device if the inode is marked for realtime and we're /not/ allocating into the attr fork. Fixes: 58643460546d ("xfs: also use xfs_bmap_btalloc_accounting for RT allocations") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_bmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 5e6a5e1f3..494994d36 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3271,7 +3271,7 @@ xfs_bmap_alloc_account( struct xfs_bmalloca *ap) { bool isrt = XFS_IS_REALTIME_INODE(ap->ip) && - (ap->flags & XFS_BMAPI_ATTRFORK); + !(ap->flags & XFS_BMAPI_ATTRFORK); uint fld; if (ap->flags & XFS_BMAPI_COWFORK) { From patchwork Mon Apr 22 16:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638746 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 A51AB15381B for ; Mon, 22 Apr 2024 16:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804048; cv=none; b=UJQTHr9mBHDJ+E88sbs5XykSKfeEsQB1OD0WjVCK5ZyRmhazTeJB8P6vmd1qhacfRbyiZ6PycCFzx9v5E0ZpQrtq/RFA0wGsI4gY0FFMthVD1B53tqRIgtzKw1xP41eQmyAwhd0eRBXhQOCbKfIoOJggIxCmo2kBdSKawrZDTpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804048; c=relaxed/simple; bh=YlAi+kr94f8AxIotiARGHP4DpvJjCtJwFSPXjiNhH7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qyqa5d81/8u2XVO2KqIFtJm6wyg8+knr0BDZWodL+wtrYmwM4Guc/cX1dg4SYA13agJVMcCi6Mq1WkuYKEnjjusaiDG0yxN1ti84fz84BLj0lKJCcbzlKG+3jbcWFyaifw/aqCU7SvLpbATd2R3Qyob68EYV3tnYILdQJ4iPcG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VUYuKWNJ; 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="VUYuKWNJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B463C32781; Mon, 22 Apr 2024 16:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804048; bh=YlAi+kr94f8AxIotiARGHP4DpvJjCtJwFSPXjiNhH7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUYuKWNJ70MIj/DqxSFh/O53hOFVQy6meQj57rd1YlPDg+PxgQUsh8aQR/awAXPKn Io3LVSa/t/BqlEtHUS+YmpDL52Yz849oRTBabThOQG5XyFCL6LQX0XPza/jfYcIraV zMG6aagxGrzT4y6ooCNG5UCqq7u0pSJ8uONC9Bf5ifiV7spPZJxrOauV5bTDsJog9+ OQim/XiXjoARgHzQEsi7l1xMVdhAVXbM4WsiLb97Zd5a/U6nrd3td64RclMBO0i552 DYvBXP5F8Kau8dbeWAZtbofF7OAPsFj5+rRuBFiNffuTC/5QtXviQ3b3kfLJcoaChV qLxRlafROc8xQ== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 66/67] xfs: reset XFS_ATTR_INCOMPLETE filter on node removal Date: Mon, 22 Apr 2024 18:26:28 +0200 Message-ID: <20240422163832.858420-68-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Andrey Albershteyn Source kernel commit: 82ef1a5356572219f41f9123ca047259a77bd67b In XFS_DAS_NODE_REMOVE_ATTR case, xfs_attr_mode_remove_attr() sets filter to XFS_ATTR_INCOMPLETE. The filter is then reset in xfs_attr_complete_op() if XFS_DA_OP_REPLACE operation is performed. The filter is not reset though if XFS just removes the attribute (args->value == NULL) with xfs_attr_defer_remove(). attr code goes to XFS_DAS_DONE state. Fix this by always resetting XFS_ATTR_INCOMPLETE filter. The replace operation already resets this filter in anyway and others are completed at this step hence don't need it. Fixes: fdaf1bb3cafc ("xfs: ATTR_REPLACE algorithm with LARP enabled needs rework") Signed-off-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 1419846bd..630065f1a 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -419,10 +419,10 @@ xfs_attr_complete_op( bool do_replace = args->op_flags & XFS_DA_OP_REPLACE; args->op_flags &= ~XFS_DA_OP_REPLACE; - if (do_replace) { - args->attr_filter &= ~XFS_ATTR_INCOMPLETE; + args->attr_filter &= ~XFS_ATTR_INCOMPLETE; + if (do_replace) return replace_state; - } + return XFS_DAS_DONE; } From patchwork Mon Apr 22 16:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13638747 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 C9A5E153BFE for ; Mon, 22 Apr 2024 16:40: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=1713804049; cv=none; b=KQ7qaA3YGJpMbsjor8VrqGskLAYbBwsH4DJv0hftMppm9HQPh+krdr/JAGRh22O5h1TSvMxfZotqCqDX+oQDXvvl+FaTWgJhaz0IlSJf0/a4z3jLg6fG4irnN0WWhHljqMPyf8cOf1Ik91sZdTijHLodXph/KqfXR5/lUpBf0BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713804049; c=relaxed/simple; bh=xBdqNSpQfYAPtMtOBkzeDjQB8lwX4ELnytvU2/LkD+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QkIECdSlA5onpTCFVWcQgr4o8WaJc+EGscX9tBFHxZvI6SlIEwMOp+GcFA5bsLTBzO5C6aahyz/a+GXQ33zvQ82iie8F/SMwWADpIt421tbxSD39yGBBr5ap29ww1AdHzqYxA2BLQ1PY+yZK+hdLQMoP/gJ0rw6wc+qM0SJDp+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eE/R52lJ; 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="eE/R52lJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9005C116B1; Mon, 22 Apr 2024 16:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713804049; bh=xBdqNSpQfYAPtMtOBkzeDjQB8lwX4ELnytvU2/LkD+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eE/R52lJMuBsd4AjMTUvAnAMk9bhMB24pYIU4oB2g1gluF7j2ZZQTUQyb3TGCod09 tpQCA9GEUMElLDQ0/j/lj1yi0r8aeuXMF/4Rw+gAA0LY1ZSZ/KBpDhx1clTMZUJ9Ev f9tLpU+d/aok7OPEQqjCKP2p7XGA/12wLikPhcJSSjBjoJFitWD5di8hJWlgSgbU6W FUIZ6t135YssKd/vSFdd4XQ4DkJE7R2pUn2YE7S0UvOkABLYI9lZMf0DKsb/JgnL5W Z2r1KzwGghw5Wvl+cz8dZMd4x4zir9h4NqjltQ2o6vKcDm028qd1hIwoEEQHiTgARC b9fpvBMs9MqOg== From: cem@kernel.org To: linux-xfs@vger.kernel.org Cc: djwong@kernel.org, hch@lst.de Subject: [PATCH 67/67] xfs: remove conditional building of rt geometry validator functions Date: Mon, 22 Apr 2024 18:26:29 +0200 Message-ID: <20240422163832.858420-69-cem@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240422163832.858420-2-cem@kernel.org> References: <20240422163832.858420-2-cem@kernel.org> 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: 881f78f472556ed05588172d5b5676b48dc48240 I mistakenly turned off CONFIG_XFS_RT in the Kconfig file for arm64 variant of the djwong-wtf git branch. Unfortunately, it took me a good hour to figure out that RT wasn't built because this is what got printed to dmesg: XFS (sda2): realtime geometry sanity check failed XFS (sda2): Metadata corruption detected at xfs_sb_read_verify+0x170/0x190 [xfs], xfs_sb block 0x0 Whereas I would have expected: XFS (sda2): Not built with CONFIG_XFS_RT XFS (sda2): RT mount failed The root cause of these problems is the conditional compilation of the new functions xfs_validate_rtextents and xfs_compute_rextslog that I introduced in the two commits listed below. The !RT versions of these functions return false and 0, respectively, which causes primary superblock validation to fail, which explains the first message. Move the two functions to other parts of libxfs that are not conditionally defined by CONFIG_XFS_RT and remove the broken stubs so that validation works again. Fixes: e14293803f4e ("xfs: don't allow overly small or large realtime volumes") Fixes: a6a38f309afc ("xfs: make rextslog computation consistent with mkfs") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R Signed-off-by: Carlos Maiolino --- libxfs/xfs_rtbitmap.c | 14 -------------- libxfs/xfs_rtbitmap.h | 16 ---------------- libxfs/xfs_sb.c | 14 ++++++++++++++ libxfs/xfs_sb.h | 2 ++ libxfs/xfs_types.h | 12 ++++++++++++ 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 79af7cda3..08a4128fc 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1116,20 +1116,6 @@ xfs_rtbitmap_blockcount( return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize); } -/* - * Compute the maximum level number of the realtime summary file, as defined by - * mkfs. The historic use of highbit32 on a 64-bit quantity prohibited correct - * use of rt volumes with more than 2^32 extents. - */ -uint8_t -xfs_compute_rextslog( - xfs_rtbxlen_t rtextents) -{ - if (!rtextents) - return 0; - return xfs_highbit64(rtextents); -} - /* * Compute the number of rtbitmap words needed to populate every block of a * bitmap that is large enough to track the given number of rt extents. diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 274dc7dae..152a66750 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -351,20 +351,6 @@ xfs_rtfree_extent( int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, xfs_filblks_t rtlen); -uint8_t xfs_compute_rextslog(xfs_rtbxlen_t rtextents); - -/* Do we support an rt volume having this number of rtextents? */ -static inline bool -xfs_validate_rtextents( - xfs_rtbxlen_t rtextents) -{ - /* No runt rt volumes */ - if (rtextents == 0) - return false; - - return true; -} - xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents); unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp, @@ -383,8 +369,6 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, # define xfs_rtsummary_read_buf(a,b) (-ENOSYS) # define xfs_rtbuf_cache_relse(a) (0) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) -# define xfs_compute_rextslog(rtx) (0) -# define xfs_validate_rtextents(rtx) (false) static inline xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) { diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 7a72d5a17..402f03a55 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1375,3 +1375,17 @@ xfs_validate_stripe_geometry( } return true; } + +/* + * Compute the maximum level number of the realtime summary file, as defined by + * mkfs. The historic use of highbit32 on a 64-bit quantity prohibited correct + * use of rt volumes with more than 2^32 extents. + */ +uint8_t +xfs_compute_rextslog( + xfs_rtbxlen_t rtextents) +{ + if (!rtextents) + return 0; + return xfs_highbit64(rtextents); +} diff --git a/libxfs/xfs_sb.h b/libxfs/xfs_sb.h index 19134b23c..2e8e8d63d 100644 --- a/libxfs/xfs_sb.h +++ b/libxfs/xfs_sb.h @@ -38,4 +38,6 @@ extern int xfs_sb_get_secondary(struct xfs_mount *mp, extern bool xfs_validate_stripe_geometry(struct xfs_mount *mp, __s64 sunit, __s64 swidth, int sectorsize, bool silent); +uint8_t xfs_compute_rextslog(xfs_rtbxlen_t rtextents); + #endif /* __XFS_SB_H__ */ diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index 20b5375f2..62e02d538 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -251,4 +251,16 @@ bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off); bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off, xfs_fileoff_t len); +/* Do we support an rt volume having this number of rtextents? */ +static inline bool +xfs_validate_rtextents( + xfs_rtbxlen_t rtextents) +{ + /* No runt rt volumes */ + if (rtextents == 0) + return false; + + return true; +} + #endif /* __XFS_TYPES_H__ */