aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2013-08-12 06:49:32 -0400
committerBen Myers <bpm@sgi.com>2013-08-12 17:36:16 -0400
commit7fd36c4418ee86712db6871ac95ab23743224bff (patch)
tree8f449f4eba8c31a16362e8640089489aa7579eff
parentd386b32b553ce145fb40f0d9360b6e5a79b5a80c (diff)
xfs: split out transaction reservation code
The transaction reservation size calculations is used by both kernel and userspace, but most of the transaction code in xfs_trans.c is kernel specific. Split all the transaction reservation code out into it's own files to make sharing with userspace simpler. This just leaves kernel-only definitions in xfs_trans.h, so it doesn't need to be shared with userspace anymore, either. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Mark Tinguely <tinguely@sgi.com> Signed-off-by: Ben Myers <bpm@sgi.com>
-rw-r--r--fs/xfs/Makefile3
-rw-r--r--fs/xfs/xfs_acl.c1
-rw-r--r--fs/xfs/xfs_buf.c1
-rw-r--r--fs/xfs/xfs_discard.c4
-rw-r--r--fs/xfs/xfs_mount.h42
-rw-r--r--fs/xfs/xfs_quotaops.c3
-rw-r--r--fs/xfs/xfs_trans.c654
-rw-r--r--fs/xfs/xfs_trans.h77
-rw-r--r--fs/xfs/xfs_trans_resv.c701
-rw-r--r--fs/xfs/xfs_trans_resv.h137
10 files changed, 851 insertions, 772 deletions
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 4a4508023a3c..dc72b6ba109c 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -47,6 +47,7 @@ xfs-y += xfs_aops.o \
47 xfs_mru_cache.o \ 47 xfs_mru_cache.o \
48 xfs_rename.o \ 48 xfs_rename.o \
49 xfs_super.o \ 49 xfs_super.o \
50 xfs_trans.o \
50 xfs_utils.o \ 51 xfs_utils.o \
51 xfs_vnodeops.o \ 52 xfs_vnodeops.o \
52 xfs_xattr.o \ 53 xfs_xattr.o \
@@ -76,7 +77,7 @@ xfs-y += xfs_alloc.o \
76 xfs_log_recover.o \ 77 xfs_log_recover.o \
77 xfs_mount.o \ 78 xfs_mount.o \
78 xfs_symlink.o \ 79 xfs_symlink.o \
79 xfs_trans.o 80 xfs_trans_resv.o
80 81
81# low-level transaction/log code 82# low-level transaction/log code
82xfs-y += xfs_log.o \ 83xfs-y += xfs_log.o \
diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
index 695606a3147d..150c670e15fa 100644
--- a/fs/xfs/xfs_acl.c
+++ b/fs/xfs/xfs_acl.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include "xfs.h" 18#include "xfs.h"
19#include "xfs_log_format.h" 19#include "xfs_log_format.h"
20#include "xfs_trans_resv.h"
20#include "xfs_acl.h" 21#include "xfs_acl.h"
21#include "xfs_attr.h" 22#include "xfs_attr.h"
22#include "xfs_bmap_btree.h" 23#include "xfs_bmap_btree.h"
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 1b2472a46e46..c8136d097c22 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -35,6 +35,7 @@
35#include <linux/freezer.h> 35#include <linux/freezer.h>
36 36
37#include "xfs_sb.h" 37#include "xfs_sb.h"
38#include "xfs_trans_resv.h"
38#include "xfs_log.h" 39#include "xfs_log.h"
39#include "xfs_ag.h" 40#include "xfs_ag.h"
40#include "xfs_mount.h" 41#include "xfs_mount.h"
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 65831f9babeb..45560ee1a4ba 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -17,12 +17,12 @@
17 */ 17 */
18#include "xfs.h" 18#include "xfs.h"
19#include "xfs_format.h" 19#include "xfs_format.h"
20#include "xfs_sb.h"
21#include "xfs_log.h" 20#include "xfs_log.h"
21#include "xfs_trans.h"
22#include "xfs_sb.h"
22#include "xfs_ag.h" 23#include "xfs_ag.h"
23#include "xfs_mount.h" 24#include "xfs_mount.h"
24#include "xfs_quota.h" 25#include "xfs_quota.h"
25#include "xfs_trans.h"
26#include "xfs_alloc_btree.h" 26#include "xfs_alloc_btree.h"
27#include "xfs_bmap_btree.h" 27#include "xfs_bmap_btree.h"
28#include "xfs_ialloc_btree.h" 28#include "xfs_ialloc_btree.h"
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 4e374d4a9189..27d0d5c72f4f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -18,45 +18,7 @@
18#ifndef __XFS_MOUNT_H__ 18#ifndef __XFS_MOUNT_H__
19#define __XFS_MOUNT_H__ 19#define __XFS_MOUNT_H__
20 20
21typedef struct xfs_trans_reservations { 21#ifdef __KERNEL__
22 uint tr_write; /* extent alloc trans */
23 uint tr_itruncate; /* truncate trans */
24 uint tr_rename; /* rename trans */
25 uint tr_link; /* link trans */
26 uint tr_remove; /* unlink trans */
27 uint tr_symlink; /* symlink trans */
28 uint tr_create; /* create trans */
29 uint tr_mkdir; /* mkdir trans */
30 uint tr_ifree; /* inode free trans */
31 uint tr_ichange; /* inode update trans */
32 uint tr_growdata; /* fs data section grow trans */
33 uint tr_swrite; /* sync write inode trans */
34 uint tr_addafork; /* cvt inode to attributed trans */
35 uint tr_writeid; /* write setuid/setgid file */
36 uint tr_attrinval; /* attr fork buffer invalidation */
37 uint tr_attrsetm; /* set/create an attribute at mount time */
38 uint tr_attrsetrt; /* set/create an attribute at runtime */
39 uint tr_attrrm; /* remove an attribute */
40 uint tr_clearagi; /* clear bad agi unlinked ino bucket */
41 uint tr_growrtalloc; /* grow realtime allocations */
42 uint tr_growrtzero; /* grow realtime zeroing */
43 uint tr_growrtfree; /* grow realtime freeing */
44 uint tr_qm_sbchange; /* change quota flags */
45 uint tr_qm_setqlim; /* adjust quota limits */
46 uint tr_qm_dqalloc; /* allocate quota on disk */
47 uint tr_qm_quotaoff; /* turn quota off */
48 uint tr_qm_equotaoff;/* end of turn quota off */
49 uint tr_sb; /* modify superblock */
50} xfs_trans_reservations_t;
51
52#ifndef __KERNEL__
53
54#define xfs_daddr_to_agno(mp,d) \
55 ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks))
56#define xfs_daddr_to_agbno(mp,d) \
57 ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks))
58
59#else /* __KERNEL__ */
60 22
61struct xlog; 23struct xlog;
62struct xfs_inode; 24struct xfs_inode;
@@ -174,7 +136,7 @@ typedef struct xfs_mount {
174 int m_ialloc_blks; /* blocks in inode allocation */ 136 int m_ialloc_blks; /* blocks in inode allocation */
175 int m_inoalign_mask;/* mask sb_inoalignmt if used */ 137 int m_inoalign_mask;/* mask sb_inoalignmt if used */
176 uint m_qflags; /* quota status flags */ 138 uint m_qflags; /* quota status flags */
177 xfs_trans_reservations_t m_reservations;/* precomputed res values */ 139 struct xfs_trans_resv m_reservations; /* precomputed res values */
178 __uint64_t m_maxicount; /* maximum inode count */ 140 __uint64_t m_maxicount; /* maximum inode count */
179 __uint64_t m_resblks; /* total reserved blocks */ 141 __uint64_t m_resblks; /* total reserved blocks */
180 __uint64_t m_resblks_avail;/* available reserved blocks */ 142 __uint64_t m_resblks_avail;/* available reserved blocks */
diff --git a/fs/xfs/xfs_quotaops.c b/fs/xfs/xfs_quotaops.c
index acf50712f4d7..446a2fc9825e 100644
--- a/fs/xfs/xfs_quotaops.c
+++ b/fs/xfs/xfs_quotaops.c
@@ -17,8 +17,9 @@
17 */ 17 */
18#include "xfs.h" 18#include "xfs.h"
19#include "xfs_format.h" 19#include "xfs_format.h"
20#include "xfs_sb.h" 20#include "xfs_trans_resv.h"
21#include "xfs_log.h" 21#include "xfs_log.h"
22#include "xfs_sb.h"
22#include "xfs_ag.h" 23#include "xfs_ag.h"
23#include "xfs_mount.h" 24#include "xfs_mount.h"
24#include "xfs_quota.h" 25#include "xfs_quota.h"
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 9b70df3cdcd7..cc824effd305 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -49,629 +49,6 @@ kmem_zone_t *xfs_trans_zone;
49kmem_zone_t *xfs_log_item_desc_zone; 49kmem_zone_t *xfs_log_item_desc_zone;
50 50
51/* 51/*
52 * A buffer has a format structure overhead in the log in addition
53 * to the data, so we need to take this into account when reserving
54 * space in a transaction for a buffer. Round the space required up
55 * to a multiple of 128 bytes so that we don't change the historical
56 * reservation that has been used for this overhead.
57 */
58STATIC uint
59xfs_buf_log_overhead(void)
60{
61 return round_up(sizeof(struct xlog_op_header) +
62 sizeof(struct xfs_buf_log_format), 128);
63}
64
65/*
66 * Calculate out transaction log reservation per item in bytes.
67 *
68 * The nbufs argument is used to indicate the number of items that
69 * will be changed in a transaction. size is used to tell how many
70 * bytes should be reserved per item.
71 */
72STATIC uint
73xfs_calc_buf_res(
74 uint nbufs,
75 uint size)
76{
77 return nbufs * (size + xfs_buf_log_overhead());
78}
79
80/*
81 * Various log reservation values.
82 *
83 * These are based on the size of the file system block because that is what
84 * most transactions manipulate. Each adds in an additional 128 bytes per
85 * item logged to try to account for the overhead of the transaction mechanism.
86 *
87 * Note: Most of the reservations underestimate the number of allocation
88 * groups into which they could free extents in the xfs_bmap_finish() call.
89 * This is because the number in the worst case is quite high and quite
90 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
91 * extents in only a single AG at a time. This will require changes to the
92 * EFI code as well, however, so that the EFI for the extents not freed is
93 * logged again in each transaction. See SGI PV #261917.
94 *
95 * Reservation functions here avoid a huge stack in xfs_trans_init due to
96 * register overflow from temporaries in the calculations.
97 */
98
99
100/*
101 * In a write transaction we can allocate a maximum of 2
102 * extents. This gives:
103 * the inode getting the new extents: inode size
104 * the inode's bmap btree: max depth * block size
105 * the agfs of the ags from which the extents are allocated: 2 * sector
106 * the superblock free block counter: sector size
107 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
108 * And the bmap_finish transaction can free bmap blocks in a join:
109 * the agfs of the ags containing the blocks: 2 * sector size
110 * the agfls of the ags containing the blocks: 2 * sector size
111 * the super block free block counter: sector size
112 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
113 */
114STATIC uint
115xfs_calc_write_reservation(
116 struct xfs_mount *mp)
117{
118 return XFS_DQUOT_LOGRES(mp) +
119 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
120 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
121 XFS_FSB_TO_B(mp, 1)) +
122 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
123 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
124 XFS_FSB_TO_B(mp, 1))),
125 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
126 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
127 XFS_FSB_TO_B(mp, 1))));
128}
129
130/*
131 * In truncating a file we free up to two extents at once. We can modify:
132 * the inode being truncated: inode size
133 * the inode's bmap btree: (max depth + 1) * block size
134 * And the bmap_finish transaction can free the blocks and bmap blocks:
135 * the agf for each of the ags: 4 * sector size
136 * the agfl for each of the ags: 4 * sector size
137 * the super block to reflect the freed blocks: sector size
138 * worst case split in allocation btrees per extent assuming 4 extents:
139 * 4 exts * 2 trees * (2 * max depth - 1) * block size
140 * the inode btree: max depth * blocksize
141 * the allocation btrees: 2 trees * (max depth - 1) * block size
142 */
143STATIC uint
144xfs_calc_itruncate_reservation(
145 struct xfs_mount *mp)
146{
147 return XFS_DQUOT_LOGRES(mp) +
148 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
149 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
150 XFS_FSB_TO_B(mp, 1))),
151 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
152 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
153 XFS_FSB_TO_B(mp, 1)) +
154 xfs_calc_buf_res(5, 0) +
155 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
156 XFS_FSB_TO_B(mp, 1)) +
157 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
158 mp->m_in_maxlevels, 0)));
159}
160
161/*
162 * In renaming a files we can modify:
163 * the four inodes involved: 4 * inode size
164 * the two directory btrees: 2 * (max depth + v2) * dir block size
165 * the two directory bmap btrees: 2 * max depth * block size
166 * And the bmap_finish transaction can free dir and bmap blocks (two sets
167 * of bmap blocks) giving:
168 * the agf for the ags in which the blocks live: 3 * sector size
169 * the agfl for the ags in which the blocks live: 3 * sector size
170 * the superblock for the free block count: sector size
171 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
172 */
173STATIC uint
174xfs_calc_rename_reservation(
175 struct xfs_mount *mp)
176{
177 return XFS_DQUOT_LOGRES(mp) +
178 MAX((xfs_calc_buf_res(4, mp->m_sb.sb_inodesize) +
179 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
180 XFS_FSB_TO_B(mp, 1))),
181 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
182 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
183 XFS_FSB_TO_B(mp, 1))));
184}
185
186/*
187 * For creating a link to an inode:
188 * the parent directory inode: inode size
189 * the linked inode: inode size
190 * the directory btree could split: (max depth + v2) * dir block size
191 * the directory bmap btree could join or split: (max depth + v2) * blocksize
192 * And the bmap_finish transaction can free some bmap blocks giving:
193 * the agf for the ag in which the blocks live: sector size
194 * the agfl for the ag in which the blocks live: sector size
195 * the superblock for the free block count: sector size
196 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
197 */
198STATIC uint
199xfs_calc_link_reservation(
200 struct xfs_mount *mp)
201{
202 return XFS_DQUOT_LOGRES(mp) +
203 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
204 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
205 XFS_FSB_TO_B(mp, 1))),
206 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
207 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
208 XFS_FSB_TO_B(mp, 1))));
209}
210
211/*
212 * For removing a directory entry we can modify:
213 * the parent directory inode: inode size
214 * the removed inode: inode size
215 * the directory btree could join: (max depth + v2) * dir block size
216 * the directory bmap btree could join or split: (max depth + v2) * blocksize
217 * And the bmap_finish transaction can free the dir and bmap blocks giving:
218 * the agf for the ag in which the blocks live: 2 * sector size
219 * the agfl for the ag in which the blocks live: 2 * sector size
220 * the superblock for the free block count: sector size
221 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
222 */
223STATIC uint
224xfs_calc_remove_reservation(
225 struct xfs_mount *mp)
226{
227 return XFS_DQUOT_LOGRES(mp) +
228 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
229 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
230 XFS_FSB_TO_B(mp, 1))),
231 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
232 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
233 XFS_FSB_TO_B(mp, 1))));
234}
235
236/*
237 * For create, break it in to the two cases that the transaction
238 * covers. We start with the modify case - allocation done by modification
239 * of the state of existing inodes - and the allocation case.
240 */
241
242/*
243 * For create we can modify:
244 * the parent directory inode: inode size
245 * the new inode: inode size
246 * the inode btree entry: block size
247 * the superblock for the nlink flag: sector size
248 * the directory btree: (max depth + v2) * dir block size
249 * the directory inode's bmap btree: (max depth + v2) * block size
250 */
251STATIC uint
252xfs_calc_create_resv_modify(
253 struct xfs_mount *mp)
254{
255 return xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
256 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
257 (uint)XFS_FSB_TO_B(mp, 1) +
258 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1));
259}
260
261/*
262 * For create we can allocate some inodes giving:
263 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
264 * the superblock for the nlink flag: sector size
265 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
266 * the inode btree: max depth * blocksize
267 * the allocation btrees: 2 trees * (max depth - 1) * block size
268 */
269STATIC uint
270xfs_calc_create_resv_alloc(
271 struct xfs_mount *mp)
272{
273 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
274 mp->m_sb.sb_sectsize +
275 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp), XFS_FSB_TO_B(mp, 1)) +
276 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
277 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
278 XFS_FSB_TO_B(mp, 1));
279}
280
281STATIC uint
282__xfs_calc_create_reservation(
283 struct xfs_mount *mp)
284{
285 return XFS_DQUOT_LOGRES(mp) +
286 MAX(xfs_calc_create_resv_alloc(mp),
287 xfs_calc_create_resv_modify(mp));
288}
289
290/*
291 * For icreate we can allocate some inodes giving:
292 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
293 * the superblock for the nlink flag: sector size
294 * the inode btree: max depth * blocksize
295 * the allocation btrees: 2 trees * (max depth - 1) * block size
296 */
297STATIC uint
298xfs_calc_icreate_resv_alloc(
299 struct xfs_mount *mp)
300{
301 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
302 mp->m_sb.sb_sectsize +
303 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
304 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
305 XFS_FSB_TO_B(mp, 1));
306}
307
308STATIC uint
309xfs_calc_icreate_reservation(xfs_mount_t *mp)
310{
311 return XFS_DQUOT_LOGRES(mp) +
312 MAX(xfs_calc_icreate_resv_alloc(mp),
313 xfs_calc_create_resv_modify(mp));
314}
315
316STATIC uint
317xfs_calc_create_reservation(
318 struct xfs_mount *mp)
319{
320 if (xfs_sb_version_hascrc(&mp->m_sb))
321 return xfs_calc_icreate_reservation(mp);
322 return __xfs_calc_create_reservation(mp);
323
324}
325
326/*
327 * Making a new directory is the same as creating a new file.
328 */
329STATIC uint
330xfs_calc_mkdir_reservation(
331 struct xfs_mount *mp)
332{
333 return xfs_calc_create_reservation(mp);
334}
335
336
337/*
338 * Making a new symplink is the same as creating a new file, but
339 * with the added blocks for remote symlink data which can be up to 1kB in
340 * length (MAXPATHLEN).
341 */
342STATIC uint
343xfs_calc_symlink_reservation(
344 struct xfs_mount *mp)
345{
346 return xfs_calc_create_reservation(mp) +
347 xfs_calc_buf_res(1, MAXPATHLEN);
348}
349
350/*
351 * In freeing an inode we can modify:
352 * the inode being freed: inode size
353 * the super block free inode counter: sector size
354 * the agi hash list and counters: sector size
355 * the inode btree entry: block size
356 * the on disk inode before ours in the agi hash list: inode cluster size
357 * the inode btree: max depth * blocksize
358 * the allocation btrees: 2 trees * (max depth - 1) * block size
359 */
360STATIC uint
361xfs_calc_ifree_reservation(
362 struct xfs_mount *mp)
363{
364 return XFS_DQUOT_LOGRES(mp) +
365 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
366 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
367 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
368 MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
369 XFS_INODE_CLUSTER_SIZE(mp)) +
370 xfs_calc_buf_res(1, 0) +
371 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
372 mp->m_in_maxlevels, 0) +
373 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
374 XFS_FSB_TO_B(mp, 1));
375}
376
377/*
378 * When only changing the inode we log the inode and possibly the superblock
379 * We also add a bit of slop for the transaction stuff.
380 */
381STATIC uint
382xfs_calc_ichange_reservation(
383 struct xfs_mount *mp)
384{
385 return XFS_DQUOT_LOGRES(mp) +
386 mp->m_sb.sb_inodesize +
387 mp->m_sb.sb_sectsize +
388 512;
389
390}
391
392/*
393 * Growing the data section of the filesystem.
394 * superblock
395 * agi and agf
396 * allocation btrees
397 */
398STATIC uint
399xfs_calc_growdata_reservation(
400 struct xfs_mount *mp)
401{
402 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
403 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
404 XFS_FSB_TO_B(mp, 1));
405}
406
407/*
408 * Growing the rt section of the filesystem.
409 * In the first set of transactions (ALLOC) we allocate space to the
410 * bitmap or summary files.
411 * superblock: sector size
412 * agf of the ag from which the extent is allocated: sector size
413 * bmap btree for bitmap/summary inode: max depth * blocksize
414 * bitmap/summary inode: inode size
415 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
416 */
417STATIC uint
418xfs_calc_growrtalloc_reservation(
419 struct xfs_mount *mp)
420{
421 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
422 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
423 XFS_FSB_TO_B(mp, 1)) +
424 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
425 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
426 XFS_FSB_TO_B(mp, 1));
427}
428
429/*
430 * Growing the rt section of the filesystem.
431 * In the second set of transactions (ZERO) we zero the new metadata blocks.
432 * one bitmap/summary block: blocksize
433 */
434STATIC uint
435xfs_calc_growrtzero_reservation(
436 struct xfs_mount *mp)
437{
438 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
439}
440
441/*
442 * Growing the rt section of the filesystem.
443 * In the third set of transactions (FREE) we update metadata without
444 * allocating any new blocks.
445 * superblock: sector size
446 * bitmap inode: inode size
447 * summary inode: inode size
448 * one bitmap block: blocksize
449 * summary blocks: new summary size
450 */
451STATIC uint
452xfs_calc_growrtfree_reservation(
453 struct xfs_mount *mp)
454{
455 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
456 xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
457 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
458 xfs_calc_buf_res(1, mp->m_rsumsize);
459}
460
461/*
462 * Logging the inode modification timestamp on a synchronous write.
463 * inode
464 */
465STATIC uint
466xfs_calc_swrite_reservation(
467 struct xfs_mount *mp)
468{
469 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
470}
471
472/*
473 * Logging the inode mode bits when writing a setuid/setgid file
474 * inode
475 */
476STATIC uint
477xfs_calc_writeid_reservation(xfs_mount_t *mp)
478{
479 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
480}
481
482/*
483 * Converting the inode from non-attributed to attributed.
484 * the inode being converted: inode size
485 * agf block and superblock (for block allocation)
486 * the new block (directory sized)
487 * bmap blocks for the new directory block
488 * allocation btrees
489 */
490STATIC uint
491xfs_calc_addafork_reservation(
492 struct xfs_mount *mp)
493{
494 return XFS_DQUOT_LOGRES(mp) +
495 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
496 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
497 xfs_calc_buf_res(1, mp->m_dirblksize) +
498 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
499 XFS_FSB_TO_B(mp, 1)) +
500 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
501 XFS_FSB_TO_B(mp, 1));
502}
503
504/*
505 * Removing the attribute fork of a file
506 * the inode being truncated: inode size
507 * the inode's bmap btree: max depth * block size
508 * And the bmap_finish transaction can free the blocks and bmap blocks:
509 * the agf for each of the ags: 4 * sector size
510 * the agfl for each of the ags: 4 * sector size
511 * the super block to reflect the freed blocks: sector size
512 * worst case split in allocation btrees per extent assuming 4 extents:
513 * 4 exts * 2 trees * (2 * max depth - 1) * block size
514 */
515STATIC uint
516xfs_calc_attrinval_reservation(
517 struct xfs_mount *mp)
518{
519 return MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
520 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
521 XFS_FSB_TO_B(mp, 1))),
522 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
523 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
524 XFS_FSB_TO_B(mp, 1))));
525}
526
527/*
528 * Setting an attribute at mount time.
529 * the inode getting the attribute
530 * the superblock for allocations
531 * the agfs extents are allocated from
532 * the attribute btree * max depth
533 * the inode allocation btree
534 * Since attribute transaction space is dependent on the size of the attribute,
535 * the calculation is done partially at mount time and partially at runtime(see
536 * below).
537 */
538STATIC uint
539xfs_calc_attrsetm_reservation(
540 struct xfs_mount *mp)
541{
542 return XFS_DQUOT_LOGRES(mp) +
543 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
544 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
545 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
546}
547
548/*
549 * Setting an attribute at runtime, transaction space unit per block.
550 * the superblock for allocations: sector size
551 * the inode bmap btree could join or split: max depth * block size
552 * Since the runtime attribute transaction space is dependent on the total
553 * blocks needed for the 1st bmap, here we calculate out the space unit for
554 * one block so that the caller could figure out the total space according
555 * to the attibute extent length in blocks by: ext * XFS_ATTRSETRT_LOG_RES(mp).
556 */
557STATIC uint
558xfs_calc_attrsetrt_reservation(
559 struct xfs_mount *mp)
560{
561 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
562 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
563 XFS_FSB_TO_B(mp, 1));
564}
565
566/*
567 * Removing an attribute.
568 * the inode: inode size
569 * the attribute btree could join: max depth * block size
570 * the inode bmap btree could join or split: max depth * block size
571 * And the bmap_finish transaction can free the attr blocks freed giving:
572 * the agf for the ag in which the blocks live: 2 * sector size
573 * the agfl for the ag in which the blocks live: 2 * sector size
574 * the superblock for the free block count: sector size
575 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
576 */
577STATIC uint
578xfs_calc_attrrm_reservation(
579 struct xfs_mount *mp)
580{
581 return XFS_DQUOT_LOGRES(mp) +
582 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
583 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
584 XFS_FSB_TO_B(mp, 1)) +
585 (uint)XFS_FSB_TO_B(mp,
586 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
587 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
588 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
589 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
590 XFS_FSB_TO_B(mp, 1))));
591}
592
593/*
594 * Clearing a bad agino number in an agi hash bucket.
595 */
596STATIC uint
597xfs_calc_clear_agi_bucket_reservation(
598 struct xfs_mount *mp)
599{
600 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
601}
602
603/*
604 * Clearing the quotaflags in the superblock.
605 * the super block for changing quota flags: sector size
606 */
607STATIC uint
608xfs_calc_qm_sbchange_reservation(
609 struct xfs_mount *mp)
610{
611 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
612}
613
614/*
615 * Adjusting quota limits.
616 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
617 */
618STATIC uint
619xfs_calc_qm_setqlim_reservation(
620 struct xfs_mount *mp)
621{
622 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
623}
624
625/*
626 * Allocating quota on disk if needed.
627 * the write transaction log space: XFS_WRITE_LOG_RES(mp)
628 * the unit of quota allocation: one system block size
629 */
630STATIC uint
631xfs_calc_qm_dqalloc_reservation(
632 struct xfs_mount *mp)
633{
634 return XFS_WRITE_LOG_RES(mp) +
635 xfs_calc_buf_res(1,
636 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
637}
638
639/*
640 * Turning off quotas.
641 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
642 * the superblock for the quota flags: sector size
643 */
644STATIC uint
645xfs_calc_qm_quotaoff_reservation(
646 struct xfs_mount *mp)
647{
648 return sizeof(struct xfs_qoff_logitem) * 2 +
649 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
650}
651
652/*
653 * End of turning off quotas.
654 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
655 */
656STATIC uint
657xfs_calc_qm_quotaoff_end_reservation(
658 struct xfs_mount *mp)
659{
660 return sizeof(struct xfs_qoff_logitem) * 2;
661}
662
663/*
664 * Syncing the incore super block changes to disk.
665 * the super block to reflect the changes: sector size
666 */
667STATIC uint
668xfs_calc_sb_reservation(
669 struct xfs_mount *mp)
670{
671 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
672}
673
674/*
675 * Initialize the precomputed transaction reservation values 52 * Initialize the precomputed transaction reservation values
676 * in the mount structure. 53 * in the mount structure.
677 */ 54 */
@@ -679,36 +56,7 @@ void
679xfs_trans_init( 56xfs_trans_init(
680 struct xfs_mount *mp) 57 struct xfs_mount *mp)
681{ 58{
682 struct xfs_trans_reservations *resp = &mp->m_reservations; 59 xfs_trans_resv_calc(mp, &mp->m_reservations);
683
684 resp->tr_write = xfs_calc_write_reservation(mp);
685 resp->tr_itruncate = xfs_calc_itruncate_reservation(mp);
686 resp->tr_rename = xfs_calc_rename_reservation(mp);
687 resp->tr_link = xfs_calc_link_reservation(mp);
688 resp->tr_remove = xfs_calc_remove_reservation(mp);
689 resp->tr_symlink = xfs_calc_symlink_reservation(mp);
690 resp->tr_create = xfs_calc_create_reservation(mp);
691 resp->tr_mkdir = xfs_calc_mkdir_reservation(mp);
692 resp->tr_ifree = xfs_calc_ifree_reservation(mp);
693 resp->tr_ichange = xfs_calc_ichange_reservation(mp);
694 resp->tr_growdata = xfs_calc_growdata_reservation(mp);
695 resp->tr_swrite = xfs_calc_swrite_reservation(mp);
696 resp->tr_writeid = xfs_calc_writeid_reservation(mp);
697 resp->tr_addafork = xfs_calc_addafork_reservation(mp);
698 resp->tr_attrinval = xfs_calc_attrinval_reservation(mp);
699 resp->tr_attrsetm = xfs_calc_attrsetm_reservation(mp);
700 resp->tr_attrsetrt = xfs_calc_attrsetrt_reservation(mp);
701 resp->tr_attrrm = xfs_calc_attrrm_reservation(mp);
702 resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp);
703 resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp);
704 resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp);
705 resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp);
706 resp->tr_qm_sbchange = xfs_calc_qm_sbchange_reservation(mp);
707 resp->tr_qm_setqlim = xfs_calc_qm_setqlim_reservation(mp);
708 resp->tr_qm_dqalloc = xfs_calc_qm_dqalloc_reservation(mp);
709 resp->tr_qm_quotaoff = xfs_calc_qm_quotaoff_reservation(mp);
710 resp->tr_qm_equotaoff = xfs_calc_qm_quotaoff_end_reservation(mp);
711 resp->tr_sb = xfs_calc_sb_reservation(mp);
712} 60}
713 61
714/* 62/*
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index 772d5aed90fa..b5dc61e3e56b 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -20,80 +20,9 @@
20 20
21struct xfs_log_item; 21struct xfs_log_item;
22 22
23/* 23#include "xfs_trans_resv.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)
27 */
28#define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
29 ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
30 24
31/* 25/* kernel only transaction subsystem defines */
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.
37 */
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
42
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)
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)
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)
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
96#ifdef __KERNEL__
97 26
98struct xfs_buf; 27struct xfs_buf;
99struct xfs_buftarg; 28struct xfs_buftarg;
@@ -323,6 +252,4 @@ void xfs_trans_ail_destroy(struct xfs_mount *);
323extern kmem_zone_t *xfs_trans_zone; 252extern kmem_zone_t *xfs_trans_zone;
324extern kmem_zone_t *xfs_log_item_desc_zone; 253extern kmem_zone_t *xfs_log_item_desc_zone;
325 254
326#endif /* __KERNEL__ */
327
328#endif /* __XFS_TRANS_H__ */ 255#endif /* __XFS_TRANS_H__ */
diff --git a/fs/xfs/xfs_trans_resv.c b/fs/xfs/xfs_trans_resv.c
new file mode 100644
index 000000000000..5a1537e2a180
--- /dev/null
+++ b/fs/xfs/xfs_trans_resv.c
@@ -0,0 +1,701 @@
1/*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * Copyright (C) 2010 Red Hat, Inc.
4 * All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#include "xfs.h"
20#include "xfs_fs.h"
21#include "xfs_format.h"
22#include "xfs_log.h"
23#include "xfs_trans_resv.h"
24#include "xfs_trans.h"
25#include "xfs_sb.h"
26#include "xfs_ag.h"
27#include "xfs_mount.h"
28#include "xfs_error.h"
29#include "xfs_da_btree.h"
30#include "xfs_bmap_btree.h"
31#include "xfs_alloc_btree.h"
32#include "xfs_ialloc_btree.h"
33#include "xfs_dinode.h"
34#include "xfs_inode.h"
35#include "xfs_btree.h"
36#include "xfs_ialloc.h"
37#include "xfs_alloc.h"
38#include "xfs_extent_busy.h"
39#include "xfs_bmap.h"
40#include "xfs_quota.h"
41#include "xfs_qm.h"
42#include "xfs_trans_space.h"
43#include "xfs_trace.h"
44
45/*
46 * A buffer has a format structure overhead in the log in addition
47 * to the data, so we need to take this into account when reserving
48 * space in a transaction for a buffer. Round the space required up
49 * to a multiple of 128 bytes so that we don't change the historical
50 * reservation that has been used for this overhead.
51 */
52STATIC uint
53xfs_buf_log_overhead(void)
54{
55 return round_up(sizeof(struct xlog_op_header) +
56 sizeof(struct xfs_buf_log_format), 128);
57}
58
59/*
60 * Calculate out transaction log reservation per item in bytes.
61 *
62 * The nbufs argument is used to indicate the number of items that
63 * will be changed in a transaction. size is used to tell how many
64 * bytes should be reserved per item.
65 */
66STATIC uint
67xfs_calc_buf_res(
68 uint nbufs,
69 uint size)
70{
71 return nbufs * (size + xfs_buf_log_overhead());
72}
73
74/*
75 * Various log reservation values.
76 *
77 * These are based on the size of the file system block because that is what
78 * most transactions manipulate. Each adds in an additional 128 bytes per
79 * item logged to try to account for the overhead of the transaction mechanism.
80 *
81 * Note: Most of the reservations underestimate the number of allocation
82 * groups into which they could free extents in the xfs_bmap_finish() call.
83 * This is because the number in the worst case is quite high and quite
84 * unusual. In order to fix this we need to change xfs_bmap_finish() to free
85 * extents in only a single AG at a time. This will require changes to the
86 * EFI code as well, however, so that the EFI for the extents not freed is
87 * logged again in each transaction. See SGI PV #261917.
88 *
89 * Reservation functions here avoid a huge stack in xfs_trans_init due to
90 * register overflow from temporaries in the calculations.
91 */
92
93
94/*
95 * In a write transaction we can allocate a maximum of 2
96 * extents. This gives:
97 * the inode getting the new extents: inode size
98 * the inode's bmap btree: max depth * block size
99 * the agfs of the ags from which the extents are allocated: 2 * sector
100 * the superblock free block counter: sector size
101 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
102 * And the bmap_finish transaction can free bmap blocks in a join:
103 * the agfs of the ags containing the blocks: 2 * sector size
104 * the agfls of the ags containing the blocks: 2 * sector size
105 * the super block free block counter: sector size
106 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
107 */
108STATIC uint
109xfs_calc_write_reservation(
110 struct xfs_mount *mp)
111{
112 return XFS_DQUOT_LOGRES(mp) +
113 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
114 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
115 XFS_FSB_TO_B(mp, 1)) +
116 xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
117 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
118 XFS_FSB_TO_B(mp, 1))),
119 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
120 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
121 XFS_FSB_TO_B(mp, 1))));
122}
123
124/*
125 * In truncating a file we free up to two extents at once. We can modify:
126 * the inode being truncated: inode size
127 * the inode's bmap btree: (max depth + 1) * block size
128 * And the bmap_finish transaction can free the blocks and bmap blocks:
129 * the agf for each of the ags: 4 * sector size
130 * the agfl for each of the ags: 4 * sector size
131 * the super block to reflect the freed blocks: sector size
132 * worst case split in allocation btrees per extent assuming 4 extents:
133 * 4 exts * 2 trees * (2 * max depth - 1) * block size
134 * the inode btree: max depth * blocksize
135 * the allocation btrees: 2 trees * (max depth - 1) * block size
136 */
137STATIC uint
138xfs_calc_itruncate_reservation(
139 struct xfs_mount *mp)
140{
141 return XFS_DQUOT_LOGRES(mp) +
142 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
143 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
144 XFS_FSB_TO_B(mp, 1))),
145 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
146 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
147 XFS_FSB_TO_B(mp, 1)) +
148 xfs_calc_buf_res(5, 0) +
149 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
150 XFS_FSB_TO_B(mp, 1)) +
151 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
152 mp->m_in_maxlevels, 0)));
153}
154
155/*
156 * In renaming a files we can modify:
157 * the four inodes involved: 4 * inode size
158 * the two directory btrees: 2 * (max depth + v2) * dir block size
159 * the two directory bmap btrees: 2 * max depth * block size
160 * And the bmap_finish transaction can free dir and bmap blocks (two sets
161 * of bmap blocks) giving:
162 * the agf for the ags in which the blocks live: 3 * sector size
163 * the agfl for the ags in which the blocks live: 3 * sector size
164 * the superblock for the free block count: sector size
165 * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
166 */
167STATIC uint
168xfs_calc_rename_reservation(
169 struct xfs_mount *mp)
170{
171 return XFS_DQUOT_LOGRES(mp) +
172 MAX((xfs_calc_buf_res(4, mp->m_sb.sb_inodesize) +
173 xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
174 XFS_FSB_TO_B(mp, 1))),
175 (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
176 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
177 XFS_FSB_TO_B(mp, 1))));
178}
179
180/*
181 * For creating a link to an inode:
182 * the parent directory inode: inode size
183 * the linked inode: inode size
184 * the directory btree could split: (max depth + v2) * dir block size
185 * the directory bmap btree could join or split: (max depth + v2) * blocksize
186 * And the bmap_finish transaction can free some bmap blocks giving:
187 * the agf for the ag in which the blocks live: sector size
188 * the agfl for the ag in which the blocks live: sector size
189 * the superblock for the free block count: sector size
190 * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
191 */
192STATIC uint
193xfs_calc_link_reservation(
194 struct xfs_mount *mp)
195{
196 return XFS_DQUOT_LOGRES(mp) +
197 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
198 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
199 XFS_FSB_TO_B(mp, 1))),
200 (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
201 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
202 XFS_FSB_TO_B(mp, 1))));
203}
204
205/*
206 * For removing a directory entry we can modify:
207 * the parent directory inode: inode size
208 * the removed inode: inode size
209 * the directory btree could join: (max depth + v2) * dir block size
210 * the directory bmap btree could join or split: (max depth + v2) * blocksize
211 * And the bmap_finish transaction can free the dir and bmap blocks giving:
212 * the agf for the ag in which the blocks live: 2 * sector size
213 * the agfl for the ag in which the blocks live: 2 * sector size
214 * the superblock for the free block count: sector size
215 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
216 */
217STATIC uint
218xfs_calc_remove_reservation(
219 struct xfs_mount *mp)
220{
221 return XFS_DQUOT_LOGRES(mp) +
222 MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
223 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
224 XFS_FSB_TO_B(mp, 1))),
225 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
226 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
227 XFS_FSB_TO_B(mp, 1))));
228}
229
230/*
231 * For create, break it in to the two cases that the transaction
232 * covers. We start with the modify case - allocation done by modification
233 * of the state of existing inodes - and the allocation case.
234 */
235
236/*
237 * For create we can modify:
238 * the parent directory inode: inode size
239 * the new inode: inode size
240 * the inode btree entry: block size
241 * the superblock for the nlink flag: sector size
242 * the directory btree: (max depth + v2) * dir block size
243 * the directory inode's bmap btree: (max depth + v2) * block size
244 */
245STATIC uint
246xfs_calc_create_resv_modify(
247 struct xfs_mount *mp)
248{
249 return xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
250 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
251 (uint)XFS_FSB_TO_B(mp, 1) +
252 xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1));
253}
254
255/*
256 * For create we can allocate some inodes giving:
257 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
258 * the superblock for the nlink flag: sector size
259 * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
260 * the inode btree: max depth * blocksize
261 * the allocation btrees: 2 trees * (max depth - 1) * block size
262 */
263STATIC uint
264xfs_calc_create_resv_alloc(
265 struct xfs_mount *mp)
266{
267 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
268 mp->m_sb.sb_sectsize +
269 xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp), XFS_FSB_TO_B(mp, 1)) +
270 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
271 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
272 XFS_FSB_TO_B(mp, 1));
273}
274
275STATIC uint
276__xfs_calc_create_reservation(
277 struct xfs_mount *mp)
278{
279 return XFS_DQUOT_LOGRES(mp) +
280 MAX(xfs_calc_create_resv_alloc(mp),
281 xfs_calc_create_resv_modify(mp));
282}
283
284/*
285 * For icreate we can allocate some inodes giving:
286 * the agi and agf of the ag getting the new inodes: 2 * sectorsize
287 * the superblock for the nlink flag: sector size
288 * the inode btree: max depth * blocksize
289 * the allocation btrees: 2 trees * (max depth - 1) * block size
290 */
291STATIC uint
292xfs_calc_icreate_resv_alloc(
293 struct xfs_mount *mp)
294{
295 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
296 mp->m_sb.sb_sectsize +
297 xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) +
298 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
299 XFS_FSB_TO_B(mp, 1));
300}
301
302STATIC uint
303xfs_calc_icreate_reservation(xfs_mount_t *mp)
304{
305 return XFS_DQUOT_LOGRES(mp) +
306 MAX(xfs_calc_icreate_resv_alloc(mp),
307 xfs_calc_create_resv_modify(mp));
308}
309
310STATIC uint
311xfs_calc_create_reservation(
312 struct xfs_mount *mp)
313{
314 if (xfs_sb_version_hascrc(&mp->m_sb))
315 return xfs_calc_icreate_reservation(mp);
316 return __xfs_calc_create_reservation(mp);
317
318}
319
320/*
321 * Making a new directory is the same as creating a new file.
322 */
323STATIC uint
324xfs_calc_mkdir_reservation(
325 struct xfs_mount *mp)
326{
327 return xfs_calc_create_reservation(mp);
328}
329
330
331/*
332 * Making a new symplink is the same as creating a new file, but
333 * with the added blocks for remote symlink data which can be up to 1kB in
334 * length (MAXPATHLEN).
335 */
336STATIC uint
337xfs_calc_symlink_reservation(
338 struct xfs_mount *mp)
339{
340 return xfs_calc_create_reservation(mp) +
341 xfs_calc_buf_res(1, MAXPATHLEN);
342}
343
344/*
345 * In freeing an inode we can modify:
346 * the inode being freed: inode size
347 * the super block free inode counter: sector size
348 * the agi hash list and counters: sector size
349 * the inode btree entry: block size
350 * the on disk inode before ours in the agi hash list: inode cluster size
351 * the inode btree: max depth * blocksize
352 * the allocation btrees: 2 trees * (max depth - 1) * block size
353 */
354STATIC uint
355xfs_calc_ifree_reservation(
356 struct xfs_mount *mp)
357{
358 return XFS_DQUOT_LOGRES(mp) +
359 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
360 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
361 xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
362 MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
363 XFS_INODE_CLUSTER_SIZE(mp)) +
364 xfs_calc_buf_res(1, 0) +
365 xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
366 mp->m_in_maxlevels, 0) +
367 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
368 XFS_FSB_TO_B(mp, 1));
369}
370
371/*
372 * When only changing the inode we log the inode and possibly the superblock
373 * We also add a bit of slop for the transaction stuff.
374 */
375STATIC uint
376xfs_calc_ichange_reservation(
377 struct xfs_mount *mp)
378{
379 return XFS_DQUOT_LOGRES(mp) +
380 mp->m_sb.sb_inodesize +
381 mp->m_sb.sb_sectsize +
382 512;
383
384}
385
386/*
387 * Growing the data section of the filesystem.
388 * superblock
389 * agi and agf
390 * allocation btrees
391 */
392STATIC uint
393xfs_calc_growdata_reservation(
394 struct xfs_mount *mp)
395{
396 return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
397 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
398 XFS_FSB_TO_B(mp, 1));
399}
400
401/*
402 * Growing the rt section of the filesystem.
403 * In the first set of transactions (ALLOC) we allocate space to the
404 * bitmap or summary files.
405 * superblock: sector size
406 * agf of the ag from which the extent is allocated: sector size
407 * bmap btree for bitmap/summary inode: max depth * blocksize
408 * bitmap/summary inode: inode size
409 * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
410 */
411STATIC uint
412xfs_calc_growrtalloc_reservation(
413 struct xfs_mount *mp)
414{
415 return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
416 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
417 XFS_FSB_TO_B(mp, 1)) +
418 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
419 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
420 XFS_FSB_TO_B(mp, 1));
421}
422
423/*
424 * Growing the rt section of the filesystem.
425 * In the second set of transactions (ZERO) we zero the new metadata blocks.
426 * one bitmap/summary block: blocksize
427 */
428STATIC uint
429xfs_calc_growrtzero_reservation(
430 struct xfs_mount *mp)
431{
432 return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
433}
434
435/*
436 * Growing the rt section of the filesystem.
437 * In the third set of transactions (FREE) we update metadata without
438 * allocating any new blocks.
439 * superblock: sector size
440 * bitmap inode: inode size
441 * summary inode: inode size
442 * one bitmap block: blocksize
443 * summary blocks: new summary size
444 */
445STATIC uint
446xfs_calc_growrtfree_reservation(
447 struct xfs_mount *mp)
448{
449 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
450 xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
451 xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
452 xfs_calc_buf_res(1, mp->m_rsumsize);
453}
454
455/*
456 * Logging the inode modification timestamp on a synchronous write.
457 * inode
458 */
459STATIC uint
460xfs_calc_swrite_reservation(
461 struct xfs_mount *mp)
462{
463 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
464}
465
466/*
467 * Logging the inode mode bits when writing a setuid/setgid file
468 * inode
469 */
470STATIC uint
471xfs_calc_writeid_reservation(xfs_mount_t *mp)
472{
473 return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
474}
475
476/*
477 * Converting the inode from non-attributed to attributed.
478 * the inode being converted: inode size
479 * agf block and superblock (for block allocation)
480 * the new block (directory sized)
481 * bmap blocks for the new directory block
482 * allocation btrees
483 */
484STATIC uint
485xfs_calc_addafork_reservation(
486 struct xfs_mount *mp)
487{
488 return XFS_DQUOT_LOGRES(mp) +
489 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
490 xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
491 xfs_calc_buf_res(1, mp->m_dirblksize) +
492 xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
493 XFS_FSB_TO_B(mp, 1)) +
494 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
495 XFS_FSB_TO_B(mp, 1));
496}
497
498/*
499 * Removing the attribute fork of a file
500 * the inode being truncated: inode size
501 * the inode's bmap btree: max depth * block size
502 * And the bmap_finish transaction can free the blocks and bmap blocks:
503 * the agf for each of the ags: 4 * sector size
504 * the agfl for each of the ags: 4 * sector size
505 * the super block to reflect the freed blocks: sector size
506 * worst case split in allocation btrees per extent assuming 4 extents:
507 * 4 exts * 2 trees * (2 * max depth - 1) * block size
508 */
509STATIC uint
510xfs_calc_attrinval_reservation(
511 struct xfs_mount *mp)
512{
513 return MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
514 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
515 XFS_FSB_TO_B(mp, 1))),
516 (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
517 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
518 XFS_FSB_TO_B(mp, 1))));
519}
520
521/*
522 * Setting an attribute at mount time.
523 * the inode getting the attribute
524 * the superblock for allocations
525 * the agfs extents are allocated from
526 * the attribute btree * max depth
527 * the inode allocation btree
528 * Since attribute transaction space is dependent on the size of the attribute,
529 * the calculation is done partially at mount time and partially at runtime(see
530 * below).
531 */
532STATIC uint
533xfs_calc_attrsetm_reservation(
534 struct xfs_mount *mp)
535{
536 return XFS_DQUOT_LOGRES(mp) +
537 xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
538 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
539 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
540}
541
542/*
543 * Setting an attribute at runtime, transaction space unit per block.
544 * the superblock for allocations: sector size
545 * the inode bmap btree could join or split: max depth * block size
546 * Since the runtime attribute transaction space is dependent on the total
547 * blocks needed for the 1st bmap, here we calculate out the space unit for
548 * one block so that the caller could figure out the total space according
549 * to the attibute extent length in blocks by: ext * XFS_ATTRSETRT_LOG_RES(mp).
550 */
551STATIC uint
552xfs_calc_attrsetrt_reservation(
553 struct xfs_mount *mp)
554{
555 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
556 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
557 XFS_FSB_TO_B(mp, 1));
558}
559
560/*
561 * Removing an attribute.
562 * the inode: inode size
563 * the attribute btree could join: max depth * block size
564 * the inode bmap btree could join or split: max depth * block size
565 * And the bmap_finish transaction can free the attr blocks freed giving:
566 * the agf for the ag in which the blocks live: 2 * sector size
567 * the agfl for the ag in which the blocks live: 2 * sector size
568 * the superblock for the free block count: sector size
569 * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
570 */
571STATIC uint
572xfs_calc_attrrm_reservation(
573 struct xfs_mount *mp)
574{
575 return XFS_DQUOT_LOGRES(mp) +
576 MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
577 xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
578 XFS_FSB_TO_B(mp, 1)) +
579 (uint)XFS_FSB_TO_B(mp,
580 XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
581 xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
582 (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
583 xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
584 XFS_FSB_TO_B(mp, 1))));
585}
586
587/*
588 * Clearing a bad agino number in an agi hash bucket.
589 */
590STATIC uint
591xfs_calc_clear_agi_bucket_reservation(
592 struct xfs_mount *mp)
593{
594 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
595}
596
597/*
598 * Clearing the quotaflags in the superblock.
599 * the super block for changing quota flags: sector size
600 */
601STATIC uint
602xfs_calc_qm_sbchange_reservation(
603 struct xfs_mount *mp)
604{
605 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
606}
607
608/*
609 * Adjusting quota limits.
610 * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
611 */
612STATIC uint
613xfs_calc_qm_setqlim_reservation(
614 struct xfs_mount *mp)
615{
616 return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
617}
618
619/*
620 * Allocating quota on disk if needed.
621 * the write transaction log space: XFS_WRITE_LOG_RES(mp)
622 * the unit of quota allocation: one system block size
623 */
624STATIC uint
625xfs_calc_qm_dqalloc_reservation(
626 struct xfs_mount *mp)
627{
628 return XFS_WRITE_LOG_RES(mp) +
629 xfs_calc_buf_res(1,
630 XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
631}
632
633/*
634 * Turning off quotas.
635 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
636 * the superblock for the quota flags: sector size
637 */
638STATIC uint
639xfs_calc_qm_quotaoff_reservation(
640 struct xfs_mount *mp)
641{
642 return sizeof(struct xfs_qoff_logitem) * 2 +
643 xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
644}
645
646/*
647 * End of turning off quotas.
648 * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
649 */
650STATIC uint
651xfs_calc_qm_quotaoff_end_reservation(
652 struct xfs_mount *mp)
653{
654 return sizeof(struct xfs_qoff_logitem) * 2;
655}
656
657/*
658 * Syncing the incore super block changes to disk.
659 * the super block to reflect the changes: sector size
660 */
661STATIC uint
662xfs_calc_sb_reservation(
663 struct xfs_mount *mp)
664{
665 return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
666}
667
668void
669xfs_trans_resv_calc(
670 struct xfs_mount *mp,
671 struct xfs_trans_resv *resp)
672{
673 resp->tr_write = xfs_calc_write_reservation(mp);
674 resp->tr_itruncate = xfs_calc_itruncate_reservation(mp);
675 resp->tr_rename = xfs_calc_rename_reservation(mp);
676 resp->tr_link = xfs_calc_link_reservation(mp);
677 resp->tr_remove = xfs_calc_remove_reservation(mp);
678 resp->tr_symlink = xfs_calc_symlink_reservation(mp);
679 resp->tr_create = xfs_calc_create_reservation(mp);
680 resp->tr_mkdir = xfs_calc_mkdir_reservation(mp);
681 resp->tr_ifree = xfs_calc_ifree_reservation(mp);
682 resp->tr_ichange = xfs_calc_ichange_reservation(mp);
683 resp->tr_growdata = xfs_calc_growdata_reservation(mp);
684 resp->tr_swrite = xfs_calc_swrite_reservation(mp);
685 resp->tr_writeid = xfs_calc_writeid_reservation(mp);
686 resp->tr_addafork = xfs_calc_addafork_reservation(mp);
687 resp->tr_attrinval = xfs_calc_attrinval_reservation(mp);
688 resp->tr_attrsetm = xfs_calc_attrsetm_reservation(mp);
689 resp->tr_attrsetrt = xfs_calc_attrsetrt_reservation(mp);
690 resp->tr_attrrm = xfs_calc_attrrm_reservation(mp);
691 resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp);
692 resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp);
693 resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp);
694 resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp);
695 resp->tr_qm_sbchange = xfs_calc_qm_sbchange_reservation(mp);
696 resp->tr_qm_setqlim = xfs_calc_qm_setqlim_reservation(mp);
697 resp->tr_qm_dqalloc = xfs_calc_qm_dqalloc_reservation(mp);
698 resp->tr_qm_quotaoff = xfs_calc_qm_quotaoff_reservation(mp);
699 resp->tr_qm_equotaoff = xfs_calc_qm_quotaoff_end_reservation(mp);
700 resp->tr_sb = xfs_calc_sb_reservation(mp);
701}
diff --git a/fs/xfs/xfs_trans_resv.h b/fs/xfs/xfs_trans_resv.h
new file mode 100644
index 000000000000..cc8260e6acb2
--- /dev/null
+++ b/fs/xfs/xfs_trans_resv.h
@@ -0,0 +1,137 @@
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_RESV_H__
19#define __XFS_TRANS_RESV_H__
20
21struct xfs_mount;
22
23/*
24 * structure for maintaining pre-calculated transaction reservations.
25 */
26struct xfs_trans_resv {
27 uint tr_write; /* extent alloc trans */
28 uint tr_itruncate; /* truncate trans */
29 uint tr_rename; /* rename trans */
30 uint tr_link; /* link trans */
31 uint tr_remove; /* unlink trans */
32 uint tr_symlink; /* symlink trans */
33 uint tr_create; /* create trans */
34 uint tr_mkdir; /* mkdir trans */
35 uint tr_ifree; /* inode free trans */
36 uint tr_ichange; /* inode update trans */
37 uint tr_growdata; /* fs data section grow trans */
38 uint tr_swrite; /* sync write inode trans */
39 uint tr_addafork; /* cvt inode to attributed trans */
40 uint tr_writeid; /* write setuid/setgid file */
41 uint tr_attrinval; /* attr fork buffer invalidation */
42 uint tr_attrsetm; /* set/create an attribute at mount time */
43 uint tr_attrsetrt; /* set/create an attribute at runtime */
44 uint tr_attrrm; /* remove an attribute */
45 uint tr_clearagi; /* clear bad agi unlinked ino bucket */
46 uint tr_growrtalloc; /* grow realtime allocations */
47 uint tr_growrtzero; /* grow realtime zeroing */
48 uint tr_growrtfree; /* grow realtime freeing */
49 uint tr_qm_sbchange; /* change quota flags */
50 uint tr_qm_setqlim; /* adjust quota limits */
51 uint tr_qm_dqalloc; /* allocate quota on disk */
52 uint tr_qm_quotaoff; /* turn quota off */
53 uint tr_qm_equotaoff;/* end of turn quota off */
54 uint tr_sb; /* modify superblock */
55};
56
57/*
58 * Per-extent log reservation for the allocation btree changes
59 * involved in freeing or allocating an extent.
60 * 2 trees * (2 blocks/level * max depth - 1) * block size
61 */
62#define XFS_ALLOCFREE_LOG_RES(mp,nx) \
63 ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * XFS_AG_MAXLEVELS(mp) - 1)))
64#define XFS_ALLOCFREE_LOG_COUNT(mp,nx) \
65 ((nx) * (2 * (2 * XFS_AG_MAXLEVELS(mp) - 1)))
66
67/*
68 * Per-directory log reservation for any directory change.
69 * dir blocks: (1 btree block per level + data block + free block) * dblock size
70 * bmap btree: (levels + 2) * max depth * block size
71 * v2 directory blocks can be fragmented below the dirblksize down to the fsb
72 * size, so account for that in the DAENTER macros.
73 */
74#define XFS_DIROP_LOG_RES(mp) \
75 (XFS_FSB_TO_B(mp, XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK)) + \
76 (XFS_FSB_TO_B(mp, XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)))
77#define XFS_DIROP_LOG_COUNT(mp) \
78 (XFS_DAENTER_BLOCKS(mp, XFS_DATA_FORK) + \
79 XFS_DAENTER_BMAPS(mp, XFS_DATA_FORK) + 1)
80
81
82#define XFS_WRITE_LOG_RES(mp) ((mp)->m_reservations.tr_write)
83#define XFS_ITRUNCATE_LOG_RES(mp) ((mp)->m_reservations.tr_itruncate)
84#define XFS_RENAME_LOG_RES(mp) ((mp)->m_reservations.tr_rename)
85#define XFS_LINK_LOG_RES(mp) ((mp)->m_reservations.tr_link)
86#define XFS_REMOVE_LOG_RES(mp) ((mp)->m_reservations.tr_remove)
87#define XFS_SYMLINK_LOG_RES(mp) ((mp)->m_reservations.tr_symlink)
88#define XFS_CREATE_LOG_RES(mp) ((mp)->m_reservations.tr_create)
89#define XFS_MKDIR_LOG_RES(mp) ((mp)->m_reservations.tr_mkdir)
90#define XFS_IFREE_LOG_RES(mp) ((mp)->m_reservations.tr_ifree)
91#define XFS_ICHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_ichange)
92#define XFS_GROWDATA_LOG_RES(mp) ((mp)->m_reservations.tr_growdata)
93#define XFS_GROWRTALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_growrtalloc)
94#define XFS_GROWRTZERO_LOG_RES(mp) ((mp)->m_reservations.tr_growrtzero)
95#define XFS_GROWRTFREE_LOG_RES(mp) ((mp)->m_reservations.tr_growrtfree)
96#define XFS_SWRITE_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
97/*
98 * Logging the inode timestamps on an fsync -- same as SWRITE
99 * as long as SWRITE logs the entire inode core
100 */
101#define XFS_FSYNC_TS_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
102#define XFS_WRITEID_LOG_RES(mp) ((mp)->m_reservations.tr_swrite)
103#define XFS_ADDAFORK_LOG_RES(mp) ((mp)->m_reservations.tr_addafork)
104#define XFS_ATTRINVAL_LOG_RES(mp) ((mp)->m_reservations.tr_attrinval)
105#define XFS_ATTRSETM_LOG_RES(mp) ((mp)->m_reservations.tr_attrsetm)
106#define XFS_ATTRSETRT_LOG_RES(mp) ((mp)->m_reservations.tr_attrsetrt)
107#define XFS_ATTRRM_LOG_RES(mp) ((mp)->m_reservations.tr_attrrm)
108#define XFS_CLEAR_AGI_BUCKET_LOG_RES(mp) ((mp)->m_reservations.tr_clearagi)
109#define XFS_QM_SBCHANGE_LOG_RES(mp) ((mp)->m_reservations.tr_qm_sbchange)
110#define XFS_QM_SETQLIM_LOG_RES(mp) ((mp)->m_reservations.tr_qm_setqlim)
111#define XFS_QM_DQALLOC_LOG_RES(mp) ((mp)->m_reservations.tr_qm_dqalloc)
112#define XFS_QM_QUOTAOFF_LOG_RES(mp) ((mp)->m_reservations.tr_qm_quotaoff)
113#define XFS_QM_QUOTAOFF_END_LOG_RES(mp) ((mp)->m_reservations.tr_qm_equotaoff)
114#define XFS_SB_LOG_RES(mp) ((mp)->m_reservations.tr_sb)
115
116/*
117 * Various log count values.
118 */
119#define XFS_DEFAULT_LOG_COUNT 1
120#define XFS_DEFAULT_PERM_LOG_COUNT 2
121#define XFS_ITRUNCATE_LOG_COUNT 2
122#define XFS_INACTIVE_LOG_COUNT 2
123#define XFS_CREATE_LOG_COUNT 2
124#define XFS_MKDIR_LOG_COUNT 3
125#define XFS_SYMLINK_LOG_COUNT 3
126#define XFS_REMOVE_LOG_COUNT 2
127#define XFS_LINK_LOG_COUNT 2
128#define XFS_RENAME_LOG_COUNT 2
129#define XFS_WRITE_LOG_COUNT 2
130#define XFS_ADDAFORK_LOG_COUNT 2
131#define XFS_ATTRINVAL_LOG_COUNT 1
132#define XFS_ATTRSET_LOG_COUNT 3
133#define XFS_ATTRRM_LOG_COUNT 3
134
135void xfs_trans_resv_calc(struct xfs_mount *mp, struct xfs_trans_resv *resp);
136
137#endif /* __XFS_TRANS_RESV_H__ */