xfs_trans.h 37 KB

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