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