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