xfs_trans.h 36 KB

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