Commit 10ea6158 authored by Chandan Babu R's avatar Chandan Babu R
Browse files

Merge tag 'bmap-intent-cleanups-6.9_2024-02-23' of...

Merge tag 'bmap-intent-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux

 into xfs-6.9-mergeC

xfs: bmap log intent cleanups

The next major target of online repair are metadata that are persisted
in blocks mapped by a file fork.  In other words, we want to repair
directories, extended attributes, symbolic links, and the realtime free
space information.  For file-based metadata, we assume that the space
metadata is correct, which enables repair to construct new versions of
the metadata in a temporary file.  We then need to swap the file fork
mappings of the two files atomically.  With this patchset, we begin
constructing such a facility based on the existing bmap log items and a
new extent swap log item.

This series cleans up a few parts of the file block mapping log intent
code before we start adding support for realtime bmap intents.  Most of
it involves cleaning up tracepoints so that more of the data extraction
logic ends up in the tracepoint code and not the tracepoint call site,
which should reduce overhead further when tracepoints are disabled.
There is also a change to pass bmap intents all the way back to the bmap
code instead of unboxing the intent values and re-boxing them after the
_finish_one function completes.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'bmap-intent-cleanups-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: add a xattr_entry helper
  xfs: move xfs_bmap_defer_add to xfs_bmap_item.c
  xfs: reuse xfs_bmap_update_cancel_item
  xfs: add a bi_entry helper
  xfs: remove xfs_trans_set_bmap_flags
  xfs: clean up bmap log intent item tracepoint callsites
  xfs: split tracepoint classes for deferred items
parents 74acb705 c75f1a2c
Loading
Loading
Loading
Loading
+3 −18
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include "xfs_icache.h"
#include "xfs_iomap.h"
#include "xfs_health.h"
#include "xfs_bmap_item.h"

struct kmem_cache		*xfs_bmap_intent_cache;

@@ -6191,15 +6192,6 @@ __xfs_bmap_add(
{
	struct xfs_bmap_intent		*bi;

	trace_xfs_bmap_defer(tp->t_mountp,
			XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock),
			type,
			XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock),
			ip->i_ino, whichfork,
			bmap->br_startoff,
			bmap->br_blockcount,
			bmap->br_state);

	bi = kmem_cache_alloc(xfs_bmap_intent_cache, GFP_KERNEL | __GFP_NOFAIL);
	INIT_LIST_HEAD(&bi->bi_list);
	bi->bi_type = type;
@@ -6207,8 +6199,7 @@ __xfs_bmap_add(
	bi->bi_whichfork = whichfork;
	bi->bi_bmap = *bmap;

	xfs_bmap_update_get_group(tp->t_mountp, bi);
	xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type);
	xfs_bmap_defer_add(tp, bi);
	return 0;
}

@@ -6252,13 +6243,7 @@ xfs_bmap_finish_one(

	ASSERT(tp->t_highest_agno == NULLAGNUMBER);

	trace_xfs_bmap_deferred(tp->t_mountp,
			XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock),
			bi->bi_type,
			XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock),
			bi->bi_owner->i_ino, bi->bi_whichfork,
			bmap->br_startoff, bmap->br_blockcount,
			bmap->br_state);
	trace_xfs_bmap_deferred(bi);

	if (WARN_ON_ONCE(bi->bi_whichfork != XFS_DATA_FORK)) {
		xfs_bmap_mark_sick(bi->bi_owner, bi->bi_whichfork);
+4 −3
Original line number Diff line number Diff line
@@ -232,6 +232,10 @@ enum xfs_bmap_intent_type {
	XFS_BMAP_UNMAP,
};

#define XFS_BMAP_INTENT_STRINGS \
	{ XFS_BMAP_MAP,		"map" }, \
	{ XFS_BMAP_UNMAP,	"unmap" }

struct xfs_bmap_intent {
	struct list_head			bi_list;
	enum xfs_bmap_intent_type		bi_type;
@@ -241,9 +245,6 @@ struct xfs_bmap_intent {
	struct xfs_bmbt_irec			bi_bmap;
};

void xfs_bmap_update_get_group(struct xfs_mount *mp,
		struct xfs_bmap_intent *bi);

int	xfs_bmap_finish_one(struct xfs_trans *tp, struct xfs_bmap_intent *bi);
void	xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
		struct xfs_bmbt_irec *imap);
+7 −4
Original line number Diff line number Diff line
@@ -391,6 +391,11 @@ xfs_attr_free_item(
		kmem_cache_free(xfs_attr_intent_cache, attr);
}

static inline struct xfs_attr_intent *attri_entry(const struct list_head *e)
{
	return list_entry(e, struct xfs_attr_intent, xattri_list);
}

/* Process an attr. */
STATIC int
xfs_attr_finish_item(
@@ -399,11 +404,10 @@ xfs_attr_finish_item(
	struct list_head		*item,
	struct xfs_btree_cur		**state)
{
	struct xfs_attr_intent		*attr;
	struct xfs_attr_intent		*attr = attri_entry(item);
	struct xfs_da_args		*args;
	int				error;

	attr = container_of(item, struct xfs_attr_intent, xattri_list);
	args = attr->xattri_da_args;

	/* Reset trans after EAGAIN cycle since the transaction is new */
@@ -443,9 +447,8 @@ STATIC void
xfs_attr_cancel_item(
	struct list_head		*item)
{
	struct xfs_attr_intent		*attr;
	struct xfs_attr_intent		*attr = attri_entry(item);

	attr = container_of(item, struct xfs_attr_intent, xattri_list);
	xfs_attr_free_item(attr);
}

+47 −48
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "xfs_log_priv.h"
#include "xfs_log_recover.h"
#include "xfs_ag.h"
#include "xfs_trace.h"

struct kmem_cache	*xfs_bui_cache;
struct kmem_cache	*xfs_bud_cache;
@@ -221,6 +222,11 @@ static const struct xfs_item_ops xfs_bud_item_ops = {
	.iop_intent	= xfs_bud_item_intent,
};

static inline struct xfs_bmap_intent *bi_entry(const struct list_head *e)
{
	return list_entry(e, struct xfs_bmap_intent, bi_list);
}

/* Sort bmap intents by inode. */
static int
xfs_bmap_update_diff_items(
@@ -228,37 +234,12 @@ xfs_bmap_update_diff_items(
	const struct list_head		*a,
	const struct list_head		*b)
{
	struct xfs_bmap_intent		*ba;
	struct xfs_bmap_intent		*bb;
	struct xfs_bmap_intent		*ba = bi_entry(a);
	struct xfs_bmap_intent		*bb = bi_entry(b);

	ba = container_of(a, struct xfs_bmap_intent, bi_list);
	bb = container_of(b, struct xfs_bmap_intent, bi_list);
	return ba->bi_owner->i_ino - bb->bi_owner->i_ino;
}

/* Set the map extent flags for this mapping. */
static void
xfs_trans_set_bmap_flags(
	struct xfs_map_extent		*map,
	enum xfs_bmap_intent_type	type,
	int				whichfork,
	xfs_exntst_t			state)
{
	map->me_flags = 0;
	switch (type) {
	case XFS_BMAP_MAP:
	case XFS_BMAP_UNMAP:
		map->me_flags = type;
		break;
	default:
		ASSERT(0);
	}
	if (state == XFS_EXT_UNWRITTEN)
		map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN;
	if (whichfork == XFS_ATTR_FORK)
		map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK;
}

/* Log bmap updates in the intent item. */
STATIC void
xfs_bmap_update_log_item(
@@ -281,8 +262,19 @@ xfs_bmap_update_log_item(
	map->me_startblock = bi->bi_bmap.br_startblock;
	map->me_startoff = bi->bi_bmap.br_startoff;
	map->me_len = bi->bi_bmap.br_blockcount;
	xfs_trans_set_bmap_flags(map, bi->bi_type, bi->bi_whichfork,
			bi->bi_bmap.br_state);

	switch (bi->bi_type) {
	case XFS_BMAP_MAP:
	case XFS_BMAP_UNMAP:
		map->me_flags = bi->bi_type;
		break;
	default:
		ASSERT(0);
	}
	if (bi->bi_bmap.br_state == XFS_EXT_UNWRITTEN)
		map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN;
	if (bi->bi_whichfork == XFS_ATTR_FORK)
		map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK;
}

static struct xfs_log_item *
@@ -325,7 +317,7 @@ xfs_bmap_update_create_done(
}

/* Take a passive ref to the AG containing the space we're mapping. */
void
static inline void
xfs_bmap_update_get_group(
	struct xfs_mount	*mp,
	struct xfs_bmap_intent	*bi)
@@ -344,6 +336,18 @@ xfs_bmap_update_get_group(
	bi->bi_pag = xfs_perag_intent_get(mp, agno);
}

/* Add this deferred BUI to the transaction. */
void
xfs_bmap_defer_add(
	struct xfs_trans	*tp,
	struct xfs_bmap_intent	*bi)
{
	trace_xfs_bmap_defer(bi);

	xfs_bmap_update_get_group(tp->t_mountp, bi);
	xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type);
}

/* Release a passive AG ref after finishing mapping work. */
static inline void
xfs_bmap_update_put_group(
@@ -352,6 +356,17 @@ xfs_bmap_update_put_group(
	xfs_perag_intent_put(bi->bi_pag);
}

/* Cancel a deferred bmap update. */
STATIC void
xfs_bmap_update_cancel_item(
	struct list_head		*item)
{
	struct xfs_bmap_intent		*bi = bi_entry(item);

	xfs_bmap_update_put_group(bi);
	kmem_cache_free(xfs_bmap_intent_cache, bi);
}

/* Process a deferred bmap update. */
STATIC int
xfs_bmap_update_finish_item(
@@ -360,19 +375,16 @@ xfs_bmap_update_finish_item(
	struct list_head		*item,
	struct xfs_btree_cur		**state)
{
	struct xfs_bmap_intent		*bi;
	struct xfs_bmap_intent		*bi = bi_entry(item);
	int				error;

	bi = container_of(item, struct xfs_bmap_intent, bi_list);

	error = xfs_bmap_finish_one(tp, bi);
	if (!error && bi->bi_bmap.br_blockcount > 0) {
		ASSERT(bi->bi_type == XFS_BMAP_UNMAP);
		return -EAGAIN;
	}

	xfs_bmap_update_put_group(bi);
	kmem_cache_free(xfs_bmap_intent_cache, bi);
	xfs_bmap_update_cancel_item(item);
	return error;
}

@@ -384,19 +396,6 @@ xfs_bmap_update_abort_intent(
	xfs_bui_release(BUI_ITEM(intent));
}

/* Cancel a deferred bmap update. */
STATIC void
xfs_bmap_update_cancel_item(
	struct list_head		*item)
{
	struct xfs_bmap_intent		*bi;

	bi = container_of(item, struct xfs_bmap_intent, bi_list);

	xfs_bmap_update_put_group(bi);
	kmem_cache_free(xfs_bmap_intent_cache, bi);
}

/* Is this recovered BUI ok? */
static inline bool
xfs_bui_validate(
+4 −0
Original line number Diff line number Diff line
@@ -68,4 +68,8 @@ struct xfs_bud_log_item {
extern struct kmem_cache	*xfs_bui_cache;
extern struct kmem_cache	*xfs_bud_cache;

struct xfs_bmap_intent;

void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi);

#endif	/* __XFS_BMAP_ITEM_H__ */
Loading