18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2000,2005 Silicon Graphics, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_LOG_RECOVER_H__ 78c2ecf20Sopenharmony_ci#define __XFS_LOG_RECOVER_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Each log item type (XFS_LI_*) gets its own xlog_recover_item_ops to 118c2ecf20Sopenharmony_ci * define how recovery should work for that type of log item. 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_cistruct xlog_recover_item; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* Sorting hat for log items as they're read in. */ 168c2ecf20Sopenharmony_cienum xlog_recover_reorder { 178c2ecf20Sopenharmony_ci XLOG_REORDER_BUFFER_LIST, 188c2ecf20Sopenharmony_ci XLOG_REORDER_ITEM_LIST, 198c2ecf20Sopenharmony_ci XLOG_REORDER_INODE_BUFFER_LIST, 208c2ecf20Sopenharmony_ci XLOG_REORDER_CANCEL_LIST, 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct xlog_recover_item_ops { 248c2ecf20Sopenharmony_ci uint16_t item_type; /* XFS_LI_* type code. */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci /* 278c2ecf20Sopenharmony_ci * Help sort recovered log items into the order required to replay them 288c2ecf20Sopenharmony_ci * correctly. Log item types that always use XLOG_REORDER_ITEM_LIST do 298c2ecf20Sopenharmony_ci * not have to supply a function here. See the comment preceding 308c2ecf20Sopenharmony_ci * xlog_recover_reorder_trans for more details about what the return 318c2ecf20Sopenharmony_ci * values mean. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci enum xlog_recover_reorder (*reorder)(struct xlog_recover_item *item); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* Start readahead for pass2, if provided. */ 368c2ecf20Sopenharmony_ci void (*ra_pass2)(struct xlog *log, struct xlog_recover_item *item); 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci /* Do whatever work we need to do for pass1, if provided. */ 398c2ecf20Sopenharmony_ci int (*commit_pass1)(struct xlog *log, struct xlog_recover_item *item); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci /* 428c2ecf20Sopenharmony_ci * This function should do whatever work is needed for pass2 of log 438c2ecf20Sopenharmony_ci * recovery, if provided. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * If the recovered item is an intent item, this function should parse 468c2ecf20Sopenharmony_ci * the recovered item to construct an in-core log intent item and 478c2ecf20Sopenharmony_ci * insert it into the AIL. The in-core log intent item should have 1 488c2ecf20Sopenharmony_ci * refcount so that the item is freed either (a) when we commit the 498c2ecf20Sopenharmony_ci * recovered log item for the intent-done item; (b) replay the work and 508c2ecf20Sopenharmony_ci * log a new intent-done item; or (c) recovery fails and we have to 518c2ecf20Sopenharmony_ci * abort. 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * If the recovered item is an intent-done item, this function should 548c2ecf20Sopenharmony_ci * parse the recovered item to find the id of the corresponding intent 558c2ecf20Sopenharmony_ci * log item. Next, it should find the in-core log intent item in the 568c2ecf20Sopenharmony_ci * AIL and release it. 578c2ecf20Sopenharmony_ci */ 588c2ecf20Sopenharmony_ci int (*commit_pass2)(struct xlog *log, struct list_head *buffer_list, 598c2ecf20Sopenharmony_ci struct xlog_recover_item *item, xfs_lsn_t lsn); 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_icreate_item_ops; 638c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_buf_item_ops; 648c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_inode_item_ops; 658c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_dquot_item_ops; 668c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_quotaoff_item_ops; 678c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_bui_item_ops; 688c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_bud_item_ops; 698c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_efi_item_ops; 708c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_efd_item_ops; 718c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_rui_item_ops; 728c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_rud_item_ops; 738c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_cui_item_ops; 748c2ecf20Sopenharmony_ciextern const struct xlog_recover_item_ops xlog_cud_item_ops; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* 778c2ecf20Sopenharmony_ci * Macros, structures, prototypes for internal log manager use. 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define XLOG_RHASH_BITS 4 818c2ecf20Sopenharmony_ci#define XLOG_RHASH_SIZE 16 828c2ecf20Sopenharmony_ci#define XLOG_RHASH_SHIFT 2 838c2ecf20Sopenharmony_ci#define XLOG_RHASH(tid) \ 848c2ecf20Sopenharmony_ci ((((uint32_t)tid)>>XLOG_RHASH_SHIFT) & (XLOG_RHASH_SIZE-1)) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define XLOG_MAX_REGIONS_IN_ITEM (XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK / 2 + 1) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* 908c2ecf20Sopenharmony_ci * item headers are in ri_buf[0]. Additional buffers follow. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_cistruct xlog_recover_item { 938c2ecf20Sopenharmony_ci struct list_head ri_list; 948c2ecf20Sopenharmony_ci int ri_cnt; /* count of regions found */ 958c2ecf20Sopenharmony_ci int ri_total; /* total regions */ 968c2ecf20Sopenharmony_ci struct xfs_log_iovec *ri_buf; /* ptr to regions buffer */ 978c2ecf20Sopenharmony_ci const struct xlog_recover_item_ops *ri_ops; 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct xlog_recover { 1018c2ecf20Sopenharmony_ci struct hlist_node r_list; 1028c2ecf20Sopenharmony_ci xlog_tid_t r_log_tid; /* log's transaction id */ 1038c2ecf20Sopenharmony_ci xfs_trans_header_t r_theader; /* trans header for partial */ 1048c2ecf20Sopenharmony_ci int r_state; /* not needed */ 1058c2ecf20Sopenharmony_ci xfs_lsn_t r_lsn; /* xact lsn */ 1068c2ecf20Sopenharmony_ci struct list_head r_itemq; /* q for items */ 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define ITEM_TYPE(i) (*(unsigned short *)(i)->ri_buf[0].i_addr) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/* 1128c2ecf20Sopenharmony_ci * This is the number of entries in the l_buf_cancel_table used during 1138c2ecf20Sopenharmony_ci * recovery. 1148c2ecf20Sopenharmony_ci */ 1158c2ecf20Sopenharmony_ci#define XLOG_BC_TABLE_SIZE 64 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define XLOG_RECOVER_CRCPASS 0 1188c2ecf20Sopenharmony_ci#define XLOG_RECOVER_PASS1 1 1198c2ecf20Sopenharmony_ci#define XLOG_RECOVER_PASS2 2 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_civoid xlog_buf_readahead(struct xlog *log, xfs_daddr_t blkno, uint len, 1228c2ecf20Sopenharmony_ci const struct xfs_buf_ops *ops); 1238c2ecf20Sopenharmony_cibool xlog_is_buffer_cancelled(struct xlog *log, xfs_daddr_t blkno, uint len); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_civoid xlog_recover_release_intent(struct xlog *log, unsigned short intent_type, 1268c2ecf20Sopenharmony_ci uint64_t intent_id); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#endif /* __XFS_LOG_RECOVER_H__ */ 129