xfs_log_format.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_LOG_FORMAT_H__
  19. #define __XFS_LOG_FORMAT_H__
  20. typedef __uint32_t xlog_tid_t;
  21. #define XLOG_MIN_ICLOGS 2
  22. #define XLOG_MAX_ICLOGS 8
  23. #define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe /* Invalid cycle number */
  24. #define XLOG_VERSION_1 1
  25. #define XLOG_VERSION_2 2 /* Large IClogs, Log sunit */
  26. #define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
  27. #define XLOG_MIN_RECORD_BSIZE (16*1024) /* eventually 32k */
  28. #define XLOG_BIG_RECORD_BSIZE (32*1024) /* 32k buffers */
  29. #define XLOG_MAX_RECORD_BSIZE (256*1024)
  30. #define XLOG_HEADER_CYCLE_SIZE (32*1024) /* cycle data in header */
  31. #define XLOG_MIN_RECORD_BSHIFT 14 /* 16384 == 1 << 14 */
  32. #define XLOG_BIG_RECORD_BSHIFT 15 /* 32k == 1 << 15 */
  33. #define XLOG_MAX_RECORD_BSHIFT 18 /* 256k == 1 << 18 */
  34. #define XLOG_BTOLSUNIT(log, b) (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
  35. (log)->l_mp->m_sb.sb_logsunit)
  36. #define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
  37. #define XLOG_HEADER_SIZE 512
  38. #define XLOG_REC_SHIFT(log) \
  39. BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
  40. XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
  41. #define XLOG_TOTAL_REC_SHIFT(log) \
  42. BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
  43. XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
  44. /* get lsn fields */
  45. #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
  46. #define BLOCK_LSN(lsn) ((uint)(lsn))
  47. /* this is used in a spot where we might otherwise double-endian-flip */
  48. #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
  49. static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
  50. {
  51. return ((xfs_lsn_t)cycle << 32) | block;
  52. }
  53. static inline uint xlog_get_cycle(char *ptr)
  54. {
  55. if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
  56. return be32_to_cpu(*((__be32 *)ptr + 1));
  57. else
  58. return be32_to_cpu(*(__be32 *)ptr);
  59. }
  60. /* Log Clients */
  61. #define XFS_TRANSACTION 0x69
  62. #define XFS_VOLUME 0x2
  63. #define XFS_LOG 0xaa
  64. #define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */
  65. /* Region types for iovec's i_type */
  66. #define XLOG_REG_TYPE_BFORMAT 1
  67. #define XLOG_REG_TYPE_BCHUNK 2
  68. #define XLOG_REG_TYPE_EFI_FORMAT 3
  69. #define XLOG_REG_TYPE_EFD_FORMAT 4
  70. #define XLOG_REG_TYPE_IFORMAT 5
  71. #define XLOG_REG_TYPE_ICORE 6
  72. #define XLOG_REG_TYPE_IEXT 7
  73. #define XLOG_REG_TYPE_IBROOT 8
  74. #define XLOG_REG_TYPE_ILOCAL 9
  75. #define XLOG_REG_TYPE_IATTR_EXT 10
  76. #define XLOG_REG_TYPE_IATTR_BROOT 11
  77. #define XLOG_REG_TYPE_IATTR_LOCAL 12
  78. #define XLOG_REG_TYPE_QFORMAT 13
  79. #define XLOG_REG_TYPE_DQUOT 14
  80. #define XLOG_REG_TYPE_QUOTAOFF 15
  81. #define XLOG_REG_TYPE_LRHEADER 16
  82. #define XLOG_REG_TYPE_UNMOUNT 17
  83. #define XLOG_REG_TYPE_COMMIT 18
  84. #define XLOG_REG_TYPE_TRANSHDR 19
  85. #define XLOG_REG_TYPE_ICREATE 20
  86. #define XLOG_REG_TYPE_MAX 20
  87. /*
  88. * Flags to log operation header
  89. *
  90. * The first write of a new transaction will be preceded with a start
  91. * record, XLOG_START_TRANS. Once a transaction is committed, a commit
  92. * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
  93. * the remainder of the current active in-core log, it is split up into
  94. * multiple regions. Each partial region will be marked with a
  95. * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
  96. *
  97. */
  98. #define XLOG_START_TRANS 0x01 /* Start a new transaction */
  99. #define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
  100. #define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
  101. #define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
  102. #define XLOG_END_TRANS 0x10 /* End a continued transaction */
  103. #define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
  104. typedef struct xlog_op_header {
  105. __be32 oh_tid; /* transaction id of operation : 4 b */
  106. __be32 oh_len; /* bytes in data region : 4 b */
  107. __u8 oh_clientid; /* who sent me this : 1 b */
  108. __u8 oh_flags; /* : 1 b */
  109. __u16 oh_res2; /* 32 bit align : 2 b */
  110. } xlog_op_header_t;
  111. /* valid values for h_fmt */
  112. #define XLOG_FMT_UNKNOWN 0
  113. #define XLOG_FMT_LINUX_LE 1
  114. #define XLOG_FMT_LINUX_BE 2
  115. #define XLOG_FMT_IRIX_BE 3
  116. /* our fmt */
  117. #ifdef XFS_NATIVE_HOST
  118. #define XLOG_FMT XLOG_FMT_LINUX_BE
  119. #else
  120. #define XLOG_FMT XLOG_FMT_LINUX_LE
  121. #endif
  122. typedef struct xlog_rec_header {
  123. __be32 h_magicno; /* log record (LR) identifier : 4 */
  124. __be32 h_cycle; /* write cycle of log : 4 */
  125. __be32 h_version; /* LR version : 4 */
  126. __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
  127. __be64 h_lsn; /* lsn of this LR : 8 */
  128. __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
  129. __le32 h_crc; /* crc of log record : 4 */
  130. __be32 h_prev_block; /* block number to previous LR : 4 */
  131. __be32 h_num_logops; /* number of log operations in this LR : 4 */
  132. __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
  133. /* new fields */
  134. __be32 h_fmt; /* format of log record : 4 */
  135. uuid_t h_fs_uuid; /* uuid of FS : 16 */
  136. __be32 h_size; /* iclog size : 4 */
  137. } xlog_rec_header_t;
  138. typedef struct xlog_rec_ext_header {
  139. __be32 xh_cycle; /* write cycle of log : 4 */
  140. __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /* : 256 */
  141. } xlog_rec_ext_header_t;
  142. /*
  143. * Quite misnamed, because this union lays out the actual on-disk log buffer.
  144. */
  145. typedef union xlog_in_core2 {
  146. xlog_rec_header_t hic_header;
  147. xlog_rec_ext_header_t hic_xheader;
  148. char hic_sector[XLOG_HEADER_SIZE];
  149. } xlog_in_core_2_t;
  150. /* not an on-disk structure, but needed by log recovery in userspace */
  151. typedef struct xfs_log_iovec {
  152. void *i_addr; /* beginning address of region */
  153. int i_len; /* length in bytes of region */
  154. uint i_type; /* type of region */
  155. } xfs_log_iovec_t;
  156. #endif /* __XFS_LOG_FORMAT_H__ */