xfs_log_recover.h 4.7 KB

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