xfs_trans.h 36 KB

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