xfs_trans.h 36 KB

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