Blame view

fs/xfs/xfs_trans.h 9.17 KB
0b61f8a40   Dave Chinner   xfs: convert to S...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
7b7187698   Nathan Scott   [XFS] Update lice...
3
4
   * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
   */
  #ifndef	__XFS_TRANS_H__
  #define	__XFS_TRANS_H__
7fd36c441   Dave Chinner   xfs: split out tr...
8
  /* kernel only transaction subsystem defines */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
9
10
11
12
13
14
15
16
  
  struct xfs_buf;
  struct xfs_buftarg;
  struct xfs_efd_log_item;
  struct xfs_efi_log_item;
  struct xfs_inode;
  struct xfs_item_ops;
  struct xfs_log_iovec;
847fff5ca   Barry Naujok   [XFS] Sync up ker...
17
18
  struct xfs_mount;
  struct xfs_trans;
3d3c8b522   Jie Liu   xfs: refactor xfs...
19
  struct xfs_trans_res;
847fff5ca   Barry Naujok   [XFS] Sync up ker...
20
  struct xfs_dquot_acct;
f8dbebef9   Darrick J. Wong   xfs: enable the x...
21
22
  struct xfs_rud_log_item;
  struct xfs_rui_log_item;
9c1946446   Darrick J. Wong   xfs: propagate bm...
23
  struct xfs_btree_cur;
f997ee213   Darrick J. Wong   xfs: log refcount...
24
  struct xfs_cui_log_item;
33ba61292   Darrick J. Wong   xfs: connect refc...
25
  struct xfs_cud_log_item;
77d61fe45   Darrick J. Wong   xfs: log bmap int...
26
  struct xfs_bui_log_item;
9f3afb57d   Darrick J. Wong   xfs: implement de...
27
  struct xfs_bud_log_item;
847fff5ca   Barry Naujok   [XFS] Sync up ker...
28

efe2330fd   Christoph Hellwig   xfs: remove the x...
29
  struct xfs_log_item {
847fff5ca   Barry Naujok   [XFS] Sync up ker...
30
  	struct list_head		li_ail;		/* AIL pointers */
e6631f855   Dave Chinner   xfs: get rid of t...
31
  	struct list_head		li_trans;	/* transaction list */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
32
  	xfs_lsn_t			li_lsn;		/* last on-disk lsn */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
33
  	struct xfs_mount		*li_mountp;	/* ptr to fs mount */
fc1829f34   David Chinner   [XFS] Add ail poi...
34
  	struct xfs_ail			*li_ailp;	/* ptr to AIL */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
35
  	uint				li_type;	/* item type */
22525c17e   Dave Chinner   xfs: log item fla...
36
  	unsigned long			li_flags;	/* misc flags */
d3a304b62   Carlos Maiolino   xfs: Properly ret...
37
  	struct xfs_buf			*li_buf;	/* real buffer pointer */
643c8c05e   Carlos Maiolino   Use list_head inf...
38
  	struct list_head		li_bio_list;	/* buffer item list */
272e42b21   Christoph Hellwig   xfs: constify xfs...
39
  	const struct xfs_item_ops	*li_ops;	/* function list */
71e330b59   Dave Chinner   xfs: Introduce de...
40
41
42
43
  
  	/* delayed logging */
  	struct list_head		li_cil;		/* CIL pointers */
  	struct xfs_log_vec		*li_lv;		/* active log vector */
b1c5ebb21   Dave Chinner   xfs: allocate log...
44
  	struct xfs_log_vec		*li_lv_shadow;	/* standby vector */
ccf7c23fc   Dave Chinner   xfs: Ensure inode...
45
  	xfs_lsn_t			li_seq;		/* CIL commit seq */
efe2330fd   Christoph Hellwig   xfs: remove the x...
46
  };
847fff5ca   Barry Naujok   [XFS] Sync up ker...
47

22525c17e   Dave Chinner   xfs: log item fla...
48
49
50
51
52
53
54
55
  /*
   * li_flags use the (set/test/clear)_bit atomic interfaces because updates can
   * race with each other and we don't want to have to use the AIL lock to
   * serialise all updates.
   */
  #define	XFS_LI_IN_AIL	0
  #define	XFS_LI_ABORTED	1
  #define	XFS_LI_FAILED	2
