xfs_trans.h 37 KB

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