1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (c) 2000,2005 Silicon Graphics, Inc. 4*4882a593Smuzhiyun * All Rights Reserved. 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun #ifndef __XFS_LOG_RECOVER_H__ 7*4882a593Smuzhiyun #define __XFS_LOG_RECOVER_H__ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun /* 10*4882a593Smuzhiyun * Each log item type (XFS_LI_*) gets its own xlog_recover_item_ops to 11*4882a593Smuzhiyun * define how recovery should work for that type of log item. 12*4882a593Smuzhiyun */ 13*4882a593Smuzhiyun struct xlog_recover_item; 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun /* Sorting hat for log items as they're read in. */ 16*4882a593Smuzhiyun enum xlog_recover_reorder { 17*4882a593Smuzhiyun XLOG_REORDER_BUFFER_LIST, 18*4882a593Smuzhiyun XLOG_REORDER_ITEM_LIST, 19*4882a593Smuzhiyun XLOG_REORDER_INODE_BUFFER_LIST, 20*4882a593Smuzhiyun XLOG_REORDER_CANCEL_LIST, 21*4882a593Smuzhiyun }; 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun struct xlog_recover_item_ops { 24*4882a593Smuzhiyun uint16_t item_type; /* XFS_LI_* type code. */ 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun /* 27*4882a593Smuzhiyun * Help sort recovered log items into the order required to replay them 28*4882a593Smuzhiyun * correctly. Log item types that always use XLOG_REORDER_ITEM_LIST do 29*4882a593Smuzhiyun * not have to supply a function here. See the comment preceding 30*4882a593Smuzhiyun * xlog_recover_reorder_trans for more details about what the return 31*4882a593Smuzhiyun * values mean. 32*4882a593Smuzhiyun */ 33*4882a593Smuzhiyun enum xlog_recover_reorder (*reorder)(struct xlog_recover_item *item); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /* Start readahead for pass2, if provided. */ 36*4882a593Smuzhiyun void (*ra_pass2)(struct xlog *log, struct xlog_recover_item *item); 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun /* Do whatever work we need to do for pass1, if provided. */ 39*4882a593Smuzhiyun int (*commit_pass1)(struct xlog *log, struct xlog_recover_item *item); 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* 42*4882a593Smuzhiyun * This function should do whatever work is needed for pass2 of log 43*4882a593Smuzhiyun * recovery, if provided. 44*4882a593Smuzhiyun * 45*4882a593Smuzhiyun * If the recovered item is an intent item, this function should parse 46*4882a593Smuzhiyun * the recovered item to construct an in-core log intent item and 47*4882a593Smuzhiyun * insert it into the AIL. The in-core log intent item should have 1 48*4882a593Smuzhiyun * refcount so that the item is freed either (a) when we commit the 49*4882a593Smuzhiyun * recovered log item for the intent-done item; (b) replay the work and 50*4882a593Smuzhiyun * log a new intent-done item; or (c) recovery fails and we have to 51*4882a593Smuzhiyun * abort. 52*4882a593Smuzhiyun * 53*4882a593Smuzhiyun * If the recovered item is an intent-done item, this function should 54*4882a593Smuzhiyun * parse the recovered item to find the id of the corresponding intent 55*4882a593Smuzhiyun * log item. Next, it should find the in-core log intent item in the 56*4882a593Smuzhiyun * AIL and release it. 57*4882a593Smuzhiyun */ 58*4882a593Smuzhiyun int (*commit_pass2)(struct xlog *log, struct list_head *buffer_list, 59*4882a593Smuzhiyun struct xlog_recover_item *item, xfs_lsn_t lsn); 60*4882a593Smuzhiyun }; 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_icreate_item_ops; 63*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_buf_item_ops; 64*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_inode_item_ops; 65*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_dquot_item_ops; 66*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_quotaoff_item_ops; 67*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_bui_item_ops; 68*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_bud_item_ops; 69*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_efi_item_ops; 70*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_efd_item_ops; 71*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_rui_item_ops; 72*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_rud_item_ops; 73*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_cui_item_ops; 74*4882a593Smuzhiyun extern const struct xlog_recover_item_ops xlog_cud_item_ops; 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun /* 77*4882a593Smuzhiyun * Macros, structures, prototypes for internal log manager use. 78*4882a593Smuzhiyun */ 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun #define XLOG_RHASH_BITS 4 81*4882a593Smuzhiyun #define XLOG_RHASH_SIZE 16 82*4882a593Smuzhiyun #define XLOG_RHASH_SHIFT 2 83*4882a593Smuzhiyun #define XLOG_RHASH(tid) \ 84*4882a593Smuzhiyun ((((uint32_t)tid)>>XLOG_RHASH_SHIFT) & (XLOG_RHASH_SIZE-1)) 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun #define XLOG_MAX_REGIONS_IN_ITEM (XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK / 2 + 1) 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun /* 90*4882a593Smuzhiyun * item headers are in ri_buf[0]. Additional buffers follow. 91*4882a593Smuzhiyun */ 92*4882a593Smuzhiyun struct xlog_recover_item { 93*4882a593Smuzhiyun struct list_head ri_list; 94*4882a593Smuzhiyun int ri_cnt; /* count of regions found */ 95*4882a593Smuzhiyun int ri_total; /* total regions */ 96*4882a593Smuzhiyun struct xfs_log_iovec *ri_buf; /* ptr to regions buffer */ 97*4882a593Smuzhiyun const struct xlog_recover_item_ops *ri_ops; 98*4882a593Smuzhiyun }; 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun struct xlog_recover { 101*4882a593Smuzhiyun struct hlist_node r_list; 102*4882a593Smuzhiyun xlog_tid_t r_log_tid; /* log's transaction id */ 103*4882a593Smuzhiyun xfs_trans_header_t r_theader; /* trans header for partial */ 104*4882a593Smuzhiyun int r_state; /* not needed */ 105*4882a593Smuzhiyun xfs_lsn_t r_lsn; /* xact lsn */ 106*4882a593Smuzhiyun struct list_head r_itemq; /* q for items */ 107*4882a593Smuzhiyun }; 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun #define ITEM_TYPE(i) (*(unsigned short *)(i)->ri_buf[0].i_addr) 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun /* 112*4882a593Smuzhiyun * This is the number of entries in the l_buf_cancel_table used during 113*4882a593Smuzhiyun * recovery. 114*4882a593Smuzhiyun */ 115*4882a593Smuzhiyun #define XLOG_BC_TABLE_SIZE 64 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun #define XLOG_RECOVER_CRCPASS 0 118*4882a593Smuzhiyun #define XLOG_RECOVER_PASS1 1 119*4882a593Smuzhiyun #define XLOG_RECOVER_PASS2 2 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun void xlog_buf_readahead(struct xlog *log, xfs_daddr_t blkno, uint len, 122*4882a593Smuzhiyun const struct xfs_buf_ops *ops); 123*4882a593Smuzhiyun bool xlog_is_buffer_cancelled(struct xlog *log, xfs_daddr_t blkno, uint len); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun void xlog_recover_release_intent(struct xlog *log, unsigned short intent_type, 126*4882a593Smuzhiyun uint64_t intent_id); 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun #endif /* __XFS_LOG_RECOVER_H__ */ 129