e6631f855   Dave Chinner   xfs: get rid of t...
56
  #define	XFS_LI_DIRTY	3	/* log item dirty in transaction */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
57

0b1b213fc   Christoph Hellwig   xfs: event tracin...
58
  #define XFS_LI_FLAGS \
22525c17e   Dave Chinner   xfs: log item fla...
59
60
  	{ (1 << XFS_LI_IN_AIL),		"IN_AIL" }, \
  	{ (1 << XFS_LI_ABORTED),	"ABORTED" }, \
e6631f855   Dave Chinner   xfs: get rid of t...
61
  	{ (1 << XFS_LI_FAILED),		"FAILED" }, \
901219bb2   Darrick J. Wong   xfs: remove XFS_L...
62
  	{ (1 << XFS_LI_DIRTY),		"DIRTY" }
0b1b213fc   Christoph Hellwig   xfs: event tracin...
63

272e42b21   Christoph Hellwig   xfs: constify xfs...
64
  struct xfs_item_ops {
9ce632a28   Christoph Hellwig   xfs: add a flag t...
65
  	unsigned flags;
efe2330fd   Christoph Hellwig   xfs: remove the x...
66
67
68
69
  	void (*iop_size)(struct xfs_log_item *, int *, int *);
  	void (*iop_format)(struct xfs_log_item *, struct xfs_log_vec *);
  	void (*iop_pin)(struct xfs_log_item *);
  	void (*iop_unpin)(struct xfs_log_item *, int remove);
43ff2122e   Christoph Hellwig   xfs: on-stack del...
70
  	uint (*iop_push)(struct xfs_log_item *, struct list_head *);
ddf92053e   Christoph Hellwig   xfs: split iop_un...
71
72
  	void (*iop_committing)(struct xfs_log_item *, xfs_lsn_t commit_lsn);
  	void (*iop_release)(struct xfs_log_item *);
efe2330fd   Christoph Hellwig   xfs: remove the x...
73
  	xfs_lsn_t (*iop_committed)(struct xfs_log_item *, xfs_lsn_t);
e6fff81e4   Darrick J. Wong   xfs: proper repla...
74
75
  	int (*iop_recover)(struct xfs_log_item *lip,
  			   struct list_head *capture_list);
154c733a3   Darrick J. Wong   xfs: refactor rel...
76
  	bool (*iop_match)(struct xfs_log_item *item, uint64_t id);
4e919af78   Darrick J. Wong   xfs: periodically...
77
78
  	struct xfs_log_item *(*iop_relog)(struct xfs_log_item *intent,
  			struct xfs_trans *tp);
272e42b21   Christoph Hellwig   xfs: constify xfs...
79
  };
847fff5ca   Barry Naujok   [XFS] Sync up ker...
80

d6b8fc6c7   Kaixu Xia   xfs: do the asser...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  /* Is this log item a deferred action intent? */
  static inline bool
  xlog_item_is_intent(struct xfs_log_item *lip)
  {
  	return lip->li_ops->iop_recover != NULL &&
  	       lip->li_ops->iop_match != NULL;
  }
  
  /* Is this a log intent-done item? */
  static inline bool
  xlog_item_is_intent_done(struct xfs_log_item *lip)
  {
  	return lip->li_ops->iop_unpin == NULL &&
  	       lip->li_ops->iop_push == NULL;
  }
9ce632a28   Christoph Hellwig   xfs: add a flag t...
96
97
98
99
100
  /*
   * Release the log item as soon as committed.  This is for items just logging
   * intents that never need to be written back in place.
   */
  #define XFS_ITEM_RELEASE_WHEN_COMMITTED	(1 << 0)
239880ef6   Dave Chinner   xfs: decouple log...
101
102
  void	xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,
  			  int type, const struct xfs_item_ops *ops);
847fff5ca   Barry Naujok   [XFS] Sync up ker...
103
  /*
904c17e68   Dave Chinner   xfs: finish remov...
104
   * Return values for the iop_push() routines.
847fff5ca   Barry Naujok   [XFS] Sync up ker...
105
   */
