^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2016 Oracle. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Darrick J. Wong <darrick.wong@oracle.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __XFS_DEFER_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __XFS_DEFER_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) struct xfs_btree_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) struct xfs_defer_op_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct xfs_defer_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Header for deferred operation list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) enum xfs_defer_ops_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) XFS_DEFER_OPS_TYPE_BMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) XFS_DEFER_OPS_TYPE_REFCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) XFS_DEFER_OPS_TYPE_RMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) XFS_DEFER_OPS_TYPE_FREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) XFS_DEFER_OPS_TYPE_AGFL_FREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) XFS_DEFER_OPS_TYPE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Save a log intent item and a list of extents, so that we can replay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * whatever action had to happen to the extent list and file the log done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct xfs_defer_pending {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct list_head dfp_list; /* pending items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct list_head dfp_work; /* work items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct xfs_log_item *dfp_intent; /* log intent item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct xfs_log_item *dfp_done; /* log done item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned int dfp_count; /* # extent items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) enum xfs_defer_ops_type dfp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct list_head *h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int xfs_defer_finish_noroll(struct xfs_trans **tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int xfs_defer_finish(struct xfs_trans **tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void xfs_defer_cancel(struct xfs_trans *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* Description of a deferred type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct xfs_defer_op_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct xfs_log_item *(*create_intent)(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct list_head *items, unsigned int count, bool sort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void (*abort_intent)(struct xfs_log_item *intent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct xfs_log_item *(*create_done)(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct xfs_log_item *intent, unsigned int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct list_head *item, struct xfs_btree_cur **state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void (*finish_cleanup)(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct xfs_btree_cur *state, int error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void (*cancel_item)(struct list_head *item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned int max_items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern const struct xfs_defer_op_type xfs_bmap_update_defer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) extern const struct xfs_defer_op_type xfs_extent_free_defer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * This structure enables a dfops user to detach the chain of deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * operations from a transaction so that they can be continued later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct xfs_defer_capture {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* List of other capture structures. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct list_head dfc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* Deferred ops state saved from the transaction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct list_head dfc_dfops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned int dfc_tpflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Block reservations for the data and rt devices. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned int dfc_blkres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned int dfc_rtxres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Log reservation saved from the transaction. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) unsigned int dfc_logres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * An inode reference that must be maintained to complete the deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct xfs_inode *dfc_capture_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Functions to capture a chain of deferred operations and continue them later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * This doesn't normally happen except log recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct xfs_inode *capture_ip, struct list_head *capture_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct xfs_inode **captured_ipp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) void xfs_defer_ops_release(struct xfs_mount *mp, struct xfs_defer_capture *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif /* __XFS_DEFER_H__ */