brintos

brintos / linux-shallow public Read only

0
0
Text · 5.4 KiB · 8b33803 Raw
163 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ */2/*3 * Copyright (C) 2016 Oracle.  All Rights Reserved.4 * Author: Darrick J. Wong <darrick.wong@oracle.com>5 */6#ifndef __XFS_DEFER_H__7#define	__XFS_DEFER_H__8 9struct xfs_btree_cur;10struct xfs_defer_op_type;11struct xfs_defer_capture;12 13/*14 * Save a log intent item and a list of extents, so that we can replay15 * whatever action had to happen to the extent list and file the log done16 * item.17 */18struct xfs_defer_pending {19	struct list_head		dfp_list;	/* pending items */20	struct list_head		dfp_work;	/* work items */21	struct xfs_log_item		*dfp_intent;	/* log intent item */22	struct xfs_log_item		*dfp_done;	/* log done item */23	const struct xfs_defer_op_type	*dfp_ops;24	unsigned int			dfp_count;	/* # extent items */25	unsigned int			dfp_flags;26};27 28/*29 * Create a log intent item for this deferred item, but don't actually finish30 * the work.  Caller must clear this before the final transaction commit.31 */32#define XFS_DEFER_PAUSED	(1U << 0)33 34#define XFS_DEFER_PENDING_STRINGS \35	{ XFS_DEFER_PAUSED,	"paused" }36 37void xfs_defer_item_pause(struct xfs_trans *tp, struct xfs_defer_pending *dfp);38void xfs_defer_item_unpause(struct xfs_trans *tp, struct xfs_defer_pending *dfp);39 40struct xfs_defer_pending *xfs_defer_add(struct xfs_trans *tp, struct list_head *h,41		const struct xfs_defer_op_type *ops);42int xfs_defer_finish_noroll(struct xfs_trans **tp);43int xfs_defer_finish(struct xfs_trans **tp);44int xfs_defer_finish_one(struct xfs_trans *tp, struct xfs_defer_pending *dfp);45void xfs_defer_cancel(struct xfs_trans *);46void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp);47 48/* Description of a deferred type. */49struct xfs_defer_op_type {50	const char		*name;51	unsigned int		max_items;52	struct xfs_log_item *(*create_intent)(struct xfs_trans *tp,53			struct list_head *items, unsigned int count, bool sort);54	void (*abort_intent)(struct xfs_log_item *intent);55	struct xfs_log_item *(*create_done)(struct xfs_trans *tp,56			struct xfs_log_item *intent, unsigned int count);57	int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done,58			struct list_head *item, struct xfs_btree_cur **state);59	void (*finish_cleanup)(struct xfs_trans *tp,60			struct xfs_btree_cur *state, int error);61	void (*cancel_item)(struct list_head *item);62	int (*recover_work)(struct xfs_defer_pending *dfp,63			    struct list_head *capture_list);64	struct xfs_log_item *(*relog_intent)(struct xfs_trans *tp,65			struct xfs_log_item *intent,66			struct xfs_log_item *done_item);67};68 69extern const struct xfs_defer_op_type xfs_bmap_update_defer_type;70extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;71extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;72extern const struct xfs_defer_op_type xfs_extent_free_defer_type;73extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;74extern const struct xfs_defer_op_type xfs_attr_defer_type;75extern const struct xfs_defer_op_type xfs_exchmaps_defer_type;76 77/*78 * Deferred operation item relogging limits.79 */80 81/*82 * Rename w/ parent pointers can require up to 5 inodes with deferred ops to83 * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip.84 * These inodes are locked in sorted order by their inode numbers85 */86#define XFS_DEFER_OPS_NR_INODES	587#define XFS_DEFER_OPS_NR_BUFS	2	/* join up to two buffers */88 89/* Resources that must be held across a transaction roll. */90struct xfs_defer_resources {91	/* held buffers */92	struct xfs_buf		*dr_bp[XFS_DEFER_OPS_NR_BUFS];93 94	/* inodes with no unlock flags */95	struct xfs_inode	*dr_ip[XFS_DEFER_OPS_NR_INODES];96 97	/* number of held buffers */98	unsigned short		dr_bufs;99 100	/* bitmap of ordered buffers */101	unsigned short		dr_ordered;102 103	/* number of held inodes */104	unsigned short		dr_inos;105};106 107/*108 * This structure enables a dfops user to detach the chain of deferred109 * operations from a transaction so that they can be continued later.110 */111struct xfs_defer_capture {112	/* List of other capture structures. */113	struct list_head	dfc_list;114 115	/* Deferred ops state saved from the transaction. */116	struct list_head	dfc_dfops;117	unsigned int		dfc_tpflags;118 119	/* Block reservations for the data and rt devices. */120	unsigned int		dfc_blkres;121	unsigned int		dfc_rtxres;122 123	/* Log reservation saved from the transaction. */124	unsigned int		dfc_logres;125 126	struct xfs_defer_resources dfc_held;127};128 129/*130 * Functions to capture a chain of deferred operations and continue them later.131 * This doesn't normally happen except log recovery.132 */133int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,134		struct list_head *capture_list);135void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,136		struct xfs_defer_resources *dres);137void xfs_defer_ops_capture_abort(struct xfs_mount *mp,138		struct xfs_defer_capture *d);139void xfs_defer_resources_rele(struct xfs_defer_resources *dres);140 141void xfs_defer_start_recovery(struct xfs_log_item *lip,142		struct list_head *r_dfops, const struct xfs_defer_op_type *ops);143void xfs_defer_cancel_recovery(struct xfs_mount *mp,144		struct xfs_defer_pending *dfp);145int xfs_defer_finish_recovery(struct xfs_mount *mp,146		struct xfs_defer_pending *dfp, struct list_head *capture_list);147 148static inline void149xfs_defer_add_item(150	struct xfs_defer_pending	*dfp,151	struct list_head		*work)152{153	list_add_tail(work, &dfp->dfp_work);154	dfp->dfp_count++;155}156 157int __init xfs_defer_init_item_caches(void);158void xfs_defer_destroy_item_caches(void);159 160void xfs_defer_add_barrier(struct xfs_trans *tp);161 162#endif /* __XFS_DEFER_H__ */163