xfs_log_format.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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. /*
  21. * On-disk Log Format definitions.
  22. *
  23. * This file contains all the on-disk format definitions used within the log. It
  24. * includes the physical log structure itself, as well as all the log item
  25. * format structures that are written into the log and intepreted by log
  26. * recovery. We start with the physical log format definitions, and then work
  27. * through all the log items definitions and everything they encode into the
  28. * log.
  29. */
  30. typedef __uint32_t xlog_tid_t;
  31. #define XLOG_MIN_ICLOGS 2
  32. #define XLOG_MAX_ICLOGS 8
  33. #define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe /* Invalid cycle number */
  34. #define XLOG_VERSION_1 1
  35. #define XLOG_VERSION_2 2 /* Large IClogs, Log sunit */
  36. #define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
  37. #define XLOG_MIN_RECORD_BSIZE (16*1024) /* eventually 32k */
  38. #define XLOG_BIG_RECORD_BSIZE (32*1024) /* 32k buffers */
  39. #define XLOG_MAX_RECORD_BSIZE (256*1024)
  40. #define XLOG_HEADER_CYCLE_SIZE (32*1024) /* cycle data in header */
  41. #define XLOG_MIN_RECORD_BSHIFT 14 /* 16384 == 1 << 14 */
  42. #define XLOG_BIG_RECORD_BSHIFT 15 /* 32k == 1 << 15 */
  43. #define XLOG_MAX_RECORD_BSHIFT 18 /* 256k == 1 << 18 */
  44. #define XLOG_BTOLSUNIT(log, b) (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
  45. (log)->l_mp->m_sb.sb_logsunit)
  46. #define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
  47. #define XLOG_HEADER_SIZE 512
  48. #define XLOG_REC_SHIFT(log) \
  49. BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
  50. XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
  51. #define XLOG_TOTAL_REC_SHIFT(log) \
  52. BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
  53. XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
  54. /* get lsn fields */
  55. #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
  56. #define BLOCK_LSN(lsn) ((uint)(lsn))
  57. /* this is used in a spot where we might otherwise double-endian-flip */
  58. #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
  59. static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
  60. {
  61. return ((xfs_lsn_t)cycle << 32) | block;
  62. }
  63. static inline uint xlog_get_cycle(char *ptr)
  64. {
  65. if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
  66. return be32_to_cpu(*((__be32 *)ptr + 1));
  67. else
  68. return be32_to_cpu(*(__be32 *)ptr);
  69. }
  70. /* Log Clients */
  71. #define XFS_TRANSACTION 0x69
  72. #define XFS_VOLUME 0x2
  73. #define XFS_LOG 0xaa
  74. #define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */
  75. /* Region types for iovec's i_type */
  76. #define XLOG_REG_TYPE_BFORMAT 1
  77. #define XLOG_REG_TYPE_BCHUNK 2
  78. #define XLOG_REG_TYPE_EFI_FORMAT 3
  79. #define XLOG_REG_TYPE_EFD_FORMAT 4
  80. #define XLOG_REG_TYPE_IFORMAT 5
  81. #define XLOG_REG_TYPE_ICORE 6
  82. #define XLOG_REG_TYPE_IEXT 7
  83. #define XLOG_REG_TYPE_IBROOT 8
  84. #define XLOG_REG_TYPE_ILOCAL 9
  85. #define XLOG_REG_TYPE_IATTR_EXT 10
  86. #define XLOG_REG_TYPE_IATTR_BROOT 11
  87. #define XLOG_REG_TYPE_IATTR_LOCAL 12
  88. #define XLOG_REG_TYPE_QFORMAT 13
  89. #define XLOG_REG_TYPE_DQUOT 14
  90. #define XLOG_REG_TYPE_QUOTAOFF 15
  91. #define XLOG_REG_TYPE_LRHEADER 16
  92. #define XLOG_REG_TYPE_UNMOUNT 17
  93. #define XLOG_REG_TYPE_COMMIT 18
  94. #define XLOG_REG_TYPE_TRANSHDR 19
  95. #define XLOG_REG_TYPE_ICREATE 20
  96. #define XLOG_REG_TYPE_MAX 20
  97. /*
  98. * Flags to log operation header
  99. *
  100. * The first write of a new transaction will be preceded with a start
  101. * record, XLOG_START_TRANS. Once a transaction is committed, a commit
  102. * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
  103. * the remainder of the current active in-core log, it is split up into
  104. * multiple regions. Each partial region will be marked with a
  105. * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
  106. *
  107. */
  108. #define XLOG_START_TRANS 0x01 /* Start a new transaction */
  109. #define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
  110. #define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
  111. #define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
  112. #define XLOG_END_TRANS 0x10 /* End a continued transaction */
  113. #define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
  114. typedef struct xlog_op_header {
  115. __be32 oh_tid; /* transaction id of operation : 4 b */
  116. __be32 oh_len; /* bytes in data region : 4 b */
  117. __u8 oh_clientid; /* who sent me this : 1 b */
  118. __u8 oh_flags; /* : 1 b */
  119. __u16 oh_res2; /* 32 bit align : 2 b */
  120. } xlog_op_header_t;
  121. /* valid values for h_fmt */
  122. #define XLOG_FMT_UNKNOWN 0
  123. #define XLOG_FMT_LINUX_LE 1
  124. #define XLOG_FMT_LINUX_BE 2
  125. #define XLOG_FMT_IRIX_BE 3
  126. /* our fmt */
  127. #ifdef XFS_NATIVE_HOST
  128. #define XLOG_FMT XLOG_FMT_LINUX_BE
  129. #else
  130. #define XLOG_FMT XLOG_FMT_LINUX_LE
  131. #endif
  132. typedef struct xlog_rec_header {
  133. __be32 h_magicno; /* log record (LR) identifier : 4 */
  134. __be32 h_cycle; /* write cycle of log : 4 */
  135. __be32 h_version; /* LR version : 4 */
  136. __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
  137. __be64 h_lsn; /* lsn of this LR : 8 */
  138. __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
  139. __le32 h_crc; /* crc of log record : 4 */
  140. __be32 h_prev_block; /* block number to previous LR : 4 */
  141. __be32 h_num_logops; /* number of log operations in this LR : 4 */
  142. __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
  143. /* new fields */
  144. __be32 h_fmt; /* format of log record : 4 */
  145. uuid_t h_fs_uuid; /* uuid of FS : 16 */
  146. __be32 h_size; /* iclog size : 4 */
  147. } xlog_rec_header_t;
  148. typedef struct xlog_rec_ext_header {
  149. __be32 xh_cycle; /* write cycle of log : 4 */
  150. __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /* : 256 */
  151. } xlog_rec_ext_header_t;
  152. /*
  153. * Quite misnamed, because this union lays out the actual on-disk log buffer.
  154. */
  155. typedef union xlog_in_core2 {
  156. xlog_rec_header_t hic_header;
  157. xlog_rec_ext_header_t hic_xheader;
  158. char hic_sector[XLOG_HEADER_SIZE];
  159. } xlog_in_core_2_t;
  160. /* not an on-disk structure, but needed by log recovery in userspace */
  161. typedef struct xfs_log_iovec {
  162. void *i_addr; /* beginning address of region */
  163. int i_len; /* length in bytes of region */
  164. uint i_type; /* type of region */
  165. } xfs_log_iovec_t;
  166. /*
  167. * Transaction Header definitions.
  168. *
  169. * This is the structure written in the log at the head of every transaction. It
  170. * identifies the type and id of the transaction, and contains the number of
  171. * items logged by the transaction so we know how many to expect during
  172. * recovery.
  173. *
  174. * Do not change the below structure without redoing the code in
  175. * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
  176. */
  177. typedef struct xfs_trans_header {
  178. uint th_magic; /* magic number */
  179. uint th_type; /* transaction type */
  180. __int32_t th_tid; /* transaction id (unused) */
  181. uint th_num_items; /* num items logged by trans */
  182. } xfs_trans_header_t;
  183. #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
  184. /*
  185. * Log item types.
  186. */
  187. #define XFS_LI_EFI 0x1236
  188. #define XFS_LI_EFD 0x1237
  189. #define XFS_LI_IUNLINK 0x1238
  190. #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */
  191. #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
  192. #define XFS_LI_DQUOT 0x123d
  193. #define XFS_LI_QUOTAOFF 0x123e
  194. #define XFS_LI_ICREATE 0x123f
  195. #define XFS_LI_TYPE_DESC \
  196. { XFS_LI_EFI, "XFS_LI_EFI" }, \
  197. { XFS_LI_EFD, "XFS_LI_EFD" }, \
  198. { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
  199. { XFS_LI_INODE, "XFS_LI_INODE" }, \
  200. { XFS_LI_BUF, "XFS_LI_BUF" }, \
  201. { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
  202. { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
  203. { XFS_LI_ICREATE, "XFS_LI_ICREATE" }
  204. /*
  205. * Transaction types. Used to distinguish types of buffers.
  206. */
  207. #define XFS_TRANS_SETATTR_NOT_SIZE 1
  208. #define XFS_TRANS_SETATTR_SIZE 2
  209. #define XFS_TRANS_INACTIVE 3
  210. #define XFS_TRANS_CREATE 4
  211. #define XFS_TRANS_CREATE_TRUNC 5
  212. #define XFS_TRANS_TRUNCATE_FILE 6
  213. #define XFS_TRANS_REMOVE 7
  214. #define XFS_TRANS_LINK 8
  215. #define XFS_TRANS_RENAME 9
  216. #define XFS_TRANS_MKDIR 10
  217. #define XFS_TRANS_RMDIR 11
  218. #define XFS_TRANS_SYMLINK 12
  219. #define XFS_TRANS_SET_DMATTRS 13
  220. #define XFS_TRANS_GROWFS 14
  221. #define XFS_TRANS_STRAT_WRITE 15
  222. #define XFS_TRANS_DIOSTRAT 16
  223. /* 17 was XFS_TRANS_WRITE_SYNC */
  224. #define XFS_TRANS_WRITEID 18
  225. #define XFS_TRANS_ADDAFORK 19
  226. #define XFS_TRANS_ATTRINVAL 20
  227. #define XFS_TRANS_ATRUNCATE 21
  228. #define XFS_TRANS_ATTR_SET 22
  229. #define XFS_TRANS_ATTR_RM 23
  230. #define XFS_TRANS_ATTR_FLAG 24
  231. #define XFS_TRANS_CLEAR_AGI_BUCKET 25
  232. #define XFS_TRANS_QM_SBCHANGE 26
  233. /*
  234. * Dummy entries since we use the transaction type to index into the
  235. * trans_type[] in xlog_recover_print_trans_head()
  236. */
  237. #define XFS_TRANS_DUMMY1 27
  238. #define XFS_TRANS_DUMMY2 28
  239. #define XFS_TRANS_QM_QUOTAOFF 29
  240. #define XFS_TRANS_QM_DQALLOC 30
  241. #define XFS_TRANS_QM_SETQLIM 31
  242. #define XFS_TRANS_QM_DQCLUSTER 32
  243. #define XFS_TRANS_QM_QINOCREATE 33
  244. #define XFS_TRANS_QM_QUOTAOFF_END 34
  245. #define XFS_TRANS_SB_UNIT 35
  246. #define XFS_TRANS_FSYNC_TS 36
  247. #define XFS_TRANS_GROWFSRT_ALLOC 37
  248. #define XFS_TRANS_GROWFSRT_ZERO 38
  249. #define XFS_TRANS_GROWFSRT_FREE 39
  250. #define XFS_TRANS_SWAPEXT 40
  251. #define XFS_TRANS_SB_COUNT 41
  252. #define XFS_TRANS_CHECKPOINT 42
  253. #define XFS_TRANS_ICREATE 43
  254. #define XFS_TRANS_TYPE_MAX 43
  255. /* new transaction types need to be reflected in xfs_logprint(8) */
  256. #define XFS_TRANS_TYPES \
  257. { XFS_TRANS_SETATTR_NOT_SIZE, "SETATTR_NOT_SIZE" }, \
  258. { XFS_TRANS_SETATTR_SIZE, "SETATTR_SIZE" }, \
  259. { XFS_TRANS_INACTIVE, "INACTIVE" }, \
  260. { XFS_TRANS_CREATE, "CREATE" }, \
  261. { XFS_TRANS_CREATE_TRUNC, "CREATE_TRUNC" }, \
  262. { XFS_TRANS_TRUNCATE_FILE, "TRUNCATE_FILE" }, \
  263. { XFS_TRANS_REMOVE, "REMOVE" }, \
  264. { XFS_TRANS_LINK, "LINK" }, \
  265. { XFS_TRANS_RENAME, "RENAME" }, \
  266. { XFS_TRANS_MKDIR, "MKDIR" }, \
  267. { XFS_TRANS_RMDIR, "RMDIR" }, \
  268. { XFS_TRANS_SYMLINK, "SYMLINK" }, \
  269. { XFS_TRANS_SET_DMATTRS, "SET_DMATTRS" }, \
  270. { XFS_TRANS_GROWFS, "GROWFS" }, \
  271. { XFS_TRANS_STRAT_WRITE, "STRAT_WRITE" }, \
  272. { XFS_TRANS_DIOSTRAT, "DIOSTRAT" }, \
  273. { XFS_TRANS_WRITEID, "WRITEID" }, \
  274. { XFS_TRANS_ADDAFORK, "ADDAFORK" }, \
  275. { XFS_TRANS_ATTRINVAL, "ATTRINVAL" }, \
  276. { XFS_TRANS_ATRUNCATE, "ATRUNCATE" }, \
  277. { XFS_TRANS_ATTR_SET, "ATTR_SET" }, \
  278. { XFS_TRANS_ATTR_RM, "ATTR_RM" }, \
  279. { XFS_TRANS_ATTR_FLAG, "ATTR_FLAG" }, \
  280. { XFS_TRANS_CLEAR_AGI_BUCKET, "CLEAR_AGI_BUCKET" }, \
  281. { XFS_TRANS_QM_SBCHANGE, "QM_SBCHANGE" }, \
  282. { XFS_TRANS_QM_QUOTAOFF, "QM_QUOTAOFF" }, \
  283. { XFS_TRANS_QM_DQALLOC, "QM_DQALLOC" }, \
  284. { XFS_TRANS_QM_SETQLIM, "QM_SETQLIM" }, \
  285. { XFS_TRANS_QM_DQCLUSTER, "QM_DQCLUSTER" }, \
  286. { XFS_TRANS_QM_QINOCREATE, "QM_QINOCREATE" }, \
  287. { XFS_TRANS_QM_QUOTAOFF_END, "QM_QOFF_END" }, \
  288. { XFS_TRANS_SB_UNIT, "SB_UNIT" }, \
  289. { XFS_TRANS_FSYNC_TS, "FSYNC_TS" }, \
  290. { XFS_TRANS_GROWFSRT_ALLOC, "GROWFSRT_ALLOC" }, \
  291. { XFS_TRANS_GROWFSRT_ZERO, "GROWFSRT_ZERO" }, \
  292. { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \
  293. { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \
  294. { XFS_TRANS_SB_COUNT, "SB_COUNT" }, \
  295. { XFS_TRANS_CHECKPOINT, "CHECKPOINT" }, \
  296. { XFS_TRANS_DUMMY1, "DUMMY1" }, \
  297. { XFS_TRANS_DUMMY2, "DUMMY2" }, \
  298. { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" }
  299. /*
  300. * This structure is used to track log items associated with
  301. * a transaction. It points to the log item and keeps some
  302. * flags to track the state of the log item. It also tracks
  303. * the amount of space needed to log the item it describes
  304. * once we get to commit processing (see xfs_trans_commit()).
  305. */
  306. struct xfs_log_item_desc {
  307. struct xfs_log_item *lid_item;
  308. struct list_head lid_trans;
  309. unsigned char lid_flags;
  310. };
  311. #define XFS_LID_DIRTY 0x1
  312. /*
  313. * Values for t_flags.
  314. */
  315. #define XFS_TRANS_DIRTY 0x01 /* something needs to be logged */
  316. #define XFS_TRANS_SB_DIRTY 0x02 /* superblock is modified */
  317. #define XFS_TRANS_PERM_LOG_RES 0x04 /* xact took a permanent log res */
  318. #define XFS_TRANS_SYNC 0x08 /* make commit synchronous */
  319. #define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */
  320. #define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
  321. #define XFS_TRANS_FREEZE_PROT 0x40 /* Transaction has elevated writer
  322. count in superblock */
  323. /*
  324. * Values for call flags parameter.
  325. */
  326. #define XFS_TRANS_RELEASE_LOG_RES 0x4
  327. #define XFS_TRANS_ABORT 0x8
  328. /*
  329. * Field values for xfs_trans_mod_sb.
  330. */
  331. #define XFS_TRANS_SB_ICOUNT 0x00000001
  332. #define XFS_TRANS_SB_IFREE 0x00000002
  333. #define XFS_TRANS_SB_FDBLOCKS 0x00000004
  334. #define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
  335. #define XFS_TRANS_SB_FREXTENTS 0x00000010
  336. #define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
  337. #define XFS_TRANS_SB_DBLOCKS 0x00000040
  338. #define XFS_TRANS_SB_AGCOUNT 0x00000080
  339. #define XFS_TRANS_SB_IMAXPCT 0x00000100
  340. #define XFS_TRANS_SB_REXTSIZE 0x00000200
  341. #define XFS_TRANS_SB_RBMBLOCKS 0x00000400
  342. #define XFS_TRANS_SB_RBLOCKS 0x00000800
  343. #define XFS_TRANS_SB_REXTENTS 0x00001000
  344. #define XFS_TRANS_SB_REXTSLOG 0x00002000
  345. /*
  346. * Here we centralize the specification of XFS meta-data buffer
  347. * reference count values. This determine how hard the buffer
  348. * cache tries to hold onto the buffer.
  349. */
  350. #define XFS_AGF_REF 4
  351. #define XFS_AGI_REF 4
  352. #define XFS_AGFL_REF 3
  353. #define XFS_INO_BTREE_REF 3
  354. #define XFS_ALLOC_BTREE_REF 2
  355. #define XFS_BMAP_BTREE_REF 2
  356. #define XFS_DIR_BTREE_REF 2
  357. #define XFS_INO_REF 2
  358. #define XFS_ATTR_BTREE_REF 1
  359. #define XFS_DQUOT_REF 1
  360. /*
  361. * Flags for xfs_trans_ichgtime().
  362. */
  363. #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
  364. #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
  365. #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
  366. /*
  367. * Inode Log Item Format definitions.
  368. *
  369. * This is the structure used to lay out an inode log item in the
  370. * log. The size of the inline data/extents/b-tree root to be logged
  371. * (if any) is indicated in the ilf_dsize field. Changes to this structure
  372. * must be added on to the end.
  373. */
  374. typedef struct xfs_inode_log_format {
  375. __uint16_t ilf_type; /* inode log item type */
  376. __uint16_t ilf_size; /* size of this item */
  377. __uint32_t ilf_fields; /* flags for fields logged */
  378. __uint16_t ilf_asize; /* size of attr d/ext/root */
  379. __uint16_t ilf_dsize; /* size of data/ext/root */
  380. __uint64_t ilf_ino; /* inode number */
  381. union {
  382. __uint32_t ilfu_rdev; /* rdev value for dev inode*/
  383. uuid_t ilfu_uuid; /* mount point value */
  384. } ilf_u;
  385. __int64_t ilf_blkno; /* blkno of inode buffer */
  386. __int32_t ilf_len; /* len of inode buffer */
  387. __int32_t ilf_boffset; /* off of inode in buffer */
  388. } xfs_inode_log_format_t;
  389. typedef struct xfs_inode_log_format_32 {
  390. __uint16_t ilf_type; /* inode log item type */
  391. __uint16_t ilf_size; /* size of this item */
  392. __uint32_t ilf_fields; /* flags for fields logged */
  393. __uint16_t ilf_asize; /* size of attr d/ext/root */
  394. __uint16_t ilf_dsize; /* size of data/ext/root */
  395. __uint64_t ilf_ino; /* inode number */
  396. union {
  397. __uint32_t ilfu_rdev; /* rdev value for dev inode*/
  398. uuid_t ilfu_uuid; /* mount point value */
  399. } ilf_u;
  400. __int64_t ilf_blkno; /* blkno of inode buffer */
  401. __int32_t ilf_len; /* len of inode buffer */
  402. __int32_t ilf_boffset; /* off of inode in buffer */
  403. } __attribute__((packed)) xfs_inode_log_format_32_t;
  404. typedef struct xfs_inode_log_format_64 {
  405. __uint16_t ilf_type; /* inode log item type */
  406. __uint16_t ilf_size; /* size of this item */
  407. __uint32_t ilf_fields; /* flags for fields logged */
  408. __uint16_t ilf_asize; /* size of attr d/ext/root */
  409. __uint16_t ilf_dsize; /* size of data/ext/root */
  410. __uint32_t ilf_pad; /* pad for 64 bit boundary */
  411. __uint64_t ilf_ino; /* inode number */
  412. union {
  413. __uint32_t ilfu_rdev; /* rdev value for dev inode*/
  414. uuid_t ilfu_uuid; /* mount point value */
  415. } ilf_u;
  416. __int64_t ilf_blkno; /* blkno of inode buffer */
  417. __int32_t ilf_len; /* len of inode buffer */
  418. __int32_t ilf_boffset; /* off of inode in buffer */
  419. } xfs_inode_log_format_64_t;
  420. /*
  421. * Flags for xfs_trans_log_inode flags field.
  422. */
  423. #define XFS_ILOG_CORE 0x001 /* log standard inode fields */
  424. #define XFS_ILOG_DDATA 0x002 /* log i_df.if_data */
  425. #define XFS_ILOG_DEXT 0x004 /* log i_df.if_extents */
  426. #define XFS_ILOG_DBROOT 0x008 /* log i_df.i_broot */
  427. #define XFS_ILOG_DEV 0x010 /* log the dev field */
  428. #define XFS_ILOG_UUID 0x020 /* log the uuid field */
  429. #define XFS_ILOG_ADATA 0x040 /* log i_af.if_data */
  430. #define XFS_ILOG_AEXT 0x080 /* log i_af.if_extents */
  431. #define XFS_ILOG_ABROOT 0x100 /* log i_af.i_broot */
  432. /*
  433. * The timestamps are dirty, but not necessarily anything else in the inode
  434. * core. Unlike the other fields above this one must never make it to disk
  435. * in the ilf_fields of the inode_log_format, but is purely store in-memory in
  436. * ili_fields in the inode_log_item.
  437. */
  438. #define XFS_ILOG_TIMESTAMP 0x4000
  439. #define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
  440. XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
  441. XFS_ILOG_UUID | XFS_ILOG_ADATA | \
  442. XFS_ILOG_AEXT | XFS_ILOG_ABROOT)
  443. #define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
  444. XFS_ILOG_DBROOT)
  445. #define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
  446. XFS_ILOG_ABROOT)
  447. #define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
  448. XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
  449. XFS_ILOG_DEV | XFS_ILOG_UUID | \
  450. XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
  451. XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP)
  452. static inline int xfs_ilog_fbroot(int w)
  453. {
  454. return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
  455. }
  456. static inline int xfs_ilog_fext(int w)
  457. {
  458. return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
  459. }
  460. static inline int xfs_ilog_fdata(int w)
  461. {
  462. return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
  463. }
  464. /*
  465. * Incore version of the on-disk inode core structures. We log this directly
  466. * into the journal in host CPU format (for better or worse) and as such
  467. * directly mirrors the xfs_dinode structure as it must contain all the same
  468. * information.
  469. */
  470. typedef struct xfs_ictimestamp {
  471. __int32_t t_sec; /* timestamp seconds */
  472. __int32_t t_nsec; /* timestamp nanoseconds */
  473. } xfs_ictimestamp_t;
  474. /*
  475. * NOTE: This structure must be kept identical to struct xfs_dinode
  476. * in xfs_dinode.h except for the endianness annotations.
  477. */
  478. typedef struct xfs_icdinode {
  479. __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
  480. __uint16_t di_mode; /* mode and type of file */
  481. __int8_t di_version; /* inode version */
  482. __int8_t di_format; /* format of di_c data */
  483. __uint16_t di_onlink; /* old number of links to file */
  484. __uint32_t di_uid; /* owner's user id */
  485. __uint32_t di_gid; /* owner's group id */
  486. __uint32_t di_nlink; /* number of links to file */
  487. __uint16_t di_projid_lo; /* lower part of owner's project id */
  488. __uint16_t di_projid_hi; /* higher part of owner's project id */
  489. __uint8_t di_pad[6]; /* unused, zeroed space */
  490. __uint16_t di_flushiter; /* incremented on flush */
  491. xfs_ictimestamp_t di_atime; /* time last accessed */
  492. xfs_ictimestamp_t di_mtime; /* time last modified */
  493. xfs_ictimestamp_t di_ctime; /* time created/inode modified */
  494. xfs_fsize_t di_size; /* number of bytes in file */
  495. xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */
  496. xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
  497. xfs_extnum_t di_nextents; /* number of extents in data fork */
  498. xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
  499. __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
  500. __int8_t di_aformat; /* format of attr fork's data */
  501. __uint32_t di_dmevmask; /* DMIG event mask */
  502. __uint16_t di_dmstate; /* DMIG state info */
  503. __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
  504. __uint32_t di_gen; /* generation number */
  505. /* di_next_unlinked is the only non-core field in the old dinode */
  506. xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
  507. /* start of the extended dinode, writable fields */
  508. __uint32_t di_crc; /* CRC of the inode */
  509. __uint64_t di_changecount; /* number of attribute changes */
  510. xfs_lsn_t di_lsn; /* flush sequence */
  511. __uint64_t di_flags2; /* more random flags */
  512. __uint8_t di_pad2[16]; /* more padding for future expansion */
  513. /* fields only written to during inode creation */
  514. xfs_ictimestamp_t di_crtime; /* time created */
  515. xfs_ino_t di_ino; /* inode number */
  516. uuid_t di_uuid; /* UUID of the filesystem */
  517. /* structure must be padded to 64 bit alignment */
  518. } xfs_icdinode_t;
  519. static inline uint xfs_icdinode_size(int version)
  520. {
  521. if (version == 3)
  522. return sizeof(struct xfs_icdinode);
  523. return offsetof(struct xfs_icdinode, di_next_unlinked);
  524. }
  525. /*
  526. * Buffer Log Format defintions
  527. *
  528. * These are the physical dirty bitmap defintions for the log format structure.
  529. */
  530. #define XFS_BLF_CHUNK 128
  531. #define XFS_BLF_SHIFT 7
  532. #define BIT_TO_WORD_SHIFT 5
  533. #define NBWORD (NBBY * sizeof(unsigned int))
  534. /*
  535. * This flag indicates that the buffer contains on disk inodes
  536. * and requires special recovery handling.
  537. */
  538. #define XFS_BLF_INODE_BUF (1<<0)
  539. /*
  540. * This flag indicates that the buffer should not be replayed
  541. * during recovery because its blocks are being freed.
  542. */
  543. #define XFS_BLF_CANCEL (1<<1)
  544. /*
  545. * This flag indicates that the buffer contains on disk
  546. * user or group dquots and may require special recovery handling.
  547. */
  548. #define XFS_BLF_UDQUOT_BUF (1<<2)
  549. #define XFS_BLF_PDQUOT_BUF (1<<3)
  550. #define XFS_BLF_GDQUOT_BUF (1<<4)
  551. /*
  552. * This is the structure used to lay out a buf log item in the
  553. * log. The data map describes which 128 byte chunks of the buffer
  554. * have been logged.
  555. */
  556. #define XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
  557. typedef struct xfs_buf_log_format {
  558. unsigned short blf_type; /* buf log item type indicator */
  559. unsigned short blf_size; /* size of this item */
  560. ushort blf_flags; /* misc state */
  561. ushort blf_len; /* number of blocks in this buf */
  562. __int64_t blf_blkno; /* starting blkno of this buf */
  563. unsigned int blf_map_size; /* used size of data bitmap in words */
  564. unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
  565. } xfs_buf_log_format_t;
  566. /*
  567. * All buffers now need to tell recovery where the magic number
  568. * is so that it can verify and calculate the CRCs on the buffer correctly
  569. * once the changes have been replayed into the buffer.
  570. *
  571. * The type value is held in the upper 5 bits of the blf_flags field, which is
  572. * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
  573. */
  574. #define XFS_BLFT_BITS 5
  575. #define XFS_BLFT_SHIFT 11
  576. #define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
  577. enum xfs_blft {
  578. XFS_BLFT_UNKNOWN_BUF = 0,
  579. XFS_BLFT_UDQUOT_BUF,
  580. XFS_BLFT_PDQUOT_BUF,
  581. XFS_BLFT_GDQUOT_BUF,
  582. XFS_BLFT_BTREE_BUF,
  583. XFS_BLFT_AGF_BUF,
  584. XFS_BLFT_AGFL_BUF,
  585. XFS_BLFT_AGI_BUF,
  586. XFS_BLFT_DINO_BUF,
  587. XFS_BLFT_SYMLINK_BUF,
  588. XFS_BLFT_DIR_BLOCK_BUF,
  589. XFS_BLFT_DIR_DATA_BUF,
  590. XFS_BLFT_DIR_FREE_BUF,
  591. XFS_BLFT_DIR_LEAF1_BUF,
  592. XFS_BLFT_DIR_LEAFN_BUF,
  593. XFS_BLFT_DA_NODE_BUF,
  594. XFS_BLFT_ATTR_LEAF_BUF,
  595. XFS_BLFT_ATTR_RMT_BUF,
  596. XFS_BLFT_SB_BUF,
  597. XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
  598. };
  599. static inline void
  600. xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
  601. {
  602. ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
  603. blf->blf_flags &= ~XFS_BLFT_MASK;
  604. blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
  605. }
  606. static inline __uint16_t
  607. xfs_blft_from_flags(struct xfs_buf_log_format *blf)
  608. {
  609. return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
  610. }
  611. /*
  612. * EFI/EFD log format definitions
  613. */
  614. typedef struct xfs_extent {
  615. xfs_dfsbno_t ext_start;
  616. xfs_extlen_t ext_len;
  617. } xfs_extent_t;
  618. /*
  619. * Since an xfs_extent_t has types (start:64, len: 32)
  620. * there are different alignments on 32 bit and 64 bit kernels.
  621. * So we provide the different variants for use by a
  622. * conversion routine.
  623. */
  624. typedef struct xfs_extent_32 {
  625. __uint64_t ext_start;
  626. __uint32_t ext_len;
  627. } __attribute__((packed)) xfs_extent_32_t;
  628. typedef struct xfs_extent_64 {
  629. __uint64_t ext_start;
  630. __uint32_t ext_len;
  631. __uint32_t ext_pad;
  632. } xfs_extent_64_t;
  633. /*
  634. * This is the structure used to lay out an efi log item in the
  635. * log. The efi_extents field is a variable size array whose
  636. * size is given by efi_nextents.
  637. */
  638. typedef struct xfs_efi_log_format {
  639. __uint16_t efi_type; /* efi log item type */
  640. __uint16_t efi_size; /* size of this item */
  641. __uint32_t efi_nextents; /* # extents to free */
  642. __uint64_t efi_id; /* efi identifier */
  643. xfs_extent_t efi_extents[1]; /* array of extents to free */
  644. } xfs_efi_log_format_t;
  645. typedef struct xfs_efi_log_format_32 {
  646. __uint16_t efi_type; /* efi log item type */
  647. __uint16_t efi_size; /* size of this item */
  648. __uint32_t efi_nextents; /* # extents to free */
  649. __uint64_t efi_id; /* efi identifier */
  650. xfs_extent_32_t efi_extents[1]; /* array of extents to free */
  651. } __attribute__((packed)) xfs_efi_log_format_32_t;
  652. typedef struct xfs_efi_log_format_64 {
  653. __uint16_t efi_type; /* efi log item type */
  654. __uint16_t efi_size; /* size of this item */
  655. __uint32_t efi_nextents; /* # extents to free */
  656. __uint64_t efi_id; /* efi identifier */
  657. xfs_extent_64_t efi_extents[1]; /* array of extents to free */
  658. } xfs_efi_log_format_64_t;
  659. /*
  660. * This is the structure used to lay out an efd log item in the
  661. * log. The efd_extents array is a variable size array whose
  662. * size is given by efd_nextents;
  663. */
  664. typedef struct xfs_efd_log_format {
  665. __uint16_t efd_type; /* efd log item type */
  666. __uint16_t efd_size; /* size of this item */
  667. __uint32_t efd_nextents; /* # of extents freed */
  668. __uint64_t efd_efi_id; /* id of corresponding efi */
  669. xfs_extent_t efd_extents[1]; /* array of extents freed */
  670. } xfs_efd_log_format_t;
  671. typedef struct xfs_efd_log_format_32 {
  672. __uint16_t efd_type; /* efd log item type */
  673. __uint16_t efd_size; /* size of this item */
  674. __uint32_t efd_nextents; /* # of extents freed */
  675. __uint64_t efd_efi_id; /* id of corresponding efi */
  676. xfs_extent_32_t efd_extents[1]; /* array of extents freed */
  677. } __attribute__((packed)) xfs_efd_log_format_32_t;
  678. typedef struct xfs_efd_log_format_64 {
  679. __uint16_t efd_type; /* efd log item type */
  680. __uint16_t efd_size; /* size of this item */
  681. __uint32_t efd_nextents; /* # of extents freed */
  682. __uint64_t efd_efi_id; /* id of corresponding efi */
  683. xfs_extent_64_t efd_extents[1]; /* array of extents freed */
  684. } xfs_efd_log_format_64_t;
  685. /*
  686. * Dquot Log format definitions.
  687. *
  688. * The first two fields must be the type and size fitting into
  689. * 32 bits : log_recovery code assumes that.
  690. */
  691. typedef struct xfs_dq_logformat {
  692. __uint16_t qlf_type; /* dquot log item type */
  693. __uint16_t qlf_size; /* size of this item */
  694. xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
  695. __int64_t qlf_blkno; /* blkno of dquot buffer */
  696. __int32_t qlf_len; /* len of dquot buffer */
  697. __uint32_t qlf_boffset; /* off of dquot in buffer */
  698. } xfs_dq_logformat_t;
  699. /*
  700. * log format struct for QUOTAOFF records.
  701. * The first two fields must be the type and size fitting into
  702. * 32 bits : log_recovery code assumes that.
  703. * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
  704. * to the first and ensures that the first logitem is taken out of the AIL
  705. * only when the last one is securely committed.
  706. */
  707. typedef struct xfs_qoff_logformat {
  708. unsigned short qf_type; /* quotaoff log item type */
  709. unsigned short qf_size; /* size of this item */
  710. unsigned int qf_flags; /* USR and/or GRP */
  711. char qf_pad[12]; /* padding for future */
  712. } xfs_qoff_logformat_t;
  713. /*
  714. * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
  715. */
  716. #define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
  717. #define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
  718. #define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
  719. #define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
  720. #define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
  721. #define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
  722. #define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
  723. /*
  724. * Conversion to and from the combined OQUOTA flag (if necessary)
  725. * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
  726. */
  727. #define XFS_GQUOTA_ENFD 0x0080 /* group quota limits enforced */
  728. #define XFS_GQUOTA_CHKD 0x0100 /* quotacheck run on group quotas */
  729. #define XFS_PQUOTA_ENFD 0x0200 /* project quota limits enforced */
  730. #define XFS_PQUOTA_CHKD 0x0400 /* quotacheck run on project quotas */
  731. #define XFS_ALL_QUOTA_ACCT \
  732. (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
  733. #define XFS_ALL_QUOTA_ENFD \
  734. (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
  735. #define XFS_ALL_QUOTA_CHKD \
  736. (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
  737. /*
  738. * Inode create log item structure
  739. *
  740. * Log recovery assumes the first two entries are the type and size and they fit
  741. * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
  742. * decoding can be done correctly.
  743. */
  744. struct xfs_icreate_log {
  745. __uint16_t icl_type; /* type of log format structure */
  746. __uint16_t icl_size; /* size of log format structure */
  747. __be32 icl_ag; /* ag being allocated in */
  748. __be32 icl_agbno; /* start block of inode range */
  749. __be32 icl_count; /* number of inodes to initialise */
  750. __be32 icl_isize; /* size of inodes */
  751. __be32 icl_length; /* length of extent to initialise */
  752. __be32 icl_gen; /* inode generation number to use */
  753. };
  754. #endif /* __XFS_LOG_FORMAT_H__ */