43ff2122e   Christoph Hellwig   xfs: on-stack del...
106
107
108
109
  #define XFS_ITEM_SUCCESS	0
  #define XFS_ITEM_PINNED		1
  #define XFS_ITEM_LOCKED		2
  #define XFS_ITEM_FLUSHING	3
847fff5ca   Barry Naujok   [XFS] Sync up ker...
110

e021a2e5f   Brian Foster   xfs: support embe...
111
  /*
9d9e62338   Brian Foster   xfs: fold dfops i...
112
   * Deferred operation item relogging limits.
e021a2e5f   Brian Foster   xfs: support embe...
113
114
115
   */
  #define XFS_DEFER_OPS_NR_INODES	2	/* join up to two inodes */
  #define XFS_DEFER_OPS_NR_BUFS	2	/* join up to two buffers */
239880ef6   Dave Chinner   xfs: decouple log...
116

847fff5ca   Barry Naujok   [XFS] Sync up ker...
117
  /*
847fff5ca   Barry Naujok   [XFS] Sync up ker...
118
119
120
121
   * This is the structure maintained for every active transaction.
   */
  typedef struct xfs_trans {
  	unsigned int		t_magic;	/* magic number */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
122
123
124
125
126
127
  	unsigned int		t_log_res;	/* amt of log space resvd */
  	unsigned int		t_log_count;	/* count for perm log res */
  	unsigned int		t_blk_res;	/* # of blocks resvd */
  	unsigned int		t_blk_res_used;	/* # of resvd blocks used */
  	unsigned int		t_rtx_res;	/* # of rt extents resvd */
  	unsigned int		t_rtx_res_used;	/* # of resvd rt extents used */
44fd29468   Brian Foster   xfs: pack holes i...
128
  	unsigned int		t_flags;	/* misc flags */
bba59c5e4   Brian Foster   xfs: add firstblo...
129
  	xfs_fsblock_t		t_firstblock;	/* first block allocated */
35a8a72f0   Christoph Hellwig   xfs: stop passing...
130
  	struct xlog_ticket	*t_ticket;	/* log mgr ticket */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
131
132
  	struct xfs_mount	*t_mountp;	/* ptr to fs mount struct */
  	struct xfs_dquot_acct   *t_dqinfo;	/* acctg info for dquots */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
133
134
135
136
137
138
  	int64_t			t_icount_delta;	/* superblock icount change */
  	int64_t			t_ifree_delta;	/* superblock ifree change */
  	int64_t			t_fdblocks_delta; /* superblock fdblocks chg */
  	int64_t			t_res_fdblocks_delta; /* on-disk only chg */
  	int64_t			t_frextents_delta;/* superblock freextents chg*/
  	int64_t			t_res_frextents_delta; /* on-disk only chg */
742ae1e35   Dave Chinner   xfs: introduce CO...
139
  #if defined(DEBUG) || defined(XFS_WARN)
847fff5ca   Barry Naujok   [XFS] Sync up ker...
140
141
142
143
144
145
146
147
148
149
150
151
  	int64_t			t_ag_freeblks_delta; /* debugging counter */
  	int64_t			t_ag_flist_delta; /* debugging counter */
  	int64_t			t_ag_btree_delta; /* debugging counter */
  #endif
  	int64_t			t_dblocks_delta;/* superblock dblocks change */
  	int64_t			t_agcount_delta;/* superblock agcount change */
  	int64_t			t_imaxpct_delta;/* superblock imaxpct change */
  	int64_t			t_rextsize_delta;/* superblock rextsize chg */
  	int64_t			t_rbmblocks_delta;/* superblock rbmblocks chg */
  	int64_t			t_rblocks_delta;/* superblock rblocks change */
  	int64_t			t_rextents_delta;/* superblocks rextents chg */
  	int64_t			t_rextslog_delta;/* superblocks rextslog chg */
e98c414f9   Christoph Hellwig   xfs: simplify log...
152
  	struct list_head	t_items;	/* log item descriptors */
ed3b4d6cd   Dave Chinner   xfs: Improve scal...
153
  	struct list_head	t_busy;		/* list of busy extents */
9d9e62338   Brian Foster   xfs: fold dfops i...
154
  	struct list_head	t_dfops;	/* deferred operations */
847fff5ca   Barry Naujok   [XFS] Sync up ker...
155
156
  	unsigned long		t_pflags;	/* saved process flags state */
  } xfs_trans_t;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
