xfs_trans.h 37 KB

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