xfs_trans.h 36 KB

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