162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016 Oracle.  All Rights Reserved.
462306a36Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef	__XFS_RMAP_ITEM_H__
762306a36Sopenharmony_ci#define	__XFS_RMAP_ITEM_H__
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * There are (currently) three pairs of rmap btree redo item types: map, unmap,
1162306a36Sopenharmony_ci * and convert.  The common abbreviations for these are RUI (rmap update
1262306a36Sopenharmony_ci * intent) and RUD (rmap update done).  The redo item type is encoded in the
1362306a36Sopenharmony_ci * flags field of each xfs_map_extent.
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * *I items should be recorded in the *first* of a series of rolled
1662306a36Sopenharmony_ci * transactions, and the *D items should be recorded in the same transaction
1762306a36Sopenharmony_ci * that records the associated rmapbt updates.  Typically, the first
1862306a36Sopenharmony_ci * transaction will record a bmbt update, followed by some number of
1962306a36Sopenharmony_ci * transactions containing rmapbt updates, and finally transactions with any
2062306a36Sopenharmony_ci * bnobt/cntbt updates.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Should the system crash after the commit of the first transaction but
2362306a36Sopenharmony_ci * before the commit of the final transaction in a series, log recovery will
2462306a36Sopenharmony_ci * use the redo information recorded by the intent items to replay the
2562306a36Sopenharmony_ci * (rmapbt/bnobt/cntbt) metadata updates in the non-first transaction.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* kernel only RUI/RUD definitions */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistruct xfs_mount;
3162306a36Sopenharmony_cistruct kmem_cache;
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/*
3462306a36Sopenharmony_ci * Max number of extents in fast allocation path.
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_ci#define	XFS_RUI_MAX_FAST_EXTENTS	16
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/*
3962306a36Sopenharmony_ci * This is the "rmap update intent" log item.  It is used to log the fact that
4062306a36Sopenharmony_ci * some reverse mappings need to change.  It is used in conjunction with the
4162306a36Sopenharmony_ci * "rmap update done" log item described below.
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * These log items follow the same rules as struct xfs_efi_log_item; see the
4462306a36Sopenharmony_ci * comments about that structure (in xfs_extfree_item.h) for more details.
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_cistruct xfs_rui_log_item {
4762306a36Sopenharmony_ci	struct xfs_log_item		rui_item;
4862306a36Sopenharmony_ci	atomic_t			rui_refcount;
4962306a36Sopenharmony_ci	atomic_t			rui_next_extent;
5062306a36Sopenharmony_ci	struct xfs_rui_log_format	rui_format;
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistatic inline size_t
5462306a36Sopenharmony_cixfs_rui_log_item_sizeof(
5562306a36Sopenharmony_ci	unsigned int		nr)
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci	return offsetof(struct xfs_rui_log_item, rui_format) +
5862306a36Sopenharmony_ci			xfs_rui_log_format_sizeof(nr);
5962306a36Sopenharmony_ci}
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/*
6262306a36Sopenharmony_ci * This is the "rmap update done" log item.  It is used to log the fact that
6362306a36Sopenharmony_ci * some rmapbt updates mentioned in an earlier rui item have been performed.
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_cistruct xfs_rud_log_item {
6662306a36Sopenharmony_ci	struct xfs_log_item		rud_item;
6762306a36Sopenharmony_ci	struct xfs_rui_log_item		*rud_ruip;
6862306a36Sopenharmony_ci	struct xfs_rud_log_format	rud_format;
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciextern struct kmem_cache	*xfs_rui_cache;
7262306a36Sopenharmony_ciextern struct kmem_cache	*xfs_rud_cache;
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#endif	/* __XFS_RMAP_ITEM_H__ */
75