2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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.
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.
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
18 #ifndef __XFS_TRANS_H__
19 #define __XFS_TRANS_H__
24 * Per-extent log reservation for the allocation btree changes
25 * involved in freeing or allocating an extent.
26 * 2 trees * (2 blocks/level * max depth - 1)
28 #define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
29 ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
32 * Per-directory log reservation for any directory change.
33 * dir blocks: (1 btree block per level + data block + free block)
34 * bmap btree: (levels + 2) * max depth
35 * v2 directory blocks can be fragmented below the dirblksize down to the fsb
36 * size, so account for that in the DAENTER macros.
38 #define XFS_DIROP_LOG_COUNT(mp) \
39 (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \
40 XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)
43 #define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write)
44 #define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate)
45 #define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename)
46 #define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link)
47 #define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove)
48 #define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink)
49 #define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create)
50 #define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir)
51 #define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree)
52 #define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange)
53 #define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata)
54 #define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc)
55 #define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero)
56 #define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree)
57 #define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
59 * Logging the inode timestamps on an fsync -- same as SWRITE
60 * as long as SWRITE logs the entire inode core
62 #define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
63 #define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
64 #define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork)
65 #define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval)
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)
69 #define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi)
70 #define XFS_QM_SBCHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_qm_sbchange)
71 #define XFS_QM_SETQLIM_LOG_RES(mp) ((mp)->m_reservations.tr_qm_setqlim)
72 #define XFS_QM_DQALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_qm_dqalloc)
73 #define XFS_QM_QUOTAOFF_LOG_RES(mp) ((mp)->m_reservations.tr_qm_quotaoff)
74 #define XFS_QM_QUOTAOFF_END_LOG_RES(mp) ((mp)->m_reservations.tr_qm_equotaoff)
75 #define XFS_SB_LOG_RES(mp) ((mp)->m_reservations.tr_sb)
78 * Various log count values.
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
100 struct xfs_efd_log_item
;
101 struct xfs_efi_log_item
;
104 struct xfs_log_iovec
;
105 struct xfs_log_item_desc
;
108 struct xfs_dquot_acct
;
109 struct xfs_busy_extent
;
111 typedef 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 */
116 struct xfs_ail
*li_ailp
; /* ptr to AIL */
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 */
124 const struct xfs_item_ops
*li_ops
; /* function list */
126 /* delayed logging */
127 struct list_head li_cil
; /* CIL pointers */
128 struct xfs_log_vec
*li_lv
; /* active log vector */
129 xfs_lsn_t li_seq
; /* CIL commit seq */
132 #define XFS_LI_IN_AIL 0x1
133 #define XFS_LI_ABORTED 0x2
135 #define XFS_LI_FLAGS \
136 { XFS_LI_IN_AIL, "IN_AIL" }, \
137 { XFS_LI_ABORTED, "ABORTED" }
139 struct xfs_item_ops
{
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
*);
143 void (*iop_unpin
)(xfs_log_item_t
*, int remove
);
144 uint (*iop_push
)(struct xfs_log_item
*, struct list_head
*);
145 void (*iop_unlock
)(xfs_log_item_t
*);
146 xfs_lsn_t (*iop_committed
)(xfs_log_item_t
*, xfs_lsn_t
);
147 void (*iop_committing
)(xfs_log_item_t
*, xfs_lsn_t
);
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)
153 #define IOP_UNPIN(ip, remove) (*(ip)->li_ops->iop_unpin)(ip, remove)
154 #define IOP_PUSH(ip, list) (*(ip)->li_ops->iop_push)(ip, list)
155 #define IOP_UNLOCK(ip) (*(ip)->li_ops->iop_unlock)(ip)
156 #define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn)
157 #define IOP_COMMITTING(ip, lsn) (*(ip)->li_ops->iop_committing)(ip, lsn)
160 * Return values for the IOP_PUSH() routines.
162 #define XFS_ITEM_SUCCESS 0
163 #define XFS_ITEM_PINNED 1
164 #define XFS_ITEM_LOCKED 2
165 #define XFS_ITEM_FLUSHING 3
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.
171 typedef void (*xfs_trans_callback_t
)(struct xfs_trans
*, void *);
174 * This is the structure maintained for every active transaction.
176 typedef 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 */
186 struct xlog_ticket
*t_ticket
; /* log mgr ticket */
187 xfs_lsn_t t_lsn
; /* log seq num of start of
189 xfs_lsn_t t_commit_lsn
; /* log seq num of end of
191 struct xfs_mount
*t_mountp
; /* ptr to fs mount struct */
192 struct xfs_dquot_acct
*t_dqinfo
; /* acctg info for dquots */
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 */
200 #if defined(DEBUG) || defined(XFS_WARN)
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 */
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 */
213 struct list_head t_items
; /* log item descriptors */
214 xfs_trans_header_t t_header
; /* header for in-log trans */
215 struct list_head t_busy
; /* list of busy extents */
216 unsigned long t_pflags
; /* saved process flags state */
220 * XFS transaction mechanism exported interfaces that are
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)
228 #if defined(DEBUG) || defined(XFS_WARN)
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)
233 #define xfs_trans_agblocks_delta(tp, d)
234 #define xfs_trans_agflist_delta(tp, d)
235 #define xfs_trans_agbtree_delta(tp, d)
239 * XFS transaction mechanism exported interfaces.
241 xfs_trans_t
*xfs_trans_alloc(struct xfs_mount
*, uint
);
242 xfs_trans_t
*_xfs_trans_alloc(struct xfs_mount
*, uint
, xfs_km_flags_t
);
243 xfs_trans_t
*xfs_trans_dup(xfs_trans_t
*);
244 int xfs_trans_reserve(xfs_trans_t
*, uint
, uint
, uint
,
246 void xfs_trans_mod_sb(xfs_trans_t
*, uint
, int64_t);
248 struct xfs_buf
*xfs_trans_get_buf_map(struct xfs_trans
*tp
,
249 struct xfs_buftarg
*target
,
250 struct xfs_buf_map
*map
, int nmaps
,
253 static inline struct xfs_buf
*
255 struct xfs_trans
*tp
,
256 struct xfs_buftarg
*target
,
261 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
262 return xfs_trans_get_buf_map(tp
, target
, &map
, 1, flags
);
265 int 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
,
270 struct xfs_buf
**bpp
,
271 const struct xfs_buf_ops
*ops
);
275 struct xfs_mount
*mp
,
276 struct xfs_trans
*tp
,
277 struct xfs_buftarg
*target
,
280 xfs_buf_flags_t flags
,
281 struct xfs_buf
**bpp
,
282 const struct xfs_buf_ops
*ops
)
284 DEFINE_SINGLE_BUF_MAP(map
, blkno
, numblks
);
285 return xfs_trans_read_buf_map(mp
, tp
, target
, &map
, 1,
289 struct xfs_buf
*xfs_trans_getsb(xfs_trans_t
*, struct xfs_mount
*, int);
291 void xfs_trans_brelse(xfs_trans_t
*, struct xfs_buf
*);
292 void xfs_trans_bjoin(xfs_trans_t
*, struct xfs_buf
*);
293 void xfs_trans_bhold(xfs_trans_t
*, struct xfs_buf
*);
294 void xfs_trans_bhold_release(xfs_trans_t
*, struct xfs_buf
*);
295 void xfs_trans_binval(xfs_trans_t
*, struct xfs_buf
*);
296 void xfs_trans_inode_buf(xfs_trans_t
*, struct xfs_buf
*);
297 void xfs_trans_stale_inode_buf(xfs_trans_t
*, struct xfs_buf
*);
298 void xfs_trans_ordered_buf(xfs_trans_t
*, struct xfs_buf
*);
299 void xfs_trans_dquot_buf(xfs_trans_t
*, struct xfs_buf
*, uint
);
300 void xfs_trans_inode_alloc_buf(xfs_trans_t
*, struct xfs_buf
*);
301 void xfs_trans_ichgtime(struct xfs_trans
*, struct xfs_inode
*, int);
302 void xfs_trans_ijoin(struct xfs_trans
*, struct xfs_inode
*, uint
);
303 void xfs_trans_log_buf(xfs_trans_t
*, struct xfs_buf
*, uint
, uint
);
304 void xfs_trans_log_inode(xfs_trans_t
*, struct xfs_inode
*, uint
);
305 struct xfs_efi_log_item
*xfs_trans_get_efi(xfs_trans_t
*, uint
);
306 void xfs_efi_release(struct xfs_efi_log_item
*, uint
);
307 void xfs_trans_log_efi_extent(xfs_trans_t
*,
308 struct xfs_efi_log_item
*,
311 struct xfs_efd_log_item
*xfs_trans_get_efd(xfs_trans_t
*,
312 struct xfs_efi_log_item
*,
314 void xfs_trans_log_efd_extent(xfs_trans_t
*,
315 struct xfs_efd_log_item
*,
318 int xfs_trans_commit(xfs_trans_t
*, uint flags
);
319 void xfs_trans_cancel(xfs_trans_t
*, int);
320 int xfs_trans_ail_init(struct xfs_mount
*);
321 void xfs_trans_ail_destroy(struct xfs_mount
*);
323 extern kmem_zone_t
*xfs_trans_zone
;
324 extern kmem_zone_t
*xfs_log_item_desc_zone
;
326 #endif /* __KERNEL__ */
328 void xfs_trans_init(struct xfs_mount
*);
329 int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
331 #endif /* __XFS_TRANS_H__ */