xfs_trans.h 38 KB

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