xfs_trans.h 38 KB

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