Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
| 4 | * Copyright (C) 2010 Red Hat, Inc. |
| 5 | * All Rights Reserved. |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 6 | */ |
| 7 | #include "xfs.h" |
| 8 | #include "xfs_fs.h" |
Dave Chinner | 70a9883 | 2013-10-23 10:36:05 +1100 | [diff] [blame] | 9 | #include "xfs_shared.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_format.h" |
| 11 | #include "xfs_log_format.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 12 | #include "xfs_trans_resv.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 13 | #include "xfs_mount.h" |
Dave Chinner | 5706278 | 2013-10-15 09:17:51 +1100 | [diff] [blame] | 14 | #include "xfs_da_format.h" |
Dave Chinner | d6cf130 | 2014-06-06 15:14:11 +1000 | [diff] [blame] | 15 | #include "xfs_da_btree.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 16 | #include "xfs_inode.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 17 | #include "xfs_bmap_btree.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 18 | #include "xfs_ialloc.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 19 | #include "xfs_quota.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 20 | #include "xfs_trans.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 21 | #include "xfs_qm.h" |
| 22 | #include "xfs_trans_space.h" |
| 23 | #include "xfs_trace.h" |
| 24 | |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 25 | #define _ALLOC true |
| 26 | #define _FREE false |
| 27 | |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 28 | /* |
| 29 | * A buffer has a format structure overhead in the log in addition |
| 30 | * to the data, so we need to take this into account when reserving |
| 31 | * space in a transaction for a buffer. Round the space required up |
| 32 | * to a multiple of 128 bytes so that we don't change the historical |
| 33 | * reservation that has been used for this overhead. |
| 34 | */ |
| 35 | STATIC uint |
| 36 | xfs_buf_log_overhead(void) |
| 37 | { |
| 38 | return round_up(sizeof(struct xlog_op_header) + |
| 39 | sizeof(struct xfs_buf_log_format), 128); |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * Calculate out transaction log reservation per item in bytes. |
| 44 | * |
| 45 | * The nbufs argument is used to indicate the number of items that |
| 46 | * will be changed in a transaction. size is used to tell how many |
| 47 | * bytes should be reserved per item. |
| 48 | */ |
| 49 | STATIC uint |
| 50 | xfs_calc_buf_res( |
| 51 | uint nbufs, |
| 52 | uint size) |
| 53 | { |
| 54 | return nbufs * (size + xfs_buf_log_overhead()); |
| 55 | } |
| 56 | |
| 57 | /* |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 58 | * Per-extent log reservation for the btree changes involved in freeing or |
| 59 | * allocating an extent. In classic XFS there were two trees that will be |
| 60 | * modified (bnobt + cntbt). With rmap enabled, there are three trees |
Darrick J. Wong | f310bd2 | 2016-10-03 09:11:19 -0700 | [diff] [blame] | 61 | * (rmapbt). With reflink, there are four trees (refcountbt). The number of |
| 62 | * blocks reserved is based on the formula: |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 63 | * |
| 64 | * num trees * ((2 blocks/level * max depth) - 1) |
| 65 | * |
| 66 | * Keep in mind that max depth is calculated separately for each type of tree. |
| 67 | */ |
Darrick J. Wong | 1946b91 | 2016-10-03 09:11:18 -0700 | [diff] [blame] | 68 | uint |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 69 | xfs_allocfree_log_count( |
| 70 | struct xfs_mount *mp, |
| 71 | uint num_ops) |
| 72 | { |
| 73 | uint blocks; |
| 74 | |
| 75 | blocks = num_ops * 2 * (2 * mp->m_ag_maxlevels - 1); |
| 76 | if (xfs_sb_version_hasrmapbt(&mp->m_sb)) |
| 77 | blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1); |
Darrick J. Wong | f310bd2 | 2016-10-03 09:11:19 -0700 | [diff] [blame] | 78 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 79 | blocks += num_ops * (2 * mp->m_refc_maxlevels - 1); |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 80 | |
| 81 | return blocks; |
| 82 | } |
| 83 | |
| 84 | /* |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 85 | * Logging inodes is really tricksy. They are logged in memory format, |
| 86 | * which means that what we write into the log doesn't directly translate into |
| 87 | * the amount of space they use on disk. |
| 88 | * |
| 89 | * Case in point - btree format forks in memory format use more space than the |
| 90 | * on-disk format. In memory, the buffer contains a normal btree block header so |
| 91 | * the btree code can treat it as though it is just another generic buffer. |
| 92 | * However, when we write it to the inode fork, we don't write all of this |
| 93 | * header as it isn't needed. e.g. the root is only ever in the inode, so |
| 94 | * there's no need for sibling pointers which would waste 16 bytes of space. |
| 95 | * |
| 96 | * Hence when we have an inode with a maximally sized btree format fork, then |
| 97 | * amount of information we actually log is greater than the size of the inode |
| 98 | * on disk. Hence we need an inode reservation function that calculates all this |
| 99 | * correctly. So, we log: |
| 100 | * |
Dave Chinner | fe4c224 | 2014-03-07 16:19:14 +1100 | [diff] [blame] | 101 | * - 4 log op headers for object |
| 102 | * - for the ilf, the inode core and 2 forks |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 103 | * - inode log format object |
Dave Chinner | fe4c224 | 2014-03-07 16:19:14 +1100 | [diff] [blame] | 104 | * - the inode core |
| 105 | * - two inode forks containing bmap btree root blocks. |
| 106 | * - the btree data contained by both forks will fit into the inode size, |
| 107 | * hence when combined with the inode core above, we have a total of the |
| 108 | * actual inode size. |
| 109 | * - the BMBT headers need to be accounted separately, as they are |
| 110 | * additional to the records and pointers that fit inside the inode |
| 111 | * forks. |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 112 | */ |
| 113 | STATIC uint |
| 114 | xfs_calc_inode_res( |
| 115 | struct xfs_mount *mp, |
| 116 | uint ninodes) |
| 117 | { |
Dave Chinner | fe4c224 | 2014-03-07 16:19:14 +1100 | [diff] [blame] | 118 | return ninodes * |
| 119 | (4 * sizeof(struct xlog_op_header) + |
| 120 | sizeof(struct xfs_inode_log_format) + |
| 121 | mp->m_sb.sb_inodesize + |
| 122 | 2 * XFS_BMBT_BLOCK_LEN(mp)); |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 126 | * Inode btree record insertion/removal modifies the inode btree and free space |
| 127 | * btrees (since the inobt does not use the agfl). This requires the following |
| 128 | * reservation: |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 129 | * |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 130 | * the inode btree: max depth * blocksize |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 131 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 132 | * |
| 133 | * The caller must account for SB and AG header modifications, etc. |
| 134 | */ |
| 135 | STATIC uint |
| 136 | xfs_calc_inobt_res( |
| 137 | struct xfs_mount *mp) |
| 138 | { |
| 139 | return xfs_calc_buf_res(mp->m_in_maxlevels, XFS_FSB_TO_B(mp, 1)) + |
| 140 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
| 141 | XFS_FSB_TO_B(mp, 1)); |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * The free inode btree is a conditional feature. The behavior differs slightly |
| 146 | * from that of the traditional inode btree in that the finobt tracks records |
| 147 | * for inode chunks with at least one free inode. A record can be removed from |
| 148 | * the tree during individual inode allocation. Therefore the finobt |
| 149 | * reservation is unconditional for both the inode chunk allocation and |
| 150 | * individual inode allocation (modify) cases. |
| 151 | * |
| 152 | * Behavior aside, the reservation for finobt modification is equivalent to the |
| 153 | * traditional inobt: cover a full finobt shape change plus block allocation. |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 154 | */ |
| 155 | STATIC uint |
| 156 | xfs_calc_finobt_res( |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 157 | struct xfs_mount *mp) |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 158 | { |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 159 | if (!xfs_sb_version_hasfinobt(&mp->m_sb)) |
| 160 | return 0; |
| 161 | |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 162 | return xfs_calc_inobt_res(mp); |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 166 | * Calculate the reservation required to allocate or free an inode chunk. This |
| 167 | * includes: |
| 168 | * |
| 169 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
| 170 | * the inode chunk: m_ialloc_blks * N |
| 171 | * |
| 172 | * The size N of the inode chunk reservation depends on whether it is for |
| 173 | * allocation or free and which type of create transaction is in use. An inode |
| 174 | * chunk free always invalidates the buffers and only requires reservation for |
| 175 | * headers (N == 0). An inode chunk allocation requires a chunk sized |
| 176 | * reservation on v4 and older superblocks to initialize the chunk. No chunk |
| 177 | * reservation is required for allocation on v5 supers, which use ordered |
| 178 | * buffers to initialize. |
| 179 | */ |
| 180 | STATIC uint |
| 181 | xfs_calc_inode_chunk_res( |
| 182 | struct xfs_mount *mp, |
| 183 | bool alloc) |
| 184 | { |
| 185 | uint res, size = 0; |
| 186 | |
| 187 | res = xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
| 188 | XFS_FSB_TO_B(mp, 1)); |
| 189 | if (alloc) { |
| 190 | /* icreate tx uses ordered buffers */ |
| 191 | if (xfs_sb_version_hascrc(&mp->m_sb)) |
| 192 | return res; |
| 193 | size = XFS_FSB_TO_B(mp, 1); |
| 194 | } |
| 195 | |
| 196 | res += xfs_calc_buf_res(mp->m_ialloc_blks, size); |
| 197 | return res; |
| 198 | } |
| 199 | |
| 200 | /* |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 201 | * Various log reservation values. |
| 202 | * |
| 203 | * These are based on the size of the file system block because that is what |
| 204 | * most transactions manipulate. Each adds in an additional 128 bytes per |
| 205 | * item logged to try to account for the overhead of the transaction mechanism. |
| 206 | * |
| 207 | * Note: Most of the reservations underestimate the number of allocation |
Darrick J. Wong | 310a75a | 2016-08-03 11:18:10 +1000 | [diff] [blame] | 208 | * groups into which they could free extents in the xfs_defer_finish() call. |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 209 | * This is because the number in the worst case is quite high and quite |
Darrick J. Wong | 310a75a | 2016-08-03 11:18:10 +1000 | [diff] [blame] | 210 | * unusual. In order to fix this we need to change xfs_defer_finish() to free |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 211 | * extents in only a single AG at a time. This will require changes to the |
| 212 | * EFI code as well, however, so that the EFI for the extents not freed is |
| 213 | * logged again in each transaction. See SGI PV #261917. |
| 214 | * |
| 215 | * Reservation functions here avoid a huge stack in xfs_trans_init due to |
| 216 | * register overflow from temporaries in the calculations. |
| 217 | */ |
| 218 | |
| 219 | |
| 220 | /* |
| 221 | * In a write transaction we can allocate a maximum of 2 |
| 222 | * extents. This gives: |
| 223 | * the inode getting the new extents: inode size |
| 224 | * the inode's bmap btree: max depth * block size |
| 225 | * the agfs of the ags from which the extents are allocated: 2 * sector |
| 226 | * the superblock free block counter: sector size |
| 227 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 228 | * And the bmap_finish transaction can free bmap blocks in a join: |
| 229 | * the agfs of the ags containing the blocks: 2 * sector size |
| 230 | * the agfls of the ags containing the blocks: 2 * sector size |
| 231 | * the super block free block counter: sector size |
| 232 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 233 | */ |
| 234 | STATIC uint |
| 235 | xfs_calc_write_reservation( |
| 236 | struct xfs_mount *mp) |
| 237 | { |
| 238 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 239 | max((xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 240 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), |
| 241 | XFS_FSB_TO_B(mp, 1)) + |
| 242 | xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 243 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 244 | XFS_FSB_TO_B(mp, 1))), |
| 245 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 246 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 247 | XFS_FSB_TO_B(mp, 1)))); |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * In truncating a file we free up to two extents at once. We can modify: |
| 252 | * the inode being truncated: inode size |
| 253 | * the inode's bmap btree: (max depth + 1) * block size |
| 254 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
| 255 | * the agf for each of the ags: 4 * sector size |
| 256 | * the agfl for each of the ags: 4 * sector size |
| 257 | * the super block to reflect the freed blocks: sector size |
| 258 | * worst case split in allocation btrees per extent assuming 4 extents: |
| 259 | * 4 exts * 2 trees * (2 * max depth - 1) * block size |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 260 | */ |
| 261 | STATIC uint |
| 262 | xfs_calc_itruncate_reservation( |
| 263 | struct xfs_mount *mp) |
| 264 | { |
| 265 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 266 | max((xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 267 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, |
| 268 | XFS_FSB_TO_B(mp, 1))), |
| 269 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 270 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4), |
Brian Foster | a606ebd | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 271 | XFS_FSB_TO_B(mp, 1)))); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* |
| 275 | * In renaming a files we can modify: |
| 276 | * the four inodes involved: 4 * inode size |
| 277 | * the two directory btrees: 2 * (max depth + v2) * dir block size |
| 278 | * the two directory bmap btrees: 2 * max depth * block size |
| 279 | * And the bmap_finish transaction can free dir and bmap blocks (two sets |
| 280 | * of bmap blocks) giving: |
| 281 | * the agf for the ags in which the blocks live: 3 * sector size |
| 282 | * the agfl for the ags in which the blocks live: 3 * sector size |
| 283 | * the superblock for the free block count: sector size |
| 284 | * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size |
| 285 | */ |
| 286 | STATIC uint |
| 287 | xfs_calc_rename_reservation( |
| 288 | struct xfs_mount *mp) |
| 289 | { |
| 290 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 291 | max((xfs_calc_inode_res(mp, 4) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 292 | xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), |
| 293 | XFS_FSB_TO_B(mp, 1))), |
| 294 | (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 295 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 3), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 296 | XFS_FSB_TO_B(mp, 1)))); |
| 297 | } |
| 298 | |
| 299 | /* |
Zhi Yong Wu | ab29743 | 2013-12-18 08:22:41 +0800 | [diff] [blame] | 300 | * For removing an inode from unlinked list at first, we can modify: |
| 301 | * the agi hash list and counters: sector size |
| 302 | * the on disk inode before ours in the agi hash list: inode cluster size |
Brian Foster | e8341d9 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 303 | * the on disk inode in the agi hash list: inode cluster size |
Zhi Yong Wu | ab29743 | 2013-12-18 08:22:41 +0800 | [diff] [blame] | 304 | */ |
| 305 | STATIC uint |
| 306 | xfs_calc_iunlink_remove_reservation( |
| 307 | struct xfs_mount *mp) |
| 308 | { |
| 309 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
Brian Foster | e8341d9 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 310 | 2 * max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size); |
Zhi Yong Wu | ab29743 | 2013-12-18 08:22:41 +0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 314 | * For creating a link to an inode: |
| 315 | * the parent directory inode: inode size |
| 316 | * the linked inode: inode size |
| 317 | * the directory btree could split: (max depth + v2) * dir block size |
| 318 | * the directory bmap btree could join or split: (max depth + v2) * blocksize |
| 319 | * And the bmap_finish transaction can free some bmap blocks giving: |
| 320 | * the agf for the ag in which the blocks live: sector size |
| 321 | * the agfl for the ag in which the blocks live: sector size |
| 322 | * the superblock for the free block count: sector size |
| 323 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size |
| 324 | */ |
| 325 | STATIC uint |
| 326 | xfs_calc_link_reservation( |
| 327 | struct xfs_mount *mp) |
| 328 | { |
| 329 | return XFS_DQUOT_LOGRES(mp) + |
Zhi Yong Wu | ab29743 | 2013-12-18 08:22:41 +0800 | [diff] [blame] | 330 | xfs_calc_iunlink_remove_reservation(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 331 | max((xfs_calc_inode_res(mp, 2) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 332 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 333 | XFS_FSB_TO_B(mp, 1))), |
| 334 | (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 335 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 336 | XFS_FSB_TO_B(mp, 1)))); |
| 337 | } |
| 338 | |
| 339 | /* |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 340 | * For adding an inode to unlinked list we can modify: |
| 341 | * the agi hash list: sector size |
Brian Foster | e8341d9 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 342 | * the on disk inode: inode cluster size |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 343 | */ |
| 344 | STATIC uint |
| 345 | xfs_calc_iunlink_add_reservation(xfs_mount_t *mp) |
| 346 | { |
| 347 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
Brian Foster | e8341d9 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 348 | max_t(uint, XFS_FSB_TO_B(mp, 1), mp->m_inode_cluster_size); |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 352 | * For removing a directory entry we can modify: |
| 353 | * the parent directory inode: inode size |
| 354 | * the removed inode: inode size |
| 355 | * the directory btree could join: (max depth + v2) * dir block size |
| 356 | * the directory bmap btree could join or split: (max depth + v2) * blocksize |
| 357 | * And the bmap_finish transaction can free the dir and bmap blocks giving: |
| 358 | * the agf for the ag in which the blocks live: 2 * sector size |
| 359 | * the agfl for the ag in which the blocks live: 2 * sector size |
| 360 | * the superblock for the free block count: sector size |
| 361 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 362 | */ |
| 363 | STATIC uint |
| 364 | xfs_calc_remove_reservation( |
| 365 | struct xfs_mount *mp) |
| 366 | { |
| 367 | return XFS_DQUOT_LOGRES(mp) + |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 368 | xfs_calc_iunlink_add_reservation(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 369 | max((xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 370 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 371 | XFS_FSB_TO_B(mp, 1))), |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 372 | (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 373 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 374 | XFS_FSB_TO_B(mp, 1)))); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * For create, break it in to the two cases that the transaction |
| 379 | * covers. We start with the modify case - allocation done by modification |
| 380 | * of the state of existing inodes - and the allocation case. |
| 381 | */ |
| 382 | |
| 383 | /* |
| 384 | * For create we can modify: |
| 385 | * the parent directory inode: inode size |
| 386 | * the new inode: inode size |
| 387 | * the inode btree entry: block size |
| 388 | * the superblock for the nlink flag: sector size |
| 389 | * the directory btree: (max depth + v2) * dir block size |
| 390 | * the directory inode's bmap btree: (max depth + v2) * block size |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 391 | * the finobt (record modification and allocation btrees) |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 392 | */ |
| 393 | STATIC uint |
| 394 | xfs_calc_create_resv_modify( |
| 395 | struct xfs_mount *mp) |
| 396 | { |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 397 | return xfs_calc_inode_res(mp, 2) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 398 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 399 | (uint)XFS_FSB_TO_B(mp, 1) + |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 400 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)) + |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 401 | xfs_calc_finobt_res(mp); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 405 | * For icreate we can allocate some inodes giving: |
| 406 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize |
| 407 | * the superblock for the nlink flag: sector size |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 408 | * the inode chunk (allocation, optional init) |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 409 | * the inobt (record insertion) |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 410 | * the finobt (optional, record insertion) |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 411 | */ |
| 412 | STATIC uint |
| 413 | xfs_calc_icreate_resv_alloc( |
| 414 | struct xfs_mount *mp) |
| 415 | { |
| 416 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 417 | mp->m_sb.sb_sectsize + |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 418 | xfs_calc_inode_chunk_res(mp, _ALLOC) + |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 419 | xfs_calc_inobt_res(mp) + |
| 420 | xfs_calc_finobt_res(mp); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | STATIC uint |
| 424 | xfs_calc_icreate_reservation(xfs_mount_t *mp) |
| 425 | { |
| 426 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 427 | max(xfs_calc_icreate_resv_alloc(mp), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 428 | xfs_calc_create_resv_modify(mp)); |
| 429 | } |
| 430 | |
| 431 | STATIC uint |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 432 | xfs_calc_create_tmpfile_reservation( |
| 433 | struct xfs_mount *mp) |
| 434 | { |
| 435 | uint res = XFS_DQUOT_LOGRES(mp); |
| 436 | |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 437 | res += xfs_calc_icreate_resv_alloc(mp); |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 438 | return res + xfs_calc_iunlink_add_reservation(mp); |
| 439 | } |
| 440 | |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 441 | /* |
| 442 | * Making a new directory is the same as creating a new file. |
| 443 | */ |
| 444 | STATIC uint |
| 445 | xfs_calc_mkdir_reservation( |
| 446 | struct xfs_mount *mp) |
| 447 | { |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 448 | return xfs_calc_icreate_reservation(mp); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | |
| 452 | /* |
| 453 | * Making a new symplink is the same as creating a new file, but |
| 454 | * with the added blocks for remote symlink data which can be up to 1kB in |
Darrick J. Wong | 6eb0b8d | 2017-07-07 08:37:26 -0700 | [diff] [blame] | 455 | * length (XFS_SYMLINK_MAXLEN). |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 456 | */ |
| 457 | STATIC uint |
| 458 | xfs_calc_symlink_reservation( |
| 459 | struct xfs_mount *mp) |
| 460 | { |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 461 | return xfs_calc_icreate_reservation(mp) + |
Darrick J. Wong | 6eb0b8d | 2017-07-07 08:37:26 -0700 | [diff] [blame] | 462 | xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /* |
| 466 | * In freeing an inode we can modify: |
| 467 | * the inode being freed: inode size |
Brian Foster | a6f4859 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 468 | * the super block free inode counter, AGF and AGFL: sector size |
| 469 | * the on disk inode (agi unlinked list removal) |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 470 | * the inode chunk (invalidated, headers only) |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 471 | * the inode btree |
Brian Foster | 9d43b18 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 472 | * the finobt (record insertion, removal or modification) |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 473 | * |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 474 | * Note that the inode chunk res. includes an allocfree res. for freeing of the |
| 475 | * inode chunk. This is technically extraneous because the inode chunk free is |
| 476 | * deferred (it occurs after a transaction roll). Include the extra reservation |
| 477 | * anyways since we've had reports of ifree transaction overruns due to too many |
| 478 | * agfl fixups during inode chunk frees. |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 479 | */ |
| 480 | STATIC uint |
| 481 | xfs_calc_ifree_reservation( |
| 482 | struct xfs_mount *mp) |
| 483 | { |
| 484 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 485 | xfs_calc_inode_res(mp, 1) + |
Brian Foster | a6f4859 | 2018-01-08 10:41:36 -0800 | [diff] [blame] | 486 | xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
Zhi Yong Wu | ab29743 | 2013-12-18 08:22:41 +0800 | [diff] [blame] | 487 | xfs_calc_iunlink_remove_reservation(mp) + |
Brian Foster | 57af33e | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 488 | xfs_calc_inode_chunk_res(mp, _FREE) + |
Brian Foster | f03c78f | 2018-01-08 10:41:37 -0800 | [diff] [blame] | 489 | xfs_calc_inobt_res(mp) + |
| 490 | xfs_calc_finobt_res(mp); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /* |
| 494 | * When only changing the inode we log the inode and possibly the superblock |
| 495 | * We also add a bit of slop for the transaction stuff. |
| 496 | */ |
| 497 | STATIC uint |
| 498 | xfs_calc_ichange_reservation( |
| 499 | struct xfs_mount *mp) |
| 500 | { |
| 501 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 502 | xfs_calc_inode_res(mp, 1) + |
| 503 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 504 | |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Growing the data section of the filesystem. |
| 509 | * superblock |
| 510 | * agi and agf |
| 511 | * allocation btrees |
| 512 | */ |
| 513 | STATIC uint |
| 514 | xfs_calc_growdata_reservation( |
| 515 | struct xfs_mount *mp) |
| 516 | { |
| 517 | return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 518 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 519 | XFS_FSB_TO_B(mp, 1)); |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Growing the rt section of the filesystem. |
| 524 | * In the first set of transactions (ALLOC) we allocate space to the |
| 525 | * bitmap or summary files. |
| 526 | * superblock: sector size |
| 527 | * agf of the ag from which the extent is allocated: sector size |
| 528 | * bmap btree for bitmap/summary inode: max depth * blocksize |
| 529 | * bitmap/summary inode: inode size |
| 530 | * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize |
| 531 | */ |
| 532 | STATIC uint |
| 533 | xfs_calc_growrtalloc_reservation( |
| 534 | struct xfs_mount *mp) |
| 535 | { |
| 536 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 537 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), |
| 538 | XFS_FSB_TO_B(mp, 1)) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 539 | xfs_calc_inode_res(mp, 1) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 540 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 541 | XFS_FSB_TO_B(mp, 1)); |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * Growing the rt section of the filesystem. |
| 546 | * In the second set of transactions (ZERO) we zero the new metadata blocks. |
| 547 | * one bitmap/summary block: blocksize |
| 548 | */ |
| 549 | STATIC uint |
| 550 | xfs_calc_growrtzero_reservation( |
| 551 | struct xfs_mount *mp) |
| 552 | { |
| 553 | return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize); |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | * Growing the rt section of the filesystem. |
| 558 | * In the third set of transactions (FREE) we update metadata without |
| 559 | * allocating any new blocks. |
| 560 | * superblock: sector size |
| 561 | * bitmap inode: inode size |
| 562 | * summary inode: inode size |
| 563 | * one bitmap block: blocksize |
| 564 | * summary blocks: new summary size |
| 565 | */ |
| 566 | STATIC uint |
| 567 | xfs_calc_growrtfree_reservation( |
| 568 | struct xfs_mount *mp) |
| 569 | { |
| 570 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 571 | xfs_calc_inode_res(mp, 2) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 572 | xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) + |
| 573 | xfs_calc_buf_res(1, mp->m_rsumsize); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Logging the inode modification timestamp on a synchronous write. |
| 578 | * inode |
| 579 | */ |
| 580 | STATIC uint |
| 581 | xfs_calc_swrite_reservation( |
| 582 | struct xfs_mount *mp) |
| 583 | { |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 584 | return xfs_calc_inode_res(mp, 1); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* |
| 588 | * Logging the inode mode bits when writing a setuid/setgid file |
| 589 | * inode |
| 590 | */ |
| 591 | STATIC uint |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 592 | xfs_calc_writeid_reservation( |
| 593 | struct xfs_mount *mp) |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 594 | { |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 595 | return xfs_calc_inode_res(mp, 1); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Converting the inode from non-attributed to attributed. |
| 600 | * the inode being converted: inode size |
| 601 | * agf block and superblock (for block allocation) |
| 602 | * the new block (directory sized) |
| 603 | * bmap blocks for the new directory block |
| 604 | * allocation btrees |
| 605 | */ |
| 606 | STATIC uint |
| 607 | xfs_calc_addafork_reservation( |
| 608 | struct xfs_mount *mp) |
| 609 | { |
| 610 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 611 | xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 612 | xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
Dave Chinner | 8f66193 | 2014-06-06 15:15:59 +1000 | [diff] [blame] | 613 | xfs_calc_buf_res(1, mp->m_dir_geo->blksize) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 614 | xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1, |
| 615 | XFS_FSB_TO_B(mp, 1)) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 616 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 1), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 617 | XFS_FSB_TO_B(mp, 1)); |
| 618 | } |
| 619 | |
| 620 | /* |
| 621 | * Removing the attribute fork of a file |
| 622 | * the inode being truncated: inode size |
| 623 | * the inode's bmap btree: max depth * block size |
| 624 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
| 625 | * the agf for each of the ags: 4 * sector size |
| 626 | * the agfl for each of the ags: 4 * sector size |
| 627 | * the super block to reflect the freed blocks: sector size |
| 628 | * worst case split in allocation btrees per extent assuming 4 extents: |
| 629 | * 4 exts * 2 trees * (2 * max depth - 1) * block size |
| 630 | */ |
| 631 | STATIC uint |
| 632 | xfs_calc_attrinval_reservation( |
| 633 | struct xfs_mount *mp) |
| 634 | { |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 635 | return max((xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 636 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK), |
| 637 | XFS_FSB_TO_B(mp, 1))), |
| 638 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 639 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 4), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 640 | XFS_FSB_TO_B(mp, 1)))); |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * Setting an attribute at mount time. |
| 645 | * the inode getting the attribute |
| 646 | * the superblock for allocations |
| 647 | * the agfs extents are allocated from |
| 648 | * the attribute btree * max depth |
| 649 | * the inode allocation btree |
| 650 | * Since attribute transaction space is dependent on the size of the attribute, |
| 651 | * the calculation is done partially at mount time and partially at runtime(see |
| 652 | * below). |
| 653 | */ |
| 654 | STATIC uint |
| 655 | xfs_calc_attrsetm_reservation( |
| 656 | struct xfs_mount *mp) |
| 657 | { |
| 658 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 2395670 | 2013-08-28 16:10:35 +1000 | [diff] [blame] | 659 | xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 660 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 661 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1)); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * Setting an attribute at runtime, transaction space unit per block. |
| 666 | * the superblock for allocations: sector size |
| 667 | * the inode bmap btree could join or split: max depth * block size |
| 668 | * Since the runtime attribute transaction space is dependent on the total |
| 669 | * blocks needed for the 1st bmap, here we calculate out the space unit for |
| 670 | * one block so that the caller could figure out the total space according |
Jie Liu | 3d3c8b5 | 2013-08-12 20:49:59 +1000 | [diff] [blame] | 671 | * to the attibute extent length in blocks by: |
| 672 | * ext * M_RES(mp)->tr_attrsetrt.tr_logres |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 673 | */ |
| 674 | STATIC uint |
| 675 | xfs_calc_attrsetrt_reservation( |
| 676 | struct xfs_mount *mp) |
| 677 | { |
| 678 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 679 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK), |
| 680 | XFS_FSB_TO_B(mp, 1)); |
| 681 | } |
| 682 | |
| 683 | /* |
| 684 | * Removing an attribute. |
| 685 | * the inode: inode size |
| 686 | * the attribute btree could join: max depth * block size |
| 687 | * the inode bmap btree could join or split: max depth * block size |
| 688 | * And the bmap_finish transaction can free the attr blocks freed giving: |
| 689 | * the agf for the ag in which the blocks live: 2 * sector size |
| 690 | * the agfl for the ag in which the blocks live: 2 * sector size |
| 691 | * the superblock for the free block count: sector size |
| 692 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 693 | */ |
| 694 | STATIC uint |
| 695 | xfs_calc_attrrm_reservation( |
| 696 | struct xfs_mount *mp) |
| 697 | { |
| 698 | return XFS_DQUOT_LOGRES(mp) + |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 699 | max((xfs_calc_inode_res(mp, 1) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 700 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, |
| 701 | XFS_FSB_TO_B(mp, 1)) + |
| 702 | (uint)XFS_FSB_TO_B(mp, |
| 703 | XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + |
| 704 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)), |
| 705 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + |
Darrick J. Wong | fa30f03 | 2016-08-03 11:37:10 +1000 | [diff] [blame] | 706 | xfs_calc_buf_res(xfs_allocfree_log_count(mp, 2), |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 707 | XFS_FSB_TO_B(mp, 1)))); |
| 708 | } |
| 709 | |
| 710 | /* |
| 711 | * Clearing a bad agino number in an agi hash bucket. |
| 712 | */ |
| 713 | STATIC uint |
| 714 | xfs_calc_clear_agi_bucket_reservation( |
| 715 | struct xfs_mount *mp) |
| 716 | { |
| 717 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 718 | } |
| 719 | |
| 720 | /* |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 721 | * Adjusting quota limits. |
| 722 | * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot) |
| 723 | */ |
| 724 | STATIC uint |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 725 | xfs_calc_qm_setqlim_reservation(void) |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 726 | { |
| 727 | return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot)); |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Allocating quota on disk if needed. |
Brian Foster | 410b11a | 2014-02-07 14:55:54 +1100 | [diff] [blame] | 732 | * the write transaction log space for quota file extent allocation |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 733 | * the unit of quota allocation: one system block size |
| 734 | */ |
| 735 | STATIC uint |
| 736 | xfs_calc_qm_dqalloc_reservation( |
| 737 | struct xfs_mount *mp) |
| 738 | { |
Brian Foster | 410b11a | 2014-02-07 14:55:54 +1100 | [diff] [blame] | 739 | return xfs_calc_write_reservation(mp) + |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 740 | xfs_calc_buf_res(1, |
| 741 | XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1); |
| 742 | } |
| 743 | |
| 744 | /* |
| 745 | * Turning off quotas. |
| 746 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 |
| 747 | * the superblock for the quota flags: sector size |
| 748 | */ |
| 749 | STATIC uint |
| 750 | xfs_calc_qm_quotaoff_reservation( |
| 751 | struct xfs_mount *mp) |
| 752 | { |
| 753 | return sizeof(struct xfs_qoff_logitem) * 2 + |
| 754 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | * End of turning off quotas. |
| 759 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 |
| 760 | */ |
| 761 | STATIC uint |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 762 | xfs_calc_qm_quotaoff_end_reservation(void) |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 763 | { |
| 764 | return sizeof(struct xfs_qoff_logitem) * 2; |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Syncing the incore super block changes to disk. |
| 769 | * the super block to reflect the changes: sector size |
| 770 | */ |
| 771 | STATIC uint |
| 772 | xfs_calc_sb_reservation( |
| 773 | struct xfs_mount *mp) |
| 774 | { |
| 775 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 776 | } |
| 777 | |
| 778 | void |
| 779 | xfs_trans_resv_calc( |
| 780 | struct xfs_mount *mp, |
| 781 | struct xfs_trans_resv *resp) |
| 782 | { |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 783 | /* |
| 784 | * The following transactions are logged in physical format and |
| 785 | * require a permanent reservation on space. |
| 786 | */ |
| 787 | resp->tr_write.tr_logres = xfs_calc_write_reservation(mp); |
Darrick J. Wong | 80de462 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 788 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 789 | resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT_REFLINK; |
| 790 | else |
| 791 | resp->tr_write.tr_logcount = XFS_WRITE_LOG_COUNT; |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 792 | resp->tr_write.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 793 | |
| 794 | resp->tr_itruncate.tr_logres = xfs_calc_itruncate_reservation(mp); |
Darrick J. Wong | 80de462 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 795 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 796 | resp->tr_itruncate.tr_logcount = |
| 797 | XFS_ITRUNCATE_LOG_COUNT_REFLINK; |
| 798 | else |
| 799 | resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 800 | resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 801 | |
| 802 | resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); |
| 803 | resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT; |
| 804 | resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 805 | |
| 806 | resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); |
| 807 | resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT; |
| 808 | resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 809 | |
| 810 | resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); |
| 811 | resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT; |
| 812 | resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 813 | |
| 814 | resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); |
| 815 | resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT; |
| 816 | resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 817 | |
Brian Foster | c017cb5 | 2018-01-08 10:41:38 -0800 | [diff] [blame] | 818 | resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp); |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 819 | resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT; |
| 820 | resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 821 | |
Zhi Yong Wu | 99b6436 | 2013-12-18 08:22:40 +0800 | [diff] [blame] | 822 | resp->tr_create_tmpfile.tr_logres = |
| 823 | xfs_calc_create_tmpfile_reservation(mp); |
| 824 | resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; |
| 825 | resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 826 | |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 827 | resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); |
| 828 | resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; |
| 829 | resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 830 | |
| 831 | resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); |
| 832 | resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; |
| 833 | resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 834 | |
| 835 | resp->tr_addafork.tr_logres = xfs_calc_addafork_reservation(mp); |
| 836 | resp->tr_addafork.tr_logcount = XFS_ADDAFORK_LOG_COUNT; |
| 837 | resp->tr_addafork.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 838 | |
| 839 | resp->tr_attrinval.tr_logres = xfs_calc_attrinval_reservation(mp); |
| 840 | resp->tr_attrinval.tr_logcount = XFS_ATTRINVAL_LOG_COUNT; |
| 841 | resp->tr_attrinval.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 842 | |
| 843 | resp->tr_attrsetm.tr_logres = xfs_calc_attrsetm_reservation(mp); |
| 844 | resp->tr_attrsetm.tr_logcount = XFS_ATTRSET_LOG_COUNT; |
| 845 | resp->tr_attrsetm.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 846 | |
| 847 | resp->tr_attrrm.tr_logres = xfs_calc_attrrm_reservation(mp); |
| 848 | resp->tr_attrrm.tr_logcount = XFS_ATTRRM_LOG_COUNT; |
| 849 | resp->tr_attrrm.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 850 | |
| 851 | resp->tr_growrtalloc.tr_logres = xfs_calc_growrtalloc_reservation(mp); |
| 852 | resp->tr_growrtalloc.tr_logcount = XFS_DEFAULT_PERM_LOG_COUNT; |
| 853 | resp->tr_growrtalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 854 | |
| 855 | resp->tr_qm_dqalloc.tr_logres = xfs_calc_qm_dqalloc_reservation(mp); |
Darrick J. Wong | 80de462 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 856 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 857 | resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT_REFLINK; |
| 858 | else |
| 859 | resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT; |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 860 | resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; |
| 861 | |
| 862 | /* |
| 863 | * The following transactions are logged in logical format with |
| 864 | * a default log count. |
| 865 | */ |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 866 | resp->tr_qm_setqlim.tr_logres = xfs_calc_qm_setqlim_reservation(); |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 867 | resp->tr_qm_setqlim.tr_logcount = XFS_DEFAULT_LOG_COUNT; |
| 868 | |
| 869 | resp->tr_qm_quotaoff.tr_logres = xfs_calc_qm_quotaoff_reservation(mp); |
| 870 | resp->tr_qm_quotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT; |
| 871 | |
| 872 | resp->tr_qm_equotaoff.tr_logres = |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 873 | xfs_calc_qm_quotaoff_end_reservation(); |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 874 | resp->tr_qm_equotaoff.tr_logcount = XFS_DEFAULT_LOG_COUNT; |
| 875 | |
| 876 | resp->tr_sb.tr_logres = xfs_calc_sb_reservation(mp); |
| 877 | resp->tr_sb.tr_logcount = XFS_DEFAULT_LOG_COUNT; |
| 878 | |
| 879 | /* The following transaction are logged in logical format */ |
| 880 | resp->tr_ichange.tr_logres = xfs_calc_ichange_reservation(mp); |
| 881 | resp->tr_growdata.tr_logres = xfs_calc_growdata_reservation(mp); |
Jie Liu | 20996c9 | 2013-08-12 20:49:57 +1000 | [diff] [blame] | 882 | resp->tr_fsyncts.tr_logres = xfs_calc_swrite_reservation(mp); |
Jie Liu | 0eadd10 | 2013-08-12 20:49:56 +1000 | [diff] [blame] | 883 | resp->tr_writeid.tr_logres = xfs_calc_writeid_reservation(mp); |
| 884 | resp->tr_attrsetrt.tr_logres = xfs_calc_attrsetrt_reservation(mp); |
| 885 | resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp); |
| 886 | resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp); |
| 887 | resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp); |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 888 | } |