xfs_trans.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_TRANS_H__
  7. #define __XFS_TRANS_H__
  8. /* kernel only transaction subsystem defines */
  9. struct xlog;
  10. struct xfs_buf;
  11. struct xfs_buftarg;
  12. struct xfs_efd_log_item;
  13. struct xfs_efi_log_item;
  14. struct xfs_inode;
  15. struct xfs_item_ops;
  16. struct xfs_log_iovec;
  17. struct xfs_mount;
  18. struct xfs_trans;
  19. struct xfs_trans_res;
  20. struct xfs_dquot_acct;
  21. struct xfs_rud_log_item;
  22. struct xfs_rui_log_item;
  23. struct xfs_btree_cur;
  24. struct xfs_cui_log_item;
  25. struct xfs_cud_log_item;
  26. struct xfs_bui_log_item;
  27. struct xfs_bud_log_item;
  28. struct xfs_log_item {
  29. struct list_head li_ail; /* AIL pointers */
  30. struct list_head li_trans; /* transaction list */
  31. xfs_lsn_t li_lsn; /* last on-disk lsn */
  32. struct xlog *li_log;
  33. struct xfs_ail *li_ailp; /* ptr to AIL */
  34. uint li_type; /* item type */
  35. unsigned long li_flags; /* misc flags */
  36. struct xfs_buf *li_buf; /* real buffer pointer */
  37. struct list_head li_bio_list; /* buffer item list */
  38. const struct xfs_item_ops *li_ops; /* function list */
  39. /* delayed logging */
  40. struct list_head li_cil; /* CIL pointers */
  41. struct xfs_log_vec *li_lv; /* active log vector */
  42. struct xfs_log_vec *li_lv_shadow; /* standby vector */
  43. xfs_csn_t li_seq; /* CIL commit seq */
  44. uint32_t li_order_id; /* CIL commit order */
  45. };
  46. /*
  47. * li_flags use the (set/test/clear)_bit atomic interfaces because updates can
  48. * race with each other and we don't want to have to use the AIL lock to
  49. * serialise all updates.
  50. */
  51. #define XFS_LI_IN_AIL 0
  52. #define XFS_LI_ABORTED 1
  53. #define XFS_LI_FAILED 2
  54. #define XFS_LI_DIRTY 3
  55. #define XFS_LI_WHITEOUT 4
  56. #define XFS_LI_FLAGS \
  57. { (1u << XFS_LI_IN_AIL), "IN_AIL" }, \
  58. { (1u << XFS_LI_ABORTED), "ABORTED" }, \
  59. { (1u << XFS_LI_FAILED), "FAILED" }, \
  60. { (1u << XFS_LI_DIRTY), "DIRTY" }, \
  61. { (1u << XFS_LI_WHITEOUT), "WHITEOUT" }
  62. struct xfs_item_ops {
  63. unsigned flags;
  64. void (*iop_size)(struct xfs_log_item *, int *, int *);
  65. void (*iop_format)(struct xfs_log_item *, struct xfs_log_vec *);
  66. void (*iop_pin)(struct xfs_log_item *);
  67. void (*iop_unpin)(struct xfs_log_item *, int remove);
  68. uint64_t (*iop_sort)(struct xfs_log_item *lip);
  69. int (*iop_precommit)(struct xfs_trans *tp, struct xfs_log_item *lip);
  70. void (*iop_committing)(struct xfs_log_item *lip, xfs_csn_t seq);
  71. xfs_lsn_t (*iop_committed)(struct xfs_log_item *, xfs_lsn_t);
  72. uint (*iop_push)(struct xfs_log_item *, struct list_head *);
  73. void (*iop_release)(struct xfs_log_item *);
  74. int (*iop_recover)(struct xfs_log_item *lip,
  75. struct list_head *capture_list);
  76. bool (*iop_match)(struct xfs_log_item *item, uint64_t id);
  77. struct xfs_log_item *(*iop_relog)(struct xfs_log_item *intent,
  78. struct xfs_trans *tp);
  79. struct xfs_log_item *(*iop_intent)(struct xfs_log_item *intent_done);
  80. };
  81. /*
  82. * Log item ops flags
  83. */
  84. /*
  85. * Release the log item when the journal commits instead of inserting into the
  86. * AIL for writeback tracking and/or log tail pinning.
  87. */
  88. #define XFS_ITEM_RELEASE_WHEN_COMMITTED (1 << 0)
  89. #define XFS_ITEM_INTENT (1 << 1)
  90. #define XFS_ITEM_INTENT_DONE (1 << 2)
  91. static inline bool
  92. xlog_item_is_intent(struct xfs_log_item *lip)
  93. {
  94. return lip->li_ops->flags & XFS_ITEM_INTENT;
  95. }
  96. static inline bool
  97. xlog_item_is_intent_done(struct xfs_log_item *lip)
  98. {
  99. return lip->li_ops->flags & XFS_ITEM_INTENT_DONE;
  100. }
  101. void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,
  102. int type, const struct xfs_item_ops *ops);
  103. /*
  104. * Return values for the iop_push() routines.
  105. */
  106. #define XFS_ITEM_SUCCESS 0
  107. #define XFS_ITEM_PINNED 1
  108. #define XFS_ITEM_LOCKED 2
  109. #define XFS_ITEM_FLUSHING 3
  110. /*
  111. * This is the structure maintained for every active transaction.
  112. */
  113. typedef struct xfs_trans {
  114. unsigned int t_magic; /* magic number */
  115. unsigned int t_log_res; /* amt of log space resvd */
  116. unsigned int t_log_count; /* count for perm log res */
  117. unsigned int t_blk_res; /* # of blocks resvd */
  118. unsigned int t_blk_res_used; /* # of resvd blocks used */
  119. unsigned int t_rtx_res; /* # of rt extents resvd */
  120. unsigned int t_rtx_res_used; /* # of resvd rt extents used */
  121. unsigned int t_flags; /* misc flags */
  122. xfs_fsblock_t t_firstblock; /* first block allocated */
  123. struct xlog_ticket *t_ticket; /* log mgr ticket */
  124. struct xfs_mount *t_mountp; /* ptr to fs mount struct */
  125. struct xfs_dquot_acct *t_dqinfo; /* acctg info for dquots */
  126. int64_t t_icount_delta; /* superblock icount change */
  127. int64_t t_ifree_delta; /* superblock ifree change */
  128. int64_t t_fdblocks_delta; /* superblock fdblocks chg */
  129. int64_t t_res_fdblocks_delta; /* on-disk only chg */
  130. int64_t t_frextents_delta;/* superblock freextents chg*/
  131. int64_t t_res_frextents_delta; /* on-disk only chg */
  132. int64_t t_dblocks_delta;/* superblock dblocks change */
  133. int64_t t_agcount_delta;/* superblock agcount change */
  134. int64_t t_imaxpct_delta;/* superblock imaxpct change */
  135. int64_t t_rextsize_delta;/* superblock rextsize chg */
  136. int64_t t_rbmblocks_delta;/* superblock rbmblocks chg */
  137. int64_t t_rblocks_delta;/* superblock rblocks change */
  138. int64_t t_rextents_delta;/* superblocks rextents chg */
  139. int64_t t_rextslog_delta;/* superblocks rextslog chg */
  140. struct list_head t_items; /* log item descriptors */
  141. struct list_head t_busy; /* list of busy extents */
  142. struct list_head t_dfops; /* deferred operations */
  143. unsigned long t_pflags; /* saved process flags state */
  144. } xfs_trans_t;
  145. /*
  146. * XFS transaction mechanism exported interfaces that are
  147. * actually macros.
  148. */
  149. #define xfs_trans_set_sync(tp) ((tp)->t_flags |= XFS_TRANS_SYNC)
  150. /*
  151. * XFS transaction mechanism exported interfaces.
  152. */
  153. int xfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
  154. uint blocks, uint rtextents, uint flags,
  155. struct xfs_trans **tpp);
  156. int xfs_trans_alloc_empty(struct xfs_mount *mp,
  157. struct xfs_trans **tpp);
  158. void xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
  159. int xfs_trans_get_buf_map(struct xfs_trans *tp, struct xfs_buftarg *target,
  160. struct xfs_buf_map *map, int nmaps, xfs_buf_flags_t flags,
  161. struct xfs_buf **bpp);
  162. static inline int
  163. xfs_trans_get_buf(
  164. struct xfs_trans *tp,
  165. struct xfs_buftarg *target,
  166. xfs_daddr_t blkno,
  167. int numblks,
  168. xfs_buf_flags_t flags,
  169. struct xfs_buf **bpp)
  170. {
  171. DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
  172. return xfs_trans_get_buf_map(tp, target, &map, 1, flags, bpp);
  173. }
  174. int xfs_trans_read_buf_map(struct xfs_mount *mp,
  175. struct xfs_trans *tp,
  176. struct xfs_buftarg *target,
  177. struct xfs_buf_map *map, int nmaps,
  178. xfs_buf_flags_t flags,
  179. struct xfs_buf **bpp,
  180. const struct xfs_buf_ops *ops);
  181. static inline int
  182. xfs_trans_read_buf(
  183. struct xfs_mount *mp,
  184. struct xfs_trans *tp,
  185. struct xfs_buftarg *target,
  186. xfs_daddr_t blkno,
  187. int numblks,
  188. xfs_buf_flags_t flags,
  189. struct xfs_buf **bpp,
  190. const struct xfs_buf_ops *ops)
  191. {
  192. DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
  193. return xfs_trans_read_buf_map(mp, tp, target, &map, 1,
  194. flags, bpp, ops);
  195. }
  196. struct xfs_buf *xfs_trans_getsb(struct xfs_trans *);
  197. void xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *);
  198. void xfs_trans_bjoin(xfs_trans_t *, struct xfs_buf *);
  199. void xfs_trans_bhold(xfs_trans_t *, struct xfs_buf *);
  200. void xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *);
  201. void xfs_trans_binval(xfs_trans_t *, struct xfs_buf *);
  202. void xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
  203. void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);
  204. bool xfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *);
  205. void xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
  206. void xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
  207. void xfs_trans_ichgtime(struct xfs_trans *, struct xfs_inode *, int);
  208. void xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
  209. void xfs_trans_log_buf(struct xfs_trans *, struct xfs_buf *, uint,
  210. uint);
  211. void xfs_trans_dirty_buf(struct xfs_trans *, struct xfs_buf *);
  212. bool xfs_trans_buf_is_dirty(struct xfs_buf *bp);
  213. void xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
  214. int xfs_trans_commit(struct xfs_trans *);
  215. int xfs_trans_roll(struct xfs_trans **);
  216. int xfs_trans_roll_inode(struct xfs_trans **, struct xfs_inode *);
  217. void xfs_trans_cancel(xfs_trans_t *);
  218. int xfs_trans_ail_init(struct xfs_mount *);
  219. void xfs_trans_ail_destroy(struct xfs_mount *);
  220. void xfs_trans_buf_set_type(struct xfs_trans *, struct xfs_buf *,
  221. enum xfs_blft);
  222. void xfs_trans_buf_copy_type(struct xfs_buf *dst_bp,
  223. struct xfs_buf *src_bp);
  224. extern struct kmem_cache *xfs_trans_cache;
  225. static inline struct xfs_log_item *
  226. xfs_trans_item_relog(
  227. struct xfs_log_item *lip,
  228. struct xfs_trans *tp)
  229. {
  230. return lip->li_ops->iop_relog(lip, tp);
  231. }
  232. struct xfs_dquot;
  233. int xfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
  234. unsigned int dblocks, unsigned int rblocks, bool force,
  235. struct xfs_trans **tpp);
  236. int xfs_trans_alloc_icreate(struct xfs_mount *mp, struct xfs_trans_res *resv,
  237. struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
  238. struct xfs_dquot *pdqp, unsigned int dblocks,
  239. struct xfs_trans **tpp);
  240. int xfs_trans_alloc_ichange(struct xfs_inode *ip, struct xfs_dquot *udqp,
  241. struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, bool force,
  242. struct xfs_trans **tpp);
  243. int xfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv,
  244. struct xfs_inode *ip, unsigned int *dblocks,
  245. struct xfs_trans **tpp, int *nospace_error);
  246. static inline void
  247. xfs_trans_set_context(
  248. struct xfs_trans *tp)
  249. {
  250. ASSERT(current->journal_info == NULL);
  251. tp->t_pflags = memalloc_nofs_save();
  252. current->journal_info = tp;
  253. }
  254. static inline void
  255. xfs_trans_clear_context(
  256. struct xfs_trans *tp)
  257. {
  258. if (current->journal_info == tp) {
  259. memalloc_nofs_restore(tp->t_pflags);
  260. current->journal_info = NULL;
  261. }
  262. }
  263. static inline void
  264. xfs_trans_switch_context(
  265. struct xfs_trans *old_tp,
  266. struct xfs_trans *new_tp)
  267. {
  268. ASSERT(current->journal_info == old_tp);
  269. new_tp->t_pflags = old_tp->t_pflags;
  270. old_tp->t_pflags = 0;
  271. current->journal_info = new_tp;
  272. }
  273. #endif /* __XFS_TRANS_H__ */