Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|---|
| 2 | /* |
| 3 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
| 5 | */ |
| 6 | #ifndef __XFS_LOG_RECOVER_H__ |
| 7 | #define __XFS_LOG_RECOVER_H__ |
| 8 | |
| 9 | /* |
| 10 | * Each log item type (XFS_LI_*) gets its own xlog_recover_item_ops to |
| 11 | * define how recovery should work for that type of log item. |
| 12 | */ |
| 13 | struct xlog_recover_item; |
| 14 | struct xfs_defer_op_type; |
| 15 | |
| 16 | /* Sorting hat for log items as they're read in. */ |
| 17 | enum xlog_recover_reorder { |
| 18 | XLOG_REORDER_BUFFER_LIST, |
| 19 | XLOG_REORDER_ITEM_LIST, |
| 20 | XLOG_REORDER_INODE_BUFFER_LIST, |
| 21 | XLOG_REORDER_CANCEL_LIST, |
| 22 | }; |
| 23 | |
| 24 | struct xlog_recover_item_ops { |
| 25 | uint16_t item_type; /* XFS_LI_* type code. */ |
| 26 | |
| 27 | /* |
| 28 | * Help sort recovered log items into the order required to replay them |
| 29 | * correctly. Log item types that always use XLOG_REORDER_ITEM_LIST do |
| 30 | * not have to supply a function here. See the comment preceding |
| 31 | * xlog_recover_reorder_trans for more details about what the return |
| 32 | * values mean. |
| 33 | */ |
| 34 | enum xlog_recover_reorder (*reorder)(struct xlog_recover_item *item); |
| 35 | |
| 36 | /* Start readahead for pass2, if provided. */ |
| 37 | void (*ra_pass2)(struct xlog *log, struct xlog_recover_item *item); |
| 38 | |
| 39 | /* Do whatever work we need to do for pass1, if provided. */ |
| 40 | int (*commit_pass1)(struct xlog *log, struct xlog_recover_item *item); |
| 41 | |
| 42 | /* |
| 43 | * This function should do whatever work is needed for pass2 of log |
| 44 | * recovery, if provided. |
| 45 | * |
| 46 | * If the recovered item is an intent item, this function should parse |
| 47 | * the recovered item to construct an in-core log intent item and |
| 48 | * insert it into the AIL. The in-core log intent item should have 1 |
| 49 | * refcount so that the item is freed either (a) when we commit the |
| 50 | * recovered log item for the intent-done item; (b) replay the work and |
| 51 | * log a new intent-done item; or (c) recovery fails and we have to |
| 52 | * abort. |
| 53 | * |
| 54 | * If the recovered item is an intent-done item, this function should |
| 55 | * parse the recovered item to find the id of the corresponding intent |
| 56 | * log item. Next, it should find the in-core log intent item in the |
| 57 | * AIL and release it. |
| 58 | */ |
| 59 | int (*commit_pass2)(struct xlog *log, struct list_head *buffer_list, |
| 60 | struct xlog_recover_item *item, xfs_lsn_t lsn); |
| 61 | }; |
| 62 | |
| 63 | extern const struct xlog_recover_item_ops xlog_icreate_item_ops; |
| 64 | extern const struct xlog_recover_item_ops xlog_buf_item_ops; |
| 65 | extern const struct xlog_recover_item_ops xlog_inode_item_ops; |
| 66 | extern const struct xlog_recover_item_ops xlog_dquot_item_ops; |
| 67 | extern const struct xlog_recover_item_ops xlog_quotaoff_item_ops; |
| 68 | extern const struct xlog_recover_item_ops xlog_bui_item_ops; |
| 69 | extern const struct xlog_recover_item_ops xlog_bud_item_ops; |
| 70 | extern const struct xlog_recover_item_ops xlog_efi_item_ops; |
| 71 | extern const struct xlog_recover_item_ops xlog_efd_item_ops; |
| 72 | extern const struct xlog_recover_item_ops xlog_rui_item_ops; |
| 73 | extern const struct xlog_recover_item_ops xlog_rud_item_ops; |
| 74 | extern const struct xlog_recover_item_ops xlog_cui_item_ops; |
| 75 | extern const struct xlog_recover_item_ops xlog_cud_item_ops; |
| 76 | extern const struct xlog_recover_item_ops xlog_attri_item_ops; |
| 77 | extern const struct xlog_recover_item_ops xlog_attrd_item_ops; |
| 78 | extern const struct xlog_recover_item_ops xlog_xmi_item_ops; |
| 79 | extern const struct xlog_recover_item_ops xlog_xmd_item_ops; |
| 80 | extern const struct xlog_recover_item_ops xlog_rtefi_item_ops; |
| 81 | extern const struct xlog_recover_item_ops xlog_rtefd_item_ops; |
| 82 | extern const struct xlog_recover_item_ops xlog_rtrui_item_ops; |
| 83 | extern const struct xlog_recover_item_ops xlog_rtrud_item_ops; |
| 84 | extern const struct xlog_recover_item_ops xlog_rtcui_item_ops; |
| 85 | extern const struct xlog_recover_item_ops xlog_rtcud_item_ops; |
| 86 | |
| 87 | /* |
| 88 | * Macros, structures, prototypes for internal log manager use. |
| 89 | */ |
| 90 | |
| 91 | #define XLOG_RHASH_BITS 4 |
| 92 | #define XLOG_RHASH_SIZE 16 |
| 93 | #define XLOG_RHASH_SHIFT 2 |
| 94 | #define XLOG_RHASH(tid) \ |
| 95 | ((((uint32_t)tid)>>XLOG_RHASH_SHIFT) & (XLOG_RHASH_SIZE-1)) |
| 96 | |
| 97 | #define XLOG_MAX_REGIONS_IN_ITEM (XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK / 2 + 1) |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | * item headers are in ri_buf[0]. Additional buffers follow. |
| 102 | */ |
| 103 | struct xlog_recover_item { |
| 104 | struct list_head ri_list; |
| 105 | int ri_cnt; /* count of regions found */ |
| 106 | int ri_total; /* total regions */ |
| 107 | struct kvec *ri_buf; /* ptr to regions buffer */ |
| 108 | const struct xlog_recover_item_ops *ri_ops; |
| 109 | }; |
| 110 | |
| 111 | struct xlog_recover { |
| 112 | struct hlist_node r_list; |
| 113 | xlog_tid_t r_log_tid; /* log's transaction id */ |
| 114 | struct xfs_trans_header r_theader; /* trans header for partial */ |
| 115 | int r_state; /* not needed */ |
| 116 | xfs_lsn_t r_lsn; /* xact lsn */ |
| 117 | struct list_head r_itemq; /* q for items */ |
| 118 | }; |
| 119 | |
| 120 | #define ITEM_TYPE(i) (*(unsigned short *)(i)->ri_buf[0].iov_base) |
| 121 | |
| 122 | #define XLOG_RECOVER_CRCPASS 0 |
| 123 | #define XLOG_RECOVER_PASS1 1 |
| 124 | #define XLOG_RECOVER_PASS2 2 |
| 125 | |
| 126 | void xlog_buf_readahead(struct xlog *log, xfs_daddr_t blkno, uint len, |
| 127 | const struct xfs_buf_ops *ops); |
| 128 | bool xlog_is_buffer_cancelled(struct xlog *log, xfs_daddr_t blkno, uint len); |
| 129 | |
| 130 | int xlog_recover_iget(struct xfs_mount *mp, xfs_ino_t ino, |
| 131 | struct xfs_inode **ipp); |
| 132 | int xlog_recover_iget_handle(struct xfs_mount *mp, xfs_ino_t ino, uint32_t gen, |
| 133 | struct xfs_inode **ipp); |
| 134 | void xlog_recover_release_intent(struct xlog *log, unsigned short intent_type, |
| 135 | uint64_t intent_id); |
| 136 | int xlog_alloc_buf_cancel_table(struct xlog *log); |
| 137 | void xlog_free_buf_cancel_table(struct xlog *log); |
| 138 | |
| 139 | #ifdef DEBUG |
| 140 | void xlog_check_buf_cancel_table(struct xlog *log); |
| 141 | #else |
| 142 | #define xlog_check_buf_cancel_table(log) do { } while (0) |
| 143 | #endif |
| 144 | |
| 145 | /* |
| 146 | * Transform a regular reservation into one suitable for recovery of a log |
| 147 | * intent item. |
| 148 | * |
| 149 | * Intent recovery only runs a single step of the transaction chain and defers |
| 150 | * the rest to a separate transaction. Therefore, we reduce logcount to 1 here |
| 151 | * to avoid livelocks if the log grant space is nearly exhausted due to the |
| 152 | * recovered intent pinning the tail. Keep the same logflags to avoid tripping |
| 153 | * asserts elsewhere. Struct copies abound below. |
| 154 | */ |
| 155 | static inline struct xfs_trans_res |
| 156 | xlog_recover_resv(const struct xfs_trans_res *r) |
| 157 | { |
| 158 | struct xfs_trans_res ret = { |
| 159 | .tr_logres = r->tr_logres, |
| 160 | .tr_logcount = 1, |
| 161 | .tr_logflags = r->tr_logflags, |
| 162 | }; |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | struct xfs_defer_pending; |
| 168 | |
| 169 | void xlog_recover_intent_item(struct xlog *log, struct xfs_log_item *lip, |
| 170 | xfs_lsn_t lsn, const struct xfs_defer_op_type *ops); |
| 171 | int xlog_recover_finish_intent(struct xfs_trans *tp, |
| 172 | struct xfs_defer_pending *dfp); |
| 173 | |
| 174 | #endif /* __XFS_LOG_RECOVER_H__ */ |
| 175 |
Warning: This file is not a C or C++ file. It does not have highlighting.
