From 4c6a63fdb9d45fed16f16aa044ab47ec497ad03f Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 1 Jul 2025 10:45:12 -0700 Subject: [PATCH] libxfs: add helpers to compute log item overhead Add selected helpers to estimate the transaction reservation required to write various log intent and buffer items to the log. These helpers will be used by the online repair code for more precise estimations of how much work can be done in a single transaction. Signed-off-by: "Darrick J. Wong" Reviewed-by: Andrey Albershteyn --- libxfs/defer_item.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ libxfs/defer_item.h | 14 +++++++++++++ 2 files changed, 65 insertions(+) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 6beefa6a..4530583d 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -942,3 +942,54 @@ const struct xfs_defer_op_type xfs_exchmaps_defer_type = { .finish_item = xfs_exchmaps_finish_item, .cancel_item = xfs_exchmaps_cancel_item, }; + +/* log intent size calculations */ + +static inline unsigned int +xlog_item_space( + unsigned int niovecs, + unsigned int nbytes) +{ + nbytes += niovecs * (sizeof(uint64_t) + sizeof(struct xlog_op_header)); + return round_up(nbytes, sizeof(uint64_t)); +} + +unsigned int xfs_efi_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_efi_log_format_sizeof(nr)); +} + +unsigned int xfs_efd_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_efd_log_format_sizeof(nr)); +} + +unsigned int xfs_rui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_rui_log_format_sizeof(nr)); +} + +unsigned int xfs_rud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_rud_log_format)); +} + +unsigned int xfs_bui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_bui_log_format_sizeof(nr)); +} + +unsigned int xfs_bud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_bud_log_format)); +} + +unsigned int xfs_cui_log_space(unsigned int nr) +{ + return xlog_item_space(1, xfs_cui_log_format_sizeof(nr)); +} + +unsigned int xfs_cud_log_space(void) +{ + return xlog_item_space(1, sizeof(struct xfs_cud_log_format)); +} diff --git a/libxfs/defer_item.h b/libxfs/defer_item.h index 93cf1eed..325a6f7b 100644 --- a/libxfs/defer_item.h +++ b/libxfs/defer_item.h @@ -39,4 +39,18 @@ struct xfs_refcount_intent; void xfs_refcount_defer_add(struct xfs_trans *tp, struct xfs_refcount_intent *ri); +/* log intent size calculations */ + +unsigned int xfs_efi_log_space(unsigned int nr); +unsigned int xfs_efd_log_space(unsigned int nr); + +unsigned int xfs_rui_log_space(unsigned int nr); +unsigned int xfs_rud_log_space(void); + +unsigned int xfs_bui_log_space(unsigned int nr); +unsigned int xfs_bud_log_space(void); + +unsigned int xfs_cui_log_space(unsigned int nr); +unsigned int xfs_cud_log_space(void); + #endif /* __LIBXFS_DEFER_ITEM_H_ */ -- 2.47.3