158
159
160
  /*
   * XFS transaction mechanism exported interfaces that are
   * actually macros.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
  #define	xfs_trans_set_sync(tp)		((tp)->t_flags |= XFS_TRANS_SYNC)
742ae1e35   Dave Chinner   xfs: introduce CO...
162
  #if defined(DEBUG) || defined(XFS_WARN)
20f4ebf2b   David Chinner   [XFS] Make growfs...
163
164
165
  #define	xfs_trans_agblocks_delta(tp, d)	((tp)->t_ag_freeblks_delta += (int64_t)d)
  #define	xfs_trans_agflist_delta(tp, d)	((tp)->t_ag_flist_delta += (int64_t)d)
  #define	xfs_trans_agbtree_delta(tp, d)	((tp)->t_ag_btree_delta += (int64_t)d)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
167
168
169
170
171
172
173
174
  #else
  #define	xfs_trans_agblocks_delta(tp, d)
  #define	xfs_trans_agflist_delta(tp, d)
  #define	xfs_trans_agbtree_delta(tp, d)
  #endif
  
  /*
   * XFS transaction mechanism exported interfaces.
   */
253f4911f   Christoph Hellwig   xfs: better xfs_t...
175
176
177
  int		xfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
  			uint blocks, uint rtextents, uint flags,
  			struct xfs_trans **tpp);
e89c04133   Darrick J. Wong   xfs: implement th...
178
179
  int		xfs_trans_alloc_empty(struct xfs_mount *mp,
  			struct xfs_trans **tpp);
20f4ebf2b   David Chinner   [XFS] Make growfs...
180
  void		xfs_trans_mod_sb(xfs_trans_t *, uint, int64_t);
de2a4f591   Dave Chinner   xfs: add disconti...
181

9676b54e6   Darrick J. Wong   xfs: make xfs_tra...
182
183
184
  int xfs_trans_get_buf_map(struct xfs_trans *tp, struct xfs_buftarg *target,
  		struct xfs_buf_map *map, int nmaps, xfs_buf_flags_t flags,
  		struct xfs_buf **bpp);
de2a4f591   Dave Chinner   xfs: add disconti...
185

ce92464c1   Darrick J. Wong   xfs: make xfs_tra...
186
  static inline int
de2a4f591   Dave Chinner   xfs: add disconti...
187
188
189
190
191
  xfs_trans_get_buf(
  	struct xfs_trans	*tp,
  	struct xfs_buftarg	*target,
  	xfs_daddr_t		blkno,
  	int			numblks,
ce92464c1   Darrick J. Wong   xfs: make xfs_tra...
192
193
  	uint			flags,
  	struct xfs_buf		**bpp)
de2a4f591   Dave Chinner   xfs: add disconti...
194
  {
c3f8fc73a   Dave Chinner   xfs: make buffer ...
195
  	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
ce92464c1   Darrick J. Wong   xfs: make xfs_tra...
196
  	return xfs_trans_get_buf_map(tp, target, &map, 1, flags, bpp);
de2a4f591   Dave Chinner   xfs: add disconti...
197
198
199
200
201
202
203
  }
  
  int		xfs_trans_read_buf_map(struct xfs_mount *mp,
  				       struct xfs_trans *tp,
  				       struct xfs_buftarg *target,
  				       struct xfs_buf_map *map, int nmaps,
  				       xfs_buf_flags_t flags,
c3f8fc73a   Dave Chinner   xfs: make buffer ...
204
  				       struct xfs_buf **bpp,
1813dd640   Dave Chinner   xfs: convert buff...
205
  				       const struct xfs_buf_ops *ops);
de2a4f591   Dave Chinner   xfs: add disconti...
206
207
208
209
210
211
212
213
214
  
  static inline int
  xfs_trans_read_buf(
  	struct xfs_mount	*mp,
  	struct xfs_trans	*tp,
  	struct xfs_buftarg	*target,
  	xfs_daddr_t		blkno,
  	int			numblks,
  	xfs_buf_flags_t		flags,
c3f8fc73a   Dave Chinner   xfs: make buffer ...
215
  	struct xfs_buf		**bpp,
1813dd640   Dave Chinner   xfs: convert buff...
216
  	const struct xfs_buf_ops *ops)
de2a4f591   Dave Chinner   xfs: add disconti...
217
  {
c3f8fc73a   Dave Chinner   xfs: make buffer ...
218
219
  	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
  	return xfs_trans_read_buf_map(mp, tp, target, &map, 1,
1813dd640   Dave Chinner   xfs: convert buff...
220
  				      flags, bpp, ops);
de2a4f591   Dave Chinner   xfs: add disconti...
221
  }
cead0b10f   Christoph Hellwig   xfs: simplify xfs...
222
  struct xfs_buf	*xfs_trans_getsb(struct xfs_trans *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
226
  
  void		xfs_trans_brelse(xfs_trans_t *, struct xfs_buf *);
  void		xfs_trans_bjoin(xfs_trans_t *, struct xfs_buf *);
  void		xfs_trans_bhold(xfs_trans_t *, struct xfs_buf *);
efa092f3d   Tim Shimmin   [XFS] Fixes a bug...
227
  void		xfs_trans_bhold_release(xfs_trans_t *, struct xfs_buf *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
229
  void		xfs_trans_binval(xfs_trans_t *, struct xfs_buf *);
  void		xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
  void		xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);
a5814bcee   Brian Foster   xfs: disallow mar...
231
  bool		xfs_trans_ordered_buf(xfs_trans_t *, struct xfs_buf *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
233
  void		xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
  void		xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
dcd79a142   Dave Chinner   xfs: don't use vf...
234
  void		xfs_trans_ichgtime(struct xfs_trans *, struct xfs_inode *, int);
ddc3415ab   Christoph Hellwig   xfs: simplify xfs...
235
  void		xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint);
9684010d3   Brian Foster   xfs: refactor buf...
236
237
238
  void		xfs_trans_log_buf(struct xfs_trans *, struct xfs_buf *, uint,
  				  uint);
  void		xfs_trans_dirty_buf(struct xfs_trans *, struct xfs_buf *);
38b6238eb   Darrick J. Wong   xfs: fix buffer s...
239
  bool		xfs_trans_buf_is_dirty(struct xfs_buf *bp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
  void		xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
9749fee83   Darrick J. Wong   xfs: enable the x...
241

70393313d   Christoph Hellwig   xfs: saner xfs_tr...
242
  int		xfs_trans_commit(struct xfs_trans *);
411350df1   Christoph Hellwig   xfs: refactor xfs...
243
244
  int		xfs_trans_roll(struct xfs_trans **);
  int		xfs_trans_roll_inode(struct xfs_trans **, struct xfs_inode *);
4906e2154   Christoph Hellwig   xfs: remove the f...
245
  void		xfs_trans_cancel(xfs_trans_t *);
249a8c112   David Chinner   [XFS] Move AIL pu...
246
247
  int		xfs_trans_ail_init(struct xfs_mount *);
  void		xfs_trans_ail_destroy(struct xfs_mount *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248

a4fbe6ab1   Dave Chinner   xfs: decouple ino...
249
250
251
252
  void		xfs_trans_buf_set_type(struct xfs_trans *, struct xfs_buf *,
  				       enum xfs_blft);
  void		xfs_trans_buf_copy_type(struct xfs_buf *dst_bp,
  					struct xfs_buf *src_bp);
a8272ce0c   David Chinner   [XFS] Fix up spar...
253
  extern kmem_zone_t	*xfs_trans_zone;
4e919af78   Darrick J. Wong   xfs: periodically...
254
255
256
257
258
259
260
  static inline struct xfs_log_item *
  xfs_trans_item_relog(
  	struct xfs_log_item	*lip,
  	struct xfs_trans	*tp)
  {
  	return lip->li_ops->iop_relog(lip, tp);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
  #endif	/* __XFS_TRANS_H__ */