xfs_trans.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /*
  2. * Copyright (c) 2000-2002,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_TRANS_H__
  19. #define __XFS_TRANS_H__
  20. struct xfs_log_item;
  21. /*
  22. * This is the structure written in the log at the head of
  23. * every transaction. It identifies the type and id of the
  24. * transaction, and contains the number of items logged by
  25. * the transaction so we know how many to expect during recovery.
  26. *
  27. * Do not change the below structure without redoing the code in
  28. * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
  29. */
  30. typedef struct xfs_trans_header {
  31. uint th_magic; /* magic number */
  32. uint th_type; /* transaction type */
  33. __int32_t th_tid; /* transaction id (unused) */
  34. uint th_num_items; /* num items logged by trans */
  35. } xfs_trans_header_t;
  36. #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
  37. /*
  38. * Log item types.
  39. */
  40. #define XFS_LI_EFI 0x1236
  41. #define XFS_LI_EFD 0x1237
  42. #define XFS_LI_IUNLINK 0x1238
  43. #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */
  44. #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
  45. #define XFS_LI_DQUOT 0x123d
  46. #define XFS_LI_QUOTAOFF 0x123e
  47. /*
  48. * Transaction types. Used to distinguish types of buffers.
  49. */
  50. #define XFS_TRANS_SETATTR_NOT_SIZE 1
  51. #define XFS_TRANS_SETATTR_SIZE 2
  52. #define XFS_TRANS_INACTIVE 3
  53. #define XFS_TRANS_CREATE 4
  54. #define XFS_TRANS_CREATE_TRUNC 5
  55. #define XFS_TRANS_TRUNCATE_FILE 6
  56. #define XFS_TRANS_REMOVE 7
  57. #define XFS_TRANS_LINK 8
  58. #define XFS_TRANS_RENAME 9
  59. #define XFS_TRANS_MKDIR 10
  60. #define XFS_TRANS_RMDIR 11
  61. #define XFS_TRANS_SYMLINK 12
  62. #define XFS_TRANS_SET_DMATTRS 13
  63. #define XFS_TRANS_GROWFS 14
  64. #define XFS_TRANS_STRAT_WRITE 15
  65. #define XFS_TRANS_DIOSTRAT 16
  66. #define XFS_TRANS_WRITE_SYNC 17
  67. #define XFS_TRANS_WRITEID 18
  68. #define XFS_TRANS_ADDAFORK 19
  69. #define XFS_TRANS_ATTRINVAL 20
  70. #define XFS_TRANS_ATRUNCATE 21
  71. #define XFS_TRANS_ATTR_SET 22
  72. #define XFS_TRANS_ATTR_RM 23
  73. #define XFS_TRANS_ATTR_FLAG 24
  74. #define XFS_TRANS_CLEAR_AGI_BUCKET 25
  75. #define XFS_TRANS_QM_SBCHANGE 26
  76. /*
  77. * Dummy entries since we use the transaction type to index into the
  78. * trans_type[] in xlog_recover_print_trans_head()
  79. */
  80. #define XFS_TRANS_DUMMY1 27
  81. #define XFS_TRANS_DUMMY2 28
  82. #define XFS_TRANS_QM_QUOTAOFF 29
  83. #define XFS_TRANS_QM_DQALLOC 30
  84. #define XFS_TRANS_QM_SETQLIM 31
  85. #define XFS_TRANS_QM_DQCLUSTER 32
  86. #define XFS_TRANS_QM_QINOCREATE 33
  87. #define XFS_TRANS_QM_QUOTAOFF_END 34
  88. #define XFS_TRANS_SB_UNIT 35
  89. #define XFS_TRANS_FSYNC_TS 36
  90. #define XFS_TRANS_GROWFSRT_ALLOC 37
  91. #define XFS_TRANS_GROWFSRT_ZERO 38
  92. #define XFS_TRANS_GROWFSRT_FREE 39
  93. #define XFS_TRANS_SWAPEXT 40
  94. #define XFS_TRANS_SB_COUNT 41
  95. #define XFS_TRANS_TYPE_MAX 41
  96. /* new transaction types need to be reflected in xfs_logprint(8) */
  97. /*
  98. * This structure is used to track log items associated with
  99. * a transaction. It points to the log item and keeps some
  100. * flags to track the state of the log item. It also tracks
  101. * the amount of space needed to log the item it describes
  102. * once we get to commit processing (see xfs_trans_commit()).
  103. */
  104. typedef struct xfs_log_item_desc {
  105. struct xfs_log_item *lid_item;
  106. ushort lid_size;
  107. unsigned char lid_flags;
  108. unsigned char lid_index;
  109. } xfs_log_item_desc_t;
  110. #define XFS_LID_DIRTY 0x1
  111. #define XFS_LID_PINNED 0x2
  112. #define XFS_LID_BUF_STALE 0x8
  113. /*
  114. * This structure is used to maintain a chunk list of log_item_desc
  115. * structures. The free field is a bitmask indicating which descriptors
  116. * in this chunk's array are free. The unused field is the first value
  117. * not used since this chunk was allocated.
  118. */
  119. #define XFS_LIC_NUM_SLOTS 15
  120. typedef struct xfs_log_item_chunk {
  121. struct xfs_log_item_chunk *lic_next;
  122. ushort lic_free;
  123. ushort lic_unused;
  124. xfs_log_item_desc_t lic_descs[XFS_LIC_NUM_SLOTS];
  125. } xfs_log_item_chunk_t;
  126. #define XFS_LIC_MAX_SLOT (XFS_LIC_NUM_SLOTS - 1)
  127. #define XFS_LIC_FREEMASK ((1 << XFS_LIC_NUM_SLOTS) - 1)
  128. /*
  129. * Initialize the given chunk. Set the chunk's free descriptor mask
  130. * to indicate that all descriptors are free. The caller gets to set
  131. * lic_unused to the right value (0 matches all free). The
  132. * lic_descs.lid_index values are set up as each desc is allocated.
  133. */
  134. static inline void xfs_lic_init(xfs_log_item_chunk_t *cp)
  135. {
  136. cp->lic_free = XFS_LIC_FREEMASK;
  137. }
  138. static inline void xfs_lic_init_slot(xfs_log_item_chunk_t *cp, int slot)
  139. {
  140. cp->lic_descs[slot].lid_index = (unsigned char)(slot);
  141. }
  142. static inline int xfs_lic_vacancy(xfs_log_item_chunk_t *cp)
  143. {
  144. return cp->lic_free & XFS_LIC_FREEMASK;
  145. }
  146. static inline void xfs_lic_all_free(xfs_log_item_chunk_t *cp)
  147. {
  148. cp->lic_free = XFS_LIC_FREEMASK;
  149. }
  150. static inline int xfs_lic_are_all_free(xfs_log_item_chunk_t *cp)
  151. {
  152. return ((cp->lic_free & XFS_LIC_FREEMASK) == XFS_LIC_FREEMASK);
  153. }
  154. static inline int xfs_lic_isfree(xfs_log_item_chunk_t *cp, int slot)
  155. {
  156. return (cp->lic_free & (1 << slot));
  157. }
  158. static inline void xfs_lic_claim(xfs_log_item_chunk_t *cp, int slot)
  159. {
  160. cp->lic_free &= ~(1 << slot);
  161. }
  162. static inline void xfs_lic_relse(xfs_log_item_chunk_t *cp, int slot)
  163. {
  164. cp->lic_free |= 1 << slot;
  165. }
  166. static inline xfs_log_item_desc_t *
  167. xfs_lic_slot(xfs_log_item_chunk_t *cp, int slot)
  168. {
  169. return &(cp->lic_descs[slot]);
  170. }
  171. static inline int xfs_lic_desc_to_slot(xfs_log_item_desc_t *dp)
  172. {
  173. return (uint)dp->lid_index;
  174. }
  175. /*
  176. * Calculate the address of a chunk given a descriptor pointer:
  177. * dp - dp->lid_index give the address of the start of the lic_descs array.
  178. * From this we subtract the offset of the lic_descs field in a chunk.
  179. * All of this yields the address of the chunk, which is
  180. * cast to a chunk pointer.
  181. */
  182. static inline xfs_log_item_chunk_t *
  183. xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
  184. {
  185. return (xfs_log_item_chunk_t*) \
  186. (((xfs_caddr_t)((dp) - (dp)->lid_index)) - \
  187. (xfs_caddr_t)(((xfs_log_item_chunk_t*)0)->lic_descs));
  188. }
  189. #define XFS_TRANS_MAGIC 0x5452414E /* 'TRAN' */
  190. /*
  191. * Values for t_flags.
  192. */
  193. #define XFS_TRANS_DIRTY 0x01 /* something needs to be logged */
  194. #define XFS_TRANS_SB_DIRTY 0x02 /* superblock is modified */
  195. #define XFS_TRANS_PERM_LOG_RES 0x04 /* xact took a permanent log res */
  196. #define XFS_TRANS_SYNC 0x08 /* make commit synchronous */
  197. #define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */
  198. #define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
  199. /*
  200. * Values for call flags parameter.
  201. */
  202. #define XFS_TRANS_NOSLEEP 0x1
  203. #define XFS_TRANS_WAIT 0x2
  204. #define XFS_TRANS_RELEASE_LOG_RES 0x4
  205. #define XFS_TRANS_ABORT 0x8
  206. /*
  207. * Field values for xfs_trans_mod_sb.
  208. */
  209. #define XFS_TRANS_SB_ICOUNT 0x00000001
  210. #define XFS_TRANS_SB_IFREE 0x00000002
  211. #define XFS_TRANS_SB_FDBLOCKS 0x00000004
  212. #define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
  213. #define XFS_TRANS_SB_FREXTENTS 0x00000010
  214. #define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
  215. #define XFS_TRANS_SB_DBLOCKS 0x00000040
  216. #define XFS_TRANS_SB_AGCOUNT 0x00000080
  217. #define XFS_TRANS_SB_IMAXPCT 0x00000100
  218. #define XFS_TRANS_SB_REXTSIZE 0x00000200
  219. #define XFS_TRANS_SB_RBMBLOCKS 0x00000400
  220. #define XFS_TRANS_SB_RBLOCKS 0x00000800
  221. #define XFS_TRANS_SB_REXTENTS 0x00001000
  222. #define XFS_TRANS_SB_REXTSLOG 0x00002000
  223. /*
  224. * Various log reservation values.
  225. * These are based on the size of the file system block
  226. * because that is what most transactions manipulate.
  227. * Each adds in an additional 128 bytes per item logged to
  228. * try to account for the overhead of the transaction mechanism.
  229. *
  230. * Note:
  231. * Most of the reservations underestimate the number of allocation
  232. * groups into which they could free extents in the xfs_bmap_finish()
  233. * call. This is because the number in the worst case is quite high
  234. * and quite unusual. In order to fix this we need to change
  235. * xfs_bmap_finish() to free extents in only a single AG at a time.
  236. * This will require changes to the EFI code as well, however, so that
  237. * the EFI for the extents not freed is logged again in each transaction.
  238. * See bug 261917.
  239. */
  240. /*
  241. * Per-extent log reservation for the allocation btree changes
  242. * involved in freeing or allocating an extent.
  243. * 2 trees * (2 blocks/level * max depth - 1) * block size
  244. */
  245. #define XFS_ALLOCFREE_LOG_RES(mp,nx) \
  246. ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * XFS_AG_MAXLEVELS(mp) - 1)))
  247. #define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
  248. ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
  249. /*
  250. * Per-directory log reservation for any directory change.
  251. * dir blocks: (1 btree block per level + data block + free block) * dblock size
  252. * bmap btree: (levels + 2) * max depth * block size
  253. * v2 directory blocks can be fragmented below the dirblksize down to the fsb
  254. * size, so account for that in the DAENTER macros.
  255. */
  256. #define XFS_DIROP_LOG_RES(mp) \
  257. (XFS_FSB_TO_B(mp, XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK)) + \
  258. (XFS_FSB_TO_B(mp, XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)))
  259. #define XFS_DIROP_LOG_COUNT(mp) \
  260. (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \
  261. XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)
  262. /*
  263. * In a write transaction we can allocate a maximum of 2
  264. * extents. This gives:
  265. * the inode getting the new extents: inode size
  266. * the inode's bmap btree: max depth * block size
  267. * the agfs of the ags from which the extents are allocated: 2 * sector
  268. * the superblock free block counter: sector size
  269. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  270. * And the bmap_finish transaction can free bmap blocks in a join:
  271. * the agfs of the ags containing the blocks: 2 * sector size
  272. * the agfls of the ags containing the blocks: 2 * sector size
  273. * the super block free block counter: sector size
  274. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  275. */
  276. #define XFS_CALC_WRITE_LOG_RES(mp) \
  277. (MAX( \
  278. ((mp)->m_sb.sb_inodesize + \
  279. XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \
  280. (2 * (mp)->m_sb.sb_sectsize) + \
  281. (mp)->m_sb.sb_sectsize + \
  282. XFS_ALLOCFREE_LOG_RES(mp, 2) + \
  283. (128 * (4 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + XFS_ALLOCFREE_LOG_COUNT(mp, 2)))),\
  284. ((2 * (mp)->m_sb.sb_sectsize) + \
  285. (2 * (mp)->m_sb.sb_sectsize) + \
  286. (mp)->m_sb.sb_sectsize + \
  287. XFS_ALLOCFREE_LOG_RES(mp, 2) + \
  288. (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
  289. #define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write)
  290. /*
  291. * In truncating a file we free up to two extents at once. We can modify:
  292. * the inode being truncated: inode size
  293. * the inode's bmap btree: (max depth + 1) * block size
  294. * And the bmap_finish transaction can free the blocks and bmap blocks:
  295. * the agf for each of the ags: 4 * sector size
  296. * the agfl for each of the ags: 4 * sector size
  297. * the super block to reflect the freed blocks: sector size
  298. * worst case split in allocation btrees per extent assuming 4 extents:
  299. * 4 exts * 2 trees * (2 * max depth - 1) * block size
  300. * the inode btree: max depth * blocksize
  301. * the allocation btrees: 2 trees * (max depth - 1) * block size
  302. */
  303. #define XFS_CALC_ITRUNCATE_LOG_RES(mp) \
  304. (MAX( \
  305. ((mp)->m_sb.sb_inodesize + \
  306. XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1) + \
  307. (128 * (2 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \
  308. ((4 * (mp)->m_sb.sb_sectsize) + \
  309. (4 * (mp)->m_sb.sb_sectsize) + \
  310. (mp)->m_sb.sb_sectsize + \
  311. XFS_ALLOCFREE_LOG_RES(mp, 4) + \
  312. (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4))) + \
  313. (128 * 5) + \
  314. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  315. (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
  316. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
  317. #define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate)
  318. /*
  319. * In renaming a files we can modify:
  320. * the four inodes involved: 4 * inode size
  321. * the two directory btrees: 2 * (max depth + v2) * dir block size
  322. * the two directory bmap btrees: 2 * max depth * block size
  323. * And the bmap_finish transaction can free dir and bmap blocks (two sets
  324. * of bmap blocks) giving:
  325. * the agf for the ags in which the blocks live: 3 * sector size
  326. * the agfl for the ags in which the blocks live: 3 * sector size
  327. * the superblock for the free block count: sector size
  328. * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
  329. */
  330. #define XFS_CALC_RENAME_LOG_RES(mp) \
  331. (MAX( \
  332. ((4 * (mp)->m_sb.sb_inodesize) + \
  333. (2 * XFS_DIROP_LOG_RES(mp)) + \
  334. (128 * (4 + 2 * XFS_DIROP_LOG_COUNT(mp)))), \
  335. ((3 * (mp)->m_sb.sb_sectsize) + \
  336. (3 * (mp)->m_sb.sb_sectsize) + \
  337. (mp)->m_sb.sb_sectsize + \
  338. XFS_ALLOCFREE_LOG_RES(mp, 3) + \
  339. (128 * (7 + XFS_ALLOCFREE_LOG_COUNT(mp, 3))))))
  340. #define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename)
  341. /*
  342. * For creating a link to an inode:
  343. * the parent directory inode: inode size
  344. * the linked inode: inode size
  345. * the directory btree could split: (max depth + v2) * dir block size
  346. * the directory bmap btree could join or split: (max depth + v2) * blocksize
  347. * And the bmap_finish transaction can free some bmap blocks giving:
  348. * the agf for the ag in which the blocks live: sector size
  349. * the agfl for the ag in which the blocks live: sector size
  350. * the superblock for the free block count: sector size
  351. * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
  352. */
  353. #define XFS_CALC_LINK_LOG_RES(mp) \
  354. (MAX( \
  355. ((mp)->m_sb.sb_inodesize + \
  356. (mp)->m_sb.sb_inodesize + \
  357. XFS_DIROP_LOG_RES(mp) + \
  358. (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \
  359. ((mp)->m_sb.sb_sectsize + \
  360. (mp)->m_sb.sb_sectsize + \
  361. (mp)->m_sb.sb_sectsize + \
  362. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  363. (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
  364. #define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link)
  365. /*
  366. * For removing a directory entry we can modify:
  367. * the parent directory inode: inode size
  368. * the removed inode: inode size
  369. * the directory btree could join: (max depth + v2) * dir block size
  370. * the directory bmap btree could join or split: (max depth + v2) * blocksize
  371. * And the bmap_finish transaction can free the dir and bmap blocks giving:
  372. * the agf for the ag in which the blocks live: 2 * sector size
  373. * the agfl for the ag in which the blocks live: 2 * sector size
  374. * the superblock for the free block count: sector size
  375. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  376. */
  377. #define XFS_CALC_REMOVE_LOG_RES(mp) \
  378. (MAX( \
  379. ((mp)->m_sb.sb_inodesize + \
  380. (mp)->m_sb.sb_inodesize + \
  381. XFS_DIROP_LOG_RES(mp) + \
  382. (128 * (2 + XFS_DIROP_LOG_COUNT(mp)))), \
  383. ((2 * (mp)->m_sb.sb_sectsize) + \
  384. (2 * (mp)->m_sb.sb_sectsize) + \
  385. (mp)->m_sb.sb_sectsize + \
  386. XFS_ALLOCFREE_LOG_RES(mp, 2) + \
  387. (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
  388. #define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove)
  389. /*
  390. * For symlink we can modify:
  391. * the parent directory inode: inode size
  392. * the new inode: inode size
  393. * the inode btree entry: 1 block
  394. * the directory btree: (max depth + v2) * dir block size
  395. * the directory inode's bmap btree: (max depth + v2) * block size
  396. * the blocks for the symlink: 1 kB
  397. * Or in the first xact we allocate some inodes giving:
  398. * the agi and agf of the ag getting the new inodes: 2 * sectorsize
  399. * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
  400. * the inode btree: max depth * blocksize
  401. * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
  402. */
  403. #define XFS_CALC_SYMLINK_LOG_RES(mp) \
  404. (MAX( \
  405. ((mp)->m_sb.sb_inodesize + \
  406. (mp)->m_sb.sb_inodesize + \
  407. XFS_FSB_TO_B(mp, 1) + \
  408. XFS_DIROP_LOG_RES(mp) + \
  409. 1024 + \
  410. (128 * (4 + XFS_DIROP_LOG_COUNT(mp)))), \
  411. (2 * (mp)->m_sb.sb_sectsize + \
  412. XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \
  413. XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \
  414. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  415. (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
  416. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
  417. #define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink)
  418. /*
  419. * For create we can modify:
  420. * the parent directory inode: inode size
  421. * the new inode: inode size
  422. * the inode btree entry: block size
  423. * the superblock for the nlink flag: sector size
  424. * the directory btree: (max depth + v2) * dir block size
  425. * the directory inode's bmap btree: (max depth + v2) * block size
  426. * Or in the first xact we allocate some inodes giving:
  427. * the agi and agf of the ag getting the new inodes: 2 * sectorsize
  428. * the superblock for the nlink flag: sector size
  429. * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
  430. * the inode btree: max depth * blocksize
  431. * the allocation btrees: 2 trees * (max depth - 1) * block size
  432. */
  433. #define XFS_CALC_CREATE_LOG_RES(mp) \
  434. (MAX( \
  435. ((mp)->m_sb.sb_inodesize + \
  436. (mp)->m_sb.sb_inodesize + \
  437. (mp)->m_sb.sb_sectsize + \
  438. XFS_FSB_TO_B(mp, 1) + \
  439. XFS_DIROP_LOG_RES(mp) + \
  440. (128 * (3 + XFS_DIROP_LOG_COUNT(mp)))), \
  441. (3 * (mp)->m_sb.sb_sectsize + \
  442. XFS_FSB_TO_B((mp), XFS_IALLOC_BLOCKS((mp))) + \
  443. XFS_FSB_TO_B((mp), (mp)->m_in_maxlevels) + \
  444. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  445. (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
  446. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))))
  447. #define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create)
  448. /*
  449. * Making a new directory is the same as creating a new file.
  450. */
  451. #define XFS_CALC_MKDIR_LOG_RES(mp) XFS_CALC_CREATE_LOG_RES(mp)
  452. #define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir)
  453. /*
  454. * In freeing an inode we can modify:
  455. * the inode being freed: inode size
  456. * the super block free inode counter: sector size
  457. * the agi hash list and counters: sector size
  458. * the inode btree entry: block size
  459. * the on disk inode before ours in the agi hash list: inode cluster size
  460. * the inode btree: max depth * blocksize
  461. * the allocation btrees: 2 trees * (max depth - 1) * block size
  462. */
  463. #define XFS_CALC_IFREE_LOG_RES(mp) \
  464. ((mp)->m_sb.sb_inodesize + \
  465. (mp)->m_sb.sb_sectsize + \
  466. (mp)->m_sb.sb_sectsize + \
  467. XFS_FSB_TO_B((mp), 1) + \
  468. MAX((__uint16_t)XFS_FSB_TO_B((mp), 1), XFS_INODE_CLUSTER_SIZE(mp)) + \
  469. (128 * 5) + \
  470. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  471. (128 * (2 + XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels + \
  472. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
  473. #define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree)
  474. /*
  475. * When only changing the inode we log the inode and possibly the superblock
  476. * We also add a bit of slop for the transaction stuff.
  477. */
  478. #define XFS_CALC_ICHANGE_LOG_RES(mp) ((mp)->m_sb.sb_inodesize + \
  479. (mp)->m_sb.sb_sectsize + 512)
  480. #define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange)
  481. /*
  482. * Growing the data section of the filesystem.
  483. * superblock
  484. * agi and agf
  485. * allocation btrees
  486. */
  487. #define XFS_CALC_GROWDATA_LOG_RES(mp) \
  488. ((mp)->m_sb.sb_sectsize * 3 + \
  489. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  490. (128 * (3 + XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
  491. #define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata)
  492. /*
  493. * Growing the rt section of the filesystem.
  494. * In the first set of transactions (ALLOC) we allocate space to the
  495. * bitmap or summary files.
  496. * superblock: sector size
  497. * agf of the ag from which the extent is allocated: sector size
  498. * bmap btree for bitmap/summary inode: max depth * blocksize
  499. * bitmap/summary inode: inode size
  500. * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
  501. */
  502. #define XFS_CALC_GROWRTALLOC_LOG_RES(mp) \
  503. (2 * (mp)->m_sb.sb_sectsize + \
  504. XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)) + \
  505. (mp)->m_sb.sb_inodesize + \
  506. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  507. (128 * \
  508. (3 + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + \
  509. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
  510. #define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc)
  511. /*
  512. * Growing the rt section of the filesystem.
  513. * In the second set of transactions (ZERO) we zero the new metadata blocks.
  514. * one bitmap/summary block: blocksize
  515. */
  516. #define XFS_CALC_GROWRTZERO_LOG_RES(mp) \
  517. ((mp)->m_sb.sb_blocksize + 128)
  518. #define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero)
  519. /*
  520. * Growing the rt section of the filesystem.
  521. * In the third set of transactions (FREE) we update metadata without
  522. * allocating any new blocks.
  523. * superblock: sector size
  524. * bitmap inode: inode size
  525. * summary inode: inode size
  526. * one bitmap block: blocksize
  527. * summary blocks: new summary size
  528. */
  529. #define XFS_CALC_GROWRTFREE_LOG_RES(mp) \
  530. ((mp)->m_sb.sb_sectsize + \
  531. 2 * (mp)->m_sb.sb_inodesize + \
  532. (mp)->m_sb.sb_blocksize + \
  533. (mp)->m_rsumsize + \
  534. (128 * 5))
  535. #define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree)
  536. /*
  537. * Logging the inode modification timestamp on a synchronous write.
  538. * inode
  539. */
  540. #define XFS_CALC_SWRITE_LOG_RES(mp) \
  541. ((mp)->m_sb.sb_inodesize + 128)
  542. #define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  543. /*
  544. * Logging the inode timestamps on an fsync -- same as SWRITE
  545. * as long as SWRITE logs the entire inode core
  546. */
  547. #define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  548. /*
  549. * Logging the inode mode bits when writing a setuid/setgid file
  550. * inode
  551. */
  552. #define XFS_CALC_WRITEID_LOG_RES(mp) \
  553. ((mp)->m_sb.sb_inodesize + 128)
  554. #define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  555. /*
  556. * Converting the inode from non-attributed to attributed.
  557. * the inode being converted: inode size
  558. * agf block and superblock (for block allocation)
  559. * the new block (directory sized)
  560. * bmap blocks for the new directory block
  561. * allocation btrees
  562. */
  563. #define XFS_CALC_ADDAFORK_LOG_RES(mp) \
  564. ((mp)->m_sb.sb_inodesize + \
  565. (mp)->m_sb.sb_sectsize * 2 + \
  566. (mp)->m_dirblksize + \
  567. XFS_FSB_TO_B(mp, (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1)) + \
  568. XFS_ALLOCFREE_LOG_RES(mp, 1) + \
  569. (128 * (4 + (XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1) + \
  570. XFS_ALLOCFREE_LOG_COUNT(mp, 1))))
  571. #define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork)
  572. /*
  573. * Removing the attribute fork of a file
  574. * the inode being truncated: inode size
  575. * the inode's bmap btree: max depth * block size
  576. * And the bmap_finish transaction can free the blocks and bmap blocks:
  577. * the agf for each of the ags: 4 * sector size
  578. * the agfl for each of the ags: 4 * sector size
  579. * the super block to reflect the freed blocks: sector size
  580. * worst case split in allocation btrees per extent assuming 4 extents:
  581. * 4 exts * 2 trees * (2 * max depth - 1) * block size
  582. */
  583. #define XFS_CALC_ATTRINVAL_LOG_RES(mp) \
  584. (MAX( \
  585. ((mp)->m_sb.sb_inodesize + \
  586. XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \
  587. (128 * (1 + XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)))), \
  588. ((4 * (mp)->m_sb.sb_sectsize) + \
  589. (4 * (mp)->m_sb.sb_sectsize) + \
  590. (mp)->m_sb.sb_sectsize + \
  591. XFS_ALLOCFREE_LOG_RES(mp, 4) + \
  592. (128 * (9 + XFS_ALLOCFREE_LOG_COUNT(mp, 4))))))
  593. #define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval)
  594. /*
  595. * Setting an attribute.
  596. * the inode getting the attribute
  597. * the superblock for allocations
  598. * the agfs extents are allocated from
  599. * the attribute btree * max depth
  600. * the inode allocation btree
  601. * Since attribute transaction space is dependent on the size of the attribute,
  602. * the calculation is done partially at mount time and partially at runtime.
  603. */
  604. #define XFS_CALC_ATTRSET_LOG_RES(mp) \
  605. ((mp)->m_sb.sb_inodesize + \
  606. (mp)->m_sb.sb_sectsize + \
  607. XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \
  608. (128 * (2 + XFS_DA_NODE_MAXDEPTH)))
  609. #define XFS_ATTRSET_LOG_RES(mp, ext) \
  610. ((mp)->m_reservations.tr_attrset + \
  611. (ext * (mp)->m_sb.sb_sectsize) + \
  612. (ext * XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK))) + \
  613. (128 * (ext + (ext * XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)))))
  614. /*
  615. * Removing an attribute.
  616. * the inode: inode size
  617. * the attribute btree could join: max depth * block size
  618. * the inode bmap btree could join or split: max depth * block size
  619. * And the bmap_finish transaction can free the attr blocks freed giving:
  620. * the agf for the ag in which the blocks live: 2 * sector size
  621. * the agfl for the ag in which the blocks live: 2 * sector size
  622. * the superblock for the free block count: sector size
  623. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  624. */
  625. #define XFS_CALC_ATTRRM_LOG_RES(mp) \
  626. (MAX( \
  627. ((mp)->m_sb.sb_inodesize + \
  628. XFS_FSB_TO_B((mp), XFS_DA_NODE_MAXDEPTH) + \
  629. XFS_FSB_TO_B((mp), XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + \
  630. (128 * (1 + XFS_DA_NODE_MAXDEPTH + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK)))), \
  631. ((2 * (mp)->m_sb.sb_sectsize) + \
  632. (2 * (mp)->m_sb.sb_sectsize) + \
  633. (mp)->m_sb.sb_sectsize + \
  634. XFS_ALLOCFREE_LOG_RES(mp, 2) + \
  635. (128 * (5 + XFS_ALLOCFREE_LOG_COUNT(mp, 2))))))
  636. #define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm)
  637. /*
  638. * Clearing a bad agino number in an agi hash bucket.
  639. */
  640. #define XFS_CALC_CLEAR_AGI_BUCKET_LOG_RES(mp) \
  641. ((mp)->m_sb.sb_sectsize + 128)
  642. #define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi)
  643. /*
  644. * Various log count values.
  645. */
  646. #define XFS_DEFAULT_LOG_COUNT 1
  647. #define XFS_DEFAULT_PERM_LOG_COUNT 2
  648. #define XFS_ITRUNCATE_LOG_COUNT 2
  649. #define XFS_INACTIVE_LOG_COUNT 2
  650. #define XFS_CREATE_LOG_COUNT 2
  651. #define XFS_MKDIR_LOG_COUNT 3
  652. #define XFS_SYMLINK_LOG_COUNT 3
  653. #define XFS_REMOVE_LOG_COUNT 2
  654. #define XFS_LINK_LOG_COUNT 2
  655. #define XFS_RENAME_LOG_COUNT 2
  656. #define XFS_WRITE_LOG_COUNT 2
  657. #define XFS_ADDAFORK_LOG_COUNT 2
  658. #define XFS_ATTRINVAL_LOG_COUNT 1
  659. #define XFS_ATTRSET_LOG_COUNT 3
  660. #define XFS_ATTRRM_LOG_COUNT 3
  661. /*
  662. * Here we centralize the specification of XFS meta-data buffer
  663. * reference count values. This determine how hard the buffer
  664. * cache tries to hold onto the buffer.
  665. */
  666. #define XFS_AGF_REF 4
  667. #define XFS_AGI_REF 4
  668. #define XFS_AGFL_REF 3
  669. #define XFS_INO_BTREE_REF 3
  670. #define XFS_ALLOC_BTREE_REF 2
  671. #define XFS_BMAP_BTREE_REF 2
  672. #define XFS_DIR_BTREE_REF 2
  673. #define XFS_ATTR_BTREE_REF 1
  674. #define XFS_INO_REF 1
  675. #define XFS_DQUOT_REF 1
  676. #ifdef __KERNEL__
  677. struct xfs_buf;
  678. struct xfs_buftarg;
  679. struct xfs_efd_log_item;
  680. struct xfs_efi_log_item;
  681. struct xfs_inode;
  682. struct xfs_item_ops;
  683. struct xfs_log_iovec;
  684. struct xfs_log_item_desc;
  685. struct xfs_mount;
  686. struct xfs_trans;
  687. struct xfs_dquot_acct;
  688. typedef struct xfs_log_item {
  689. struct list_head li_ail; /* AIL pointers */
  690. xfs_lsn_t li_lsn; /* last on-disk lsn */
  691. struct xfs_log_item_desc *li_desc; /* ptr to current desc*/
  692. struct xfs_mount *li_mountp; /* ptr to fs mount */
  693. struct xfs_ail *li_ailp; /* ptr to AIL */
  694. uint li_type; /* item type */
  695. uint li_flags; /* misc flags */
  696. struct xfs_log_item *li_bio_list; /* buffer item list */
  697. void (*li_cb)(struct xfs_buf *,
  698. struct xfs_log_item *);
  699. /* buffer item iodone */
  700. /* callback func */
  701. struct xfs_item_ops *li_ops; /* function list */
  702. } xfs_log_item_t;
  703. #define XFS_LI_IN_AIL 0x1
  704. #define XFS_LI_ABORTED 0x2
  705. typedef struct xfs_item_ops {
  706. uint (*iop_size)(xfs_log_item_t *);
  707. void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *);
  708. void (*iop_pin)(xfs_log_item_t *);
  709. void (*iop_unpin)(xfs_log_item_t *, int);
  710. void (*iop_unpin_remove)(xfs_log_item_t *, struct xfs_trans *);
  711. uint (*iop_trylock)(xfs_log_item_t *);
  712. void (*iop_unlock)(xfs_log_item_t *);
  713. xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t);
  714. void (*iop_push)(xfs_log_item_t *);
  715. void (*iop_pushbuf)(xfs_log_item_t *);
  716. void (*iop_committing)(xfs_log_item_t *, xfs_lsn_t);
  717. } xfs_item_ops_t;
  718. #define IOP_SIZE(ip) (*(ip)->li_ops->iop_size)(ip)
  719. #define IOP_FORMAT(ip,vp) (*(ip)->li_ops->iop_format)(ip, vp)
  720. #define IOP_PIN(ip) (*(ip)->li_ops->iop_pin)(ip)
  721. #define IOP_UNPIN(ip, flags) (*(ip)->li_ops->iop_unpin)(ip, flags)
  722. #define IOP_UNPIN_REMOVE(ip,tp) (*(ip)->li_ops->iop_unpin_remove)(ip, tp)
  723. #define IOP_TRYLOCK(ip) (*(ip)->li_ops->iop_trylock)(ip)
  724. #define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip)
  725. #define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn)
  726. #define IOP_PUSH(ip) (*(ip)->li_ops->iop_push)(ip)
  727. #define IOP_PUSHBUF(ip) (*(ip)->li_ops->iop_pushbuf)(ip)
  728. #define IOP_COMMITTING(ip, lsn) (*(ip)->li_ops->iop_committing)(ip, lsn)
  729. /*
  730. * Return values for the IOP_TRYLOCK() routines.
  731. */
  732. #define XFS_ITEM_SUCCESS 0
  733. #define XFS_ITEM_PINNED 1
  734. #define XFS_ITEM_LOCKED 2
  735. #define XFS_ITEM_FLUSHING 3
  736. #define XFS_ITEM_PUSHBUF 4
  737. /*
  738. * This structure is used to maintain a list of block ranges that have been
  739. * freed in the transaction. The ranges are listed in the perag[] busy list
  740. * between when they're freed and the transaction is committed to disk.
  741. */
  742. typedef struct xfs_log_busy_slot {
  743. xfs_agnumber_t lbc_ag;
  744. ushort lbc_idx; /* index in perag.busy[] */
  745. } xfs_log_busy_slot_t;
  746. #define XFS_LBC_NUM_SLOTS 31
  747. typedef struct xfs_log_busy_chunk {
  748. struct xfs_log_busy_chunk *lbc_next;
  749. uint lbc_free; /* free slots bitmask */
  750. ushort lbc_unused; /* first unused */
  751. xfs_log_busy_slot_t lbc_busy[XFS_LBC_NUM_SLOTS];
  752. } xfs_log_busy_chunk_t;
  753. #define XFS_LBC_MAX_SLOT (XFS_LBC_NUM_SLOTS - 1)
  754. #define XFS_LBC_FREEMASK ((1U << XFS_LBC_NUM_SLOTS) - 1)
  755. #define XFS_LBC_INIT(cp) ((cp)->lbc_free = XFS_LBC_FREEMASK)
  756. #define XFS_LBC_CLAIM(cp, slot) ((cp)->lbc_free &= ~(1 << (slot)))
  757. #define XFS_LBC_SLOT(cp, slot) (&((cp)->lbc_busy[(slot)]))
  758. #define XFS_LBC_VACANCY(cp) (((cp)->lbc_free) & XFS_LBC_FREEMASK)
  759. #define XFS_LBC_ISFREE(cp, slot) ((cp)->lbc_free & (1 << (slot)))
  760. /*
  761. * This is the type of function which can be given to xfs_trans_callback()
  762. * to be called upon the transaction's commit to disk.
  763. */
  764. typedef void (*xfs_trans_callback_t)(struct xfs_trans *, void *);
  765. /*
  766. * This is the structure maintained for every active transaction.
  767. */
  768. typedef struct xfs_trans {
  769. unsigned int t_magic; /* magic number */
  770. xfs_log_callback_t t_logcb; /* log callback struct */
  771. unsigned int t_type; /* transaction type */
  772. unsigned int t_log_res; /* amt of log space resvd */
  773. unsigned int t_log_count; /* count for perm log res */
  774. unsigned int t_blk_res; /* # of blocks resvd */
  775. unsigned int t_blk_res_used; /* # of resvd blocks used */
  776. unsigned int t_rtx_res; /* # of rt extents resvd */
  777. unsigned int t_rtx_res_used; /* # of resvd rt extents used */
  778. xfs_log_ticket_t t_ticket; /* log mgr ticket */
  779. xfs_lsn_t t_lsn; /* log seq num of start of
  780. * transaction. */
  781. xfs_lsn_t t_commit_lsn; /* log seq num of end of
  782. * transaction. */
  783. struct xfs_mount *t_mountp; /* ptr to fs mount struct */
  784. struct xfs_dquot_acct *t_dqinfo; /* acctg info for dquots */
  785. xfs_trans_callback_t t_callback; /* transaction callback */
  786. void *t_callarg; /* callback arg */
  787. unsigned int t_flags; /* misc flags */
  788. int64_t t_icount_delta; /* superblock icount change */
  789. int64_t t_ifree_delta; /* superblock ifree change */
  790. int64_t t_fdblocks_delta; /* superblock fdblocks chg */
  791. int64_t t_res_fdblocks_delta; /* on-disk only chg */
  792. int64_t t_frextents_delta;/* superblock freextents chg*/
  793. int64_t t_res_frextents_delta; /* on-disk only chg */
  794. #ifdef DEBUG
  795. int64_t t_ag_freeblks_delta; /* debugging counter */
  796. int64_t t_ag_flist_delta; /* debugging counter */
  797. int64_t t_ag_btree_delta; /* debugging counter */
  798. #endif
  799. int64_t t_dblocks_delta;/* superblock dblocks change */
  800. int64_t t_agcount_delta;/* superblock agcount change */
  801. int64_t t_imaxpct_delta;/* superblock imaxpct change */
  802. int64_t t_rextsize_delta;/* superblock rextsize chg */
  803. int64_t t_rbmblocks_delta;/* superblock rbmblocks chg */
  804. int64_t t_rblocks_delta;/* superblock rblocks change */
  805. int64_t t_rextents_delta;/* superblocks rextents chg */
  806. int64_t t_rextslog_delta;/* superblocks rextslog chg */
  807. unsigned int t_items_free; /* log item descs free */
  808. xfs_log_item_chunk_t t_items; /* first log item desc chunk */
  809. xfs_trans_header_t t_header; /* header for in-log trans */
  810. unsigned int t_busy_free; /* busy descs free */
  811. xfs_log_busy_chunk_t t_busy; /* busy/async free blocks */
  812. unsigned long t_pflags; /* saved process flags state */
  813. } xfs_trans_t;
  814. /*
  815. * XFS transaction mechanism exported interfaces that are
  816. * actually macros.
  817. */
  818. #define xfs_trans_get_log_res(tp) ((tp)->t_log_res)
  819. #define xfs_trans_get_log_count(tp) ((tp)->t_log_count)
  820. #define xfs_trans_get_block_res(tp) ((tp)->t_blk_res)
  821. #define xfs_trans_set_sync(tp) ((tp)->t_flags |= XFS_TRANS_SYNC)
  822. #ifdef DEBUG
  823. #define xfs_trans_agblocks_delta(tp, d) ((tp)->t_ag_freeblks_delta += (int64_t)d)
  824. #define xfs_trans_agflist_delta(tp, d) ((tp)->t_ag_flist_delta += (int64_t)d)
  825. #define xfs_trans_agbtree_delta(tp, d) ((tp)->t_ag_btree_delta += (int64_t)d)
  826. #else
  827. #define xfs_trans_agblocks_delta(tp, d)
  828. #define xfs_trans_agflist_delta(tp, d)
  829. #define xfs_trans_agbtree_delta(tp, d)
  830. #endif
  831. /*
  832. * XFS transaction mechanism exported interfaces.
  833. */
  834. xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint);
  835. xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint);
  836. xfs_trans_t *xfs_trans_dup(xfs_trans_t *);
  837. int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint,
  838. uint, uint);
  839. void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
  840. struct xfs_buf *xfs_trans_get_buf(xfs_trans_t *, struct xfs_buftarg *, xfs_daddr_t,
  841. int, uint);
  842. int xfs_trans_read_buf(struct xfs_mount *, xfs_trans_t *,
  843. struct xfs_buftarg *, xfs_daddr_t, int, uint,
  844. struct xfs_buf **);
  845. struct xfs_buf *xfs_trans_getsb(xfs_trans_t *, struct xfs_mount *, int);
  846. void xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *);
  847. void xfs_trans_bjoin(xfs_trans_t *, struct xfs_buf *);
  848. void xfs_trans_bhold(xfs_trans_t *, struct xfs_buf *);
  849. void xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *);
  850. void xfs_trans_binval(xfs_trans_t *, struct xfs_buf *);
  851. void xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
  852. void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);
  853. void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
  854. void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
  855. int xfs_trans_iget(struct xfs_mount *, xfs_trans_t *,
  856. xfs_ino_t , uint, uint, struct xfs_inode **);
  857. void xfs_trans_ijoin(xfs_trans_t *, struct xfs_inode *, uint);
  858. void xfs_trans_ihold(xfs_trans_t *, struct xfs_inode *);
  859. void xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint);
  860. void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
  861. struct xfs_efi_log_item *xfs_trans_get_efi(xfs_trans_t *, uint);
  862. void xfs_efi_release(struct xfs_efi_log_item *, uint);
  863. void xfs_trans_log_efi_extent(xfs_trans_t *,
  864. struct xfs_efi_log_item *,
  865. xfs_fsblock_t,
  866. xfs_extlen_t);
  867. struct xfs_efd_log_item *xfs_trans_get_efd(xfs_trans_t *,
  868. struct xfs_efi_log_item *,
  869. uint);
  870. void xfs_trans_log_efd_extent(xfs_trans_t *,
  871. struct xfs_efd_log_item *,
  872. xfs_fsblock_t,
  873. xfs_extlen_t);
  874. int _xfs_trans_commit(xfs_trans_t *,
  875. uint flags,
  876. int *);
  877. #define xfs_trans_commit(tp, flags) _xfs_trans_commit(tp, flags, NULL)
  878. void xfs_trans_cancel(xfs_trans_t *, int);
  879. int xfs_trans_ail_init(struct xfs_mount *);
  880. void xfs_trans_ail_destroy(struct xfs_mount *);
  881. xfs_log_busy_slot_t *xfs_trans_add_busy(xfs_trans_t *tp,
  882. xfs_agnumber_t ag,
  883. xfs_extlen_t idx);
  884. extern kmem_zone_t *xfs_trans_zone;
  885. #endif /* __KERNEL__ */
  886. void xfs_trans_init(struct xfs_mount *);
  887. int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
  888. #endif /* __XFS_TRANS_H__ */