xfs_trans.h 36 KB

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