xfs_trans.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. struct xfs_log_item;
  21. /*
  22. * Per-extent log reservation for the allocation btree changes
  23. * involved in freeing or allocating an extent.
  24. * 2 trees * (2 blocks/level * max depth - 1)
  25. */
  26. #define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
  27. ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
  28. /*
  29. * Per-directory log reservation for any directory change.
  30. * dir blocks: (1 btree block per level + data block + free block)
  31. * bmap btree: (levels + 2) * max depth
  32. * v2 directory blocks can be fragmented below the dirblksize down to the fsb
  33. * size, so account for that in the DAENTER macros.
  34. */
  35. #define XFS_DIROP_LOG_COUNT(mp) \
  36. (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \
  37. XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)
  38. #define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write)
  39. #define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate)
  40. #define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename)
  41. #define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link)
  42. #define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove)
  43. #define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink)
  44. #define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create)
  45. #define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir)
  46. #define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree)
  47. #define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange)
  48. #define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata)
  49. #define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc)
  50. #define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero)
  51. #define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree)
  52. #define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  53. /*
  54. * Logging the inode timestamps on an fsync -- same as SWRITE
  55. * as long as SWRITE logs the entire inode core
  56. */
  57. #define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  58. #define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
  59. #define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork)
  60. #define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval)
  61. #define XFS_ATTRSETM_LOG_RES(mp) ((mp)->m_reservations.tr_attrsetm)
  62. #define XFS_ATTRSETRT_LOG_RES(mp) ((mp)->m_reservations.tr_attrsetrt)
  63. #define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm)
  64. #define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi)
  65. #define XFS_QM_SBCHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_qm_sbchange)
  66. #define XFS_QM_SETQLIM_LOG_RES(mp) ((mp)->m_reservations.tr_qm_setqlim)
  67. #define XFS_QM_DQALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_qm_dqalloc)
  68. #define XFS_QM_QUOTAOFF_LOG_RES(mp) ((mp)->m_reservations.tr_qm_quotaoff)
  69. #define XFS_QM_QUOTAOFF_END_LOG_RES(mp) ((mp)->m_reservations.tr_qm_equotaoff)
  70. #define XFS_SB_LOG_RES(mp) ((mp)->m_reservations.tr_sb)
  71. /*
  72. * Various log count values.
  73. */
  74. #define XFS_DEFAULT_LOG_COUNT 1
  75. #define XFS_DEFAULT_PERM_LOG_COUNT 2
  76. #define XFS_ITRUNCATE_LOG_COUNT 2
  77. #define XFS_INACTIVE_LOG_COUNT 2
  78. #define XFS_CREATE_LOG_COUNT 2
  79. #define XFS_MKDIR_LOG_COUNT 3
  80. #define XFS_SYMLINK_LOG_COUNT 3
  81. #define XFS_REMOVE_LOG_COUNT 2
  82. #define XFS_LINK_LOG_COUNT 2
  83. #define XFS_RENAME_LOG_COUNT 2
  84. #define XFS_WRITE_LOG_COUNT 2
  85. #define XFS_ADDAFORK_LOG_COUNT 2
  86. #define XFS_ATTRINVAL_LOG_COUNT 1
  87. #define XFS_ATTRSET_LOG_COUNT 3
  88. #define XFS_ATTRRM_LOG_COUNT 3
  89. #ifdef __KERNEL__
  90. struct xfs_buf;
  91. struct xfs_buftarg;
  92. struct xfs_efd_log_item;
  93. struct xfs_efi_log_item;
  94. struct xfs_inode;
  95. struct xfs_item_ops;
  96. struct xfs_log_iovec;
  97. struct xfs_log_item_desc;
  98. struct xfs_mount;
  99. struct xfs_trans;
  100. struct xfs_dquot_acct;
  101. struct xfs_busy_extent;
  102. typedef struct xfs_log_item {
  103. struct list_head li_ail; /* AIL pointers */
  104. xfs_lsn_t li_lsn; /* last on-disk lsn */
  105. struct xfs_log_item_desc *li_desc; /* ptr to current desc*/
  106. struct xfs_mount *li_mountp; /* ptr to fs mount */
  107. struct xfs_ail *li_ailp; /* ptr to AIL */
  108. uint li_type; /* item type */
  109. uint li_flags; /* misc flags */
  110. struct xfs_log_item *li_bio_list; /* buffer item list */
  111. void (*li_cb)(struct xfs_buf *,
  112. struct xfs_log_item *);
  113. /* buffer item iodone */
  114. /* callback func */
  115. const struct xfs_item_ops *li_ops; /* function list */
  116. /* delayed logging */
  117. struct list_head li_cil; /* CIL pointers */
  118. struct xfs_log_vec *li_lv; /* active log vector */
  119. xfs_lsn_t li_seq; /* CIL commit seq */
  120. } xfs_log_item_t;
  121. #define XFS_LI_IN_AIL 0x1
  122. #define XFS_LI_ABORTED 0x2
  123. #define XFS_LI_FLAGS \
  124. { XFS_LI_IN_AIL, "IN_AIL" }, \
  125. { XFS_LI_ABORTED, "ABORTED" }
  126. struct xfs_item_ops {
  127. uint (*iop_size)(xfs_log_item_t *);
  128. void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *);
  129. void (*iop_pin)(xfs_log_item_t *);
  130. void (*iop_unpin)(xfs_log_item_t *, int remove);
  131. uint (*iop_push)(struct xfs_log_item *, struct list_head *);
  132. void (*iop_unlock)(xfs_log_item_t *);
  133. xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t);
  134. void (*iop_committing)(xfs_log_item_t *, xfs_lsn_t);
  135. };
  136. #define IOP_SIZE(ip) (*(ip)->li_ops->iop_size)(ip)
  137. #define IOP_FORMAT(ip,vp) (*(ip)->li_ops->iop_format)(ip, vp)
  138. #define IOP_PIN(ip) (*(ip)->li_ops->iop_pin)(ip)
  139. #define IOP_UNPIN(ip, remove) (*(ip)->li_ops->iop_unpin)(ip, remove)
  140. #define IOP_PUSH(ip, list) (*(ip)->li_ops->iop_push)(ip, list)
  141. #define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip)
  142. #define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn)
  143. #define IOP_COMMITTING(ip, lsn) (*(ip)->li_ops->iop_committing)(ip, lsn)
  144. /*
  145. * Return values for the IOP_PUSH() routines.
  146. */
  147. #define XFS_ITEM_SUCCESS 0
  148. #define XFS_ITEM_PINNED 1
  149. #define XFS_ITEM_LOCKED 2
  150. #define XFS_ITEM_FLUSHING 3
  151. /*
  152. * This is the type of function which can be given to xfs_trans_callback()
  153. * to be called upon the transaction's commit to disk.
  154. */
  155. typedef void (*xfs_trans_callback_t)(struct xfs_trans *, void *);
  156. /*
  157. * This is the structure maintained for every active transaction.
  158. */
  159. typedef struct xfs_trans {
  160. unsigned int t_magic; /* magic number */
  161. xfs_log_callback_t t_logcb; /* log callback struct */
  162. unsigned int t_type; /* transaction type */
  163. unsigned int t_log_res; /* amt of log space resvd */
  164. unsigned int t_log_count; /* count for perm log res */
  165. unsigned int t_blk_res; /* # of blocks resvd */
  166. unsigned int t_blk_res_used; /* # of resvd blocks used */
  167. unsigned int t_rtx_res; /* # of rt extents resvd */
  168. unsigned int t_rtx_res_used; /* # of resvd rt extents used */
  169. struct xlog_ticket *t_ticket; /* log mgr ticket */
  170. xfs_lsn_t t_lsn; /* log seq num of start of
  171. * transaction. */
  172. xfs_lsn_t t_commit_lsn; /* log seq num of end of
  173. * transaction. */
  174. struct xfs_mount *t_mountp; /* ptr to fs mount struct */
  175. struct xfs_dquot_acct *t_dqinfo; /* acctg info for dquots */
  176. unsigned int t_flags; /* misc flags */
  177. int64_t t_icount_delta; /* superblock icount change */
  178. int64_t t_ifree_delta; /* superblock ifree change */
  179. int64_t t_fdblocks_delta; /* superblock fdblocks chg */
  180. int64_t t_res_fdblocks_delta; /* on-disk only chg */
  181. int64_t t_frextents_delta;/* superblock freextents chg*/
  182. int64_t t_res_frextents_delta; /* on-disk only chg */
  183. #if defined(DEBUG) || defined(XFS_WARN)
  184. int64_t t_ag_freeblks_delta; /* debugging counter */
  185. int64_t t_ag_flist_delta; /* debugging counter */
  186. int64_t t_ag_btree_delta; /* debugging counter */
  187. #endif
  188. int64_t t_dblocks_delta;/* superblock dblocks change */
  189. int64_t t_agcount_delta;/* superblock agcount change */
  190. int64_t t_imaxpct_delta;/* superblock imaxpct change */
  191. int64_t t_rextsize_delta;/* superblock rextsize chg */
  192. int64_t t_rbmblocks_delta;/* superblock rbmblocks chg */
  193. int64_t t_rblocks_delta;/* superblock rblocks change */
  194. int64_t t_rextents_delta;/* superblocks rextents chg */
  195. int64_t t_rextslog_delta;/* superblocks rextslog chg */
  196. struct list_head t_items; /* log item descriptors */
  197. xfs_trans_header_t t_header; /* header for in-log trans */
  198. struct list_head t_busy; /* list of busy extents */
  199. unsigned long t_pflags; /* saved process flags state */
  200. } xfs_trans_t;
  201. /*
  202. * XFS transaction mechanism exported interfaces that are
  203. * actually macros.
  204. */
  205. #define xfs_trans_get_log_res(tp) ((tp)->t_log_res)
  206. #define xfs_trans_get_log_count(tp) ((tp)->t_log_count)
  207. #define xfs_trans_get_block_res(tp) ((tp)->t_blk_res)
  208. #define xfs_trans_set_sync(tp) ((tp)->t_flags |= XFS_TRANS_SYNC)
  209. #if defined(DEBUG) || defined(XFS_WARN)
  210. #define xfs_trans_agblocks_delta(tp, d) ((tp)->t_ag_freeblks_delta += (int64_t)d)
  211. #define xfs_trans_agflist_delta(tp, d) ((tp)->t_ag_flist_delta += (int64_t)d)
  212. #define xfs_trans_agbtree_delta(tp, d) ((tp)->t_ag_btree_delta += (int64_t)d)
  213. #else
  214. #define xfs_trans_agblocks_delta(tp, d)
  215. #define xfs_trans_agflist_delta(tp, d)
  216. #define xfs_trans_agbtree_delta(tp, d)
  217. #endif
  218. /*
  219. * XFS transaction mechanism exported interfaces.
  220. */
  221. xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint);
  222. xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, xfs_km_flags_t);
  223. xfs_trans_t *xfs_trans_dup(xfs_trans_t *);
  224. int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint,
  225. uint, uint);
  226. void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
  227. struct xfs_buf *xfs_trans_get_buf_map(struct xfs_trans *tp,
  228. struct xfs_buftarg *target,
  229. struct xfs_buf_map *map, int nmaps,
  230. uint flags);
  231. static inline struct xfs_buf *
  232. xfs_trans_get_buf(
  233. struct xfs_trans *tp,
  234. struct xfs_buftarg *target,
  235. xfs_daddr_t blkno,
  236. int numblks,
  237. uint flags)
  238. {
  239. DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
  240. return xfs_trans_get_buf_map(tp, target, &map, 1, flags);
  241. }
  242. int xfs_trans_read_buf_map(struct xfs_mount *mp,
  243. struct xfs_trans *tp,
  244. struct xfs_buftarg *target,
  245. struct xfs_buf_map *map, int nmaps,
  246. xfs_buf_flags_t flags,
  247. struct xfs_buf **bpp,
  248. const struct xfs_buf_ops *ops);
  249. static inline int
  250. xfs_trans_read_buf(
  251. struct xfs_mount *mp,
  252. struct xfs_trans *tp,
  253. struct xfs_buftarg *target,
  254. xfs_daddr_t blkno,
  255. int numblks,
  256. xfs_buf_flags_t flags,
  257. struct xfs_buf **bpp,
  258. const struct xfs_buf_ops *ops)
  259. {
  260. DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
  261. return xfs_trans_read_buf_map(mp, tp, target, &map, 1,
  262. flags, bpp, ops);
  263. }
  264. struct xfs_buf *xfs_trans_getsb(xfs_trans_t *, struct xfs_mount *, int);
  265. void xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *);
  266. void xfs_trans_bjoin(xfs_trans_t *, struct xfs_buf *);
  267. void xfs_trans_bhold(xfs_trans_t *, struct xfs_buf *);
  268. void xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *);
  269. void xfs_trans_binval(xfs_trans_t *, struct xfs_buf *);
  270. void xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
  271. void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);
  272. void xfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *);
  273. void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
  274. void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
  275. void xfs_trans_ichgtime(struct xfs_trans *, struct xfs_inode *, int);
  276. void xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
  277. void xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint);
  278. void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
  279. struct xfs_efi_log_item *xfs_trans_get_efi(xfs_trans_t *, uint);
  280. void xfs_efi_release(struct xfs_efi_log_item *, uint);
  281. void xfs_trans_log_efi_extent(xfs_trans_t *,
  282. struct xfs_efi_log_item *,
  283. xfs_fsblock_t,
  284. xfs_extlen_t);
  285. struct xfs_efd_log_item *xfs_trans_get_efd(xfs_trans_t *,
  286. struct xfs_efi_log_item *,
  287. uint);
  288. void xfs_trans_log_efd_extent(xfs_trans_t *,
  289. struct xfs_efd_log_item *,
  290. xfs_fsblock_t,
  291. xfs_extlen_t);
  292. int xfs_trans_commit(xfs_trans_t *, uint flags);
  293. void xfs_trans_cancel(xfs_trans_t *, int);
  294. int xfs_trans_ail_init(struct xfs_mount *);
  295. void xfs_trans_ail_destroy(struct xfs_mount *);
  296. extern kmem_zone_t *xfs_trans_zone;
  297. extern kmem_zone_t *xfs_log_item_desc_zone;
  298. #endif /* __KERNEL__ */
  299. #endif /* __XFS_TRANS_H__ */