xfs_trans.h 36 KB

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