xfs_trans.h 38 KB

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