Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 3 | * Copyright (C) 2010 Red Hat, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * published by the Free Software Foundation. |
| 9 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "xfs_types.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" |
| 23 | #include "xfs_trans.h" |
| 24 | #include "xfs_sb.h" |
| 25 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_mount.h" |
| 27 | #include "xfs_error.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 28 | #include "xfs_da_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 30 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_ialloc_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 32 | #include "xfs_dinode.h" |
| 33 | #include "xfs_inode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "xfs_btree.h" |
| 35 | #include "xfs_ialloc.h" |
| 36 | #include "xfs_alloc.h" |
Dave Chinner | efc27b5 | 2012-04-29 10:39:43 +0000 | [diff] [blame] | 37 | #include "xfs_extent_busy.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_quota.h" |
Jeff Liu | 4f3b578 | 2013-01-28 21:25:35 +0800 | [diff] [blame] | 40 | #include "xfs_qm.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 41 | #include "xfs_trans_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "xfs_trans_space.h" |
Niv Sardi | 322ff6b | 2008-08-13 16:05:49 +1000 | [diff] [blame] | 43 | #include "xfs_inode_item.h" |
Jeff Liu | 4f3b578 | 2013-01-28 21:25:35 +0800 | [diff] [blame] | 44 | #include "xfs_log_priv.h" |
| 45 | #include "xfs_buf_item.h" |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 46 | #include "xfs_trace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 48 | kmem_zone_t *xfs_trans_zone; |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 49 | kmem_zone_t *xfs_log_item_desc_zone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Jeff Liu | 4f3b578 | 2013-01-28 21:25:35 +0800 | [diff] [blame] | 51 | /* |
| 52 | * A buffer has a format structure overhead in the log in addition |
| 53 | * to the data, so we need to take this into account when reserving |
| 54 | * space in a transaction for a buffer. Round the space required up |
| 55 | * to a multiple of 128 bytes so that we don't change the historical |
| 56 | * reservation that has been used for this overhead. |
| 57 | */ |
| 58 | STATIC uint |
| 59 | xfs_buf_log_overhead(void) |
| 60 | { |
| 61 | return round_up(sizeof(struct xlog_op_header) + |
| 62 | sizeof(struct xfs_buf_log_format), 128); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Calculate out transaction log reservation per item in bytes. |
| 67 | * |
| 68 | * The nbufs argument is used to indicate the number of items that |
| 69 | * will be changed in a transaction. size is used to tell how many |
| 70 | * bytes should be reserved per item. |
| 71 | */ |
| 72 | STATIC uint |
| 73 | xfs_calc_buf_res( |
| 74 | uint nbufs, |
| 75 | uint size) |
| 76 | { |
| 77 | return nbufs * (size + xfs_buf_log_overhead()); |
| 78 | } |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 81 | * Various log reservation values. |
| 82 | * |
| 83 | * These are based on the size of the file system block because that is what |
| 84 | * most transactions manipulate. Each adds in an additional 128 bytes per |
| 85 | * item logged to try to account for the overhead of the transaction mechanism. |
| 86 | * |
| 87 | * Note: Most of the reservations underestimate the number of allocation |
| 88 | * groups into which they could free extents in the xfs_bmap_finish() call. |
| 89 | * This is because the number in the worst case is quite high and quite |
| 90 | * unusual. In order to fix this we need to change xfs_bmap_finish() to free |
| 91 | * extents in only a single AG at a time. This will require changes to the |
| 92 | * EFI code as well, however, so that the EFI for the extents not freed is |
| 93 | * logged again in each transaction. See SGI PV #261917. |
| 94 | * |
| 95 | * Reservation functions here avoid a huge stack in xfs_trans_init due to |
| 96 | * register overflow from temporaries in the calculations. |
| 97 | */ |
| 98 | |
| 99 | |
| 100 | /* |
| 101 | * In a write transaction we can allocate a maximum of 2 |
| 102 | * extents. This gives: |
| 103 | * the inode getting the new extents: inode size |
| 104 | * the inode's bmap btree: max depth * block size |
| 105 | * the agfs of the ags from which the extents are allocated: 2 * sector |
| 106 | * the superblock free block counter: sector size |
| 107 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 108 | * And the bmap_finish transaction can free bmap blocks in a join: |
| 109 | * the agfs of the ags containing the blocks: 2 * sector size |
| 110 | * the agfls of the ags containing the blocks: 2 * sector size |
| 111 | * the super block free block counter: sector size |
| 112 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 113 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 114 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 115 | xfs_calc_write_reservation( |
| 116 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 117 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 118 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 119 | MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 120 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), |
| 121 | XFS_FSB_TO_B(mp, 1)) + |
| 122 | xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
| 123 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), |
| 124 | XFS_FSB_TO_B(mp, 1))), |
| 125 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + |
| 126 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), |
| 127 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 128 | } |
| 129 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 130 | /* |
| 131 | * In truncating a file we free up to two extents at once. We can modify: |
| 132 | * the inode being truncated: inode size |
| 133 | * the inode's bmap btree: (max depth + 1) * block size |
| 134 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
| 135 | * the agf for each of the ags: 4 * sector size |
| 136 | * the agfl for each of the ags: 4 * sector size |
| 137 | * the super block to reflect the freed blocks: sector size |
| 138 | * worst case split in allocation btrees per extent assuming 4 extents: |
| 139 | * 4 exts * 2 trees * (2 * max depth - 1) * block size |
| 140 | * the inode btree: max depth * blocksize |
| 141 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
| 142 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 143 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 144 | xfs_calc_itruncate_reservation( |
| 145 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 146 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 147 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 148 | MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 149 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1, |
| 150 | XFS_FSB_TO_B(mp, 1))), |
| 151 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + |
| 152 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4), |
| 153 | XFS_FSB_TO_B(mp, 1)) + |
| 154 | xfs_calc_buf_res(5, 0) + |
| 155 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 156 | XFS_FSB_TO_B(mp, 1)) + |
| 157 | xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) + |
| 158 | mp->m_in_maxlevels, 0))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 159 | } |
| 160 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 161 | /* |
| 162 | * In renaming a files we can modify: |
| 163 | * the four inodes involved: 4 * inode size |
| 164 | * the two directory btrees: 2 * (max depth + v2) * dir block size |
| 165 | * the two directory bmap btrees: 2 * max depth * block size |
| 166 | * And the bmap_finish transaction can free dir and bmap blocks (two sets |
| 167 | * of bmap blocks) giving: |
| 168 | * the agf for the ags in which the blocks live: 3 * sector size |
| 169 | * the agfl for the ags in which the blocks live: 3 * sector size |
| 170 | * the superblock for the free block count: sector size |
| 171 | * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size |
| 172 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 173 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 174 | xfs_calc_rename_reservation( |
| 175 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 176 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 177 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 178 | MAX((xfs_calc_buf_res(4, mp->m_sb.sb_inodesize) + |
| 179 | xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), |
| 180 | XFS_FSB_TO_B(mp, 1))), |
| 181 | (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + |
| 182 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3), |
| 183 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 184 | } |
| 185 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 186 | /* |
| 187 | * For creating a link to an inode: |
| 188 | * the parent directory inode: inode size |
| 189 | * the linked inode: inode size |
| 190 | * the directory btree could split: (max depth + v2) * dir block size |
| 191 | * the directory bmap btree could join or split: (max depth + v2) * blocksize |
| 192 | * And the bmap_finish transaction can free some bmap blocks giving: |
| 193 | * the agf for the ag in which the blocks live: sector size |
| 194 | * the agfl for the ag in which the blocks live: sector size |
| 195 | * the superblock for the free block count: sector size |
| 196 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size |
| 197 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 198 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 199 | xfs_calc_link_reservation( |
| 200 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 201 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 202 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 203 | MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) + |
| 204 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 205 | XFS_FSB_TO_B(mp, 1))), |
| 206 | (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
| 207 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 208 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 209 | } |
| 210 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 211 | /* |
| 212 | * For removing a directory entry we can modify: |
| 213 | * the parent directory inode: inode size |
| 214 | * the removed inode: inode size |
| 215 | * the directory btree could join: (max depth + v2) * dir block size |
| 216 | * the directory bmap btree could join or split: (max depth + v2) * blocksize |
| 217 | * And the bmap_finish transaction can free the dir and bmap blocks giving: |
| 218 | * the agf for the ag in which the blocks live: 2 * sector size |
| 219 | * the agfl for the ag in which the blocks live: 2 * sector size |
| 220 | * the superblock for the free block count: sector size |
| 221 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 222 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 223 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 224 | xfs_calc_remove_reservation( |
| 225 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 226 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 227 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 228 | MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) + |
| 229 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 230 | XFS_FSB_TO_B(mp, 1))), |
| 231 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + |
| 232 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), |
| 233 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 234 | } |
| 235 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 236 | /* |
| 237 | * For symlink we can modify: |
| 238 | * the parent directory inode: inode size |
| 239 | * the new inode: inode size |
| 240 | * the inode btree entry: 1 block |
| 241 | * the directory btree: (max depth + v2) * dir block size |
| 242 | * the directory inode's bmap btree: (max depth + v2) * block size |
| 243 | * the blocks for the symlink: 1 kB |
| 244 | * Or in the first xact we allocate some inodes giving: |
| 245 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize |
| 246 | * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize |
| 247 | * the inode btree: max depth * blocksize |
| 248 | * the allocation btrees: 2 trees * (2 * max depth - 1) * block size |
| 249 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 250 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 251 | xfs_calc_symlink_reservation( |
| 252 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 253 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 254 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 255 | MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) + |
| 256 | xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) + |
| 257 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 258 | XFS_FSB_TO_B(mp, 1)) + |
| 259 | xfs_calc_buf_res(1, 1024)), |
| 260 | (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 261 | xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp), |
| 262 | XFS_FSB_TO_B(mp, 1)) + |
| 263 | xfs_calc_buf_res(mp->m_in_maxlevels, |
| 264 | XFS_FSB_TO_B(mp, 1)) + |
| 265 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 266 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 267 | } |
| 268 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 269 | /* |
| 270 | * For create we can modify: |
| 271 | * the parent directory inode: inode size |
| 272 | * the new inode: inode size |
| 273 | * the inode btree entry: block size |
| 274 | * the superblock for the nlink flag: sector size |
| 275 | * the directory btree: (max depth + v2) * dir block size |
| 276 | * the directory inode's bmap btree: (max depth + v2) * block size |
| 277 | * Or in the first xact we allocate some inodes giving: |
| 278 | * the agi and agf of the ag getting the new inodes: 2 * sectorsize |
| 279 | * the superblock for the nlink flag: sector size |
| 280 | * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize |
| 281 | * the inode btree: max depth * blocksize |
| 282 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
| 283 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 284 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 285 | xfs_calc_create_reservation( |
| 286 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 287 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 288 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 289 | MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) + |
| 290 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 291 | (uint)XFS_FSB_TO_B(mp, 1) + |
| 292 | xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), |
| 293 | XFS_FSB_TO_B(mp, 1))), |
| 294 | (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 295 | mp->m_sb.sb_sectsize + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 296 | xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp), |
| 297 | XFS_FSB_TO_B(mp, 1)) + |
| 298 | xfs_calc_buf_res(mp->m_in_maxlevels, |
| 299 | XFS_FSB_TO_B(mp, 1)) + |
| 300 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 301 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 302 | } |
| 303 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 304 | /* |
| 305 | * Making a new directory is the same as creating a new file. |
| 306 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 307 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 308 | xfs_calc_mkdir_reservation( |
| 309 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 310 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 311 | return xfs_calc_create_reservation(mp); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 312 | } |
| 313 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 314 | /* |
| 315 | * In freeing an inode we can modify: |
| 316 | * the inode being freed: inode size |
| 317 | * the super block free inode counter: sector size |
| 318 | * the agi hash list and counters: sector size |
| 319 | * the inode btree entry: block size |
| 320 | * the on disk inode before ours in the agi hash list: inode cluster size |
| 321 | * the inode btree: max depth * blocksize |
| 322 | * the allocation btrees: 2 trees * (max depth - 1) * block size |
| 323 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 324 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 325 | xfs_calc_ifree_reservation( |
| 326 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 327 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 328 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 329 | xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 330 | xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 331 | xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) + |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 332 | MAX((__uint16_t)XFS_FSB_TO_B(mp, 1), |
| 333 | XFS_INODE_CLUSTER_SIZE(mp)) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 334 | xfs_calc_buf_res(1, 0) + |
| 335 | xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) + |
| 336 | mp->m_in_maxlevels, 0) + |
| 337 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 338 | XFS_FSB_TO_B(mp, 1)); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 339 | } |
| 340 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 341 | /* |
| 342 | * When only changing the inode we log the inode and possibly the superblock |
| 343 | * We also add a bit of slop for the transaction stuff. |
| 344 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 345 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 346 | xfs_calc_ichange_reservation( |
| 347 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 348 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 349 | return XFS_DQUOT_LOGRES(mp) + |
| 350 | mp->m_sb.sb_inodesize + |
| 351 | mp->m_sb.sb_sectsize + |
| 352 | 512; |
| 353 | |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 354 | } |
| 355 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 356 | /* |
| 357 | * Growing the data section of the filesystem. |
| 358 | * superblock |
| 359 | * agi and agf |
| 360 | * allocation btrees |
| 361 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 362 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 363 | xfs_calc_growdata_reservation( |
| 364 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 365 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 366 | return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + |
| 367 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 368 | XFS_FSB_TO_B(mp, 1)); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 369 | } |
| 370 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 371 | /* |
| 372 | * Growing the rt section of the filesystem. |
| 373 | * In the first set of transactions (ALLOC) we allocate space to the |
| 374 | * bitmap or summary files. |
| 375 | * superblock: sector size |
| 376 | * agf of the ag from which the extent is allocated: sector size |
| 377 | * bmap btree for bitmap/summary inode: max depth * blocksize |
| 378 | * bitmap/summary inode: inode size |
| 379 | * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize |
| 380 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 381 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 382 | xfs_calc_growrtalloc_reservation( |
| 383 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 384 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 385 | return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 386 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), |
| 387 | XFS_FSB_TO_B(mp, 1)) + |
| 388 | xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 389 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 390 | XFS_FSB_TO_B(mp, 1)); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 391 | } |
| 392 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 393 | /* |
| 394 | * Growing the rt section of the filesystem. |
| 395 | * In the second set of transactions (ZERO) we zero the new metadata blocks. |
| 396 | * one bitmap/summary block: blocksize |
| 397 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 398 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 399 | xfs_calc_growrtzero_reservation( |
| 400 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 401 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 402 | return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 403 | } |
| 404 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 405 | /* |
| 406 | * Growing the rt section of the filesystem. |
| 407 | * In the third set of transactions (FREE) we update metadata without |
| 408 | * allocating any new blocks. |
| 409 | * superblock: sector size |
| 410 | * bitmap inode: inode size |
| 411 | * summary inode: inode size |
| 412 | * one bitmap block: blocksize |
| 413 | * summary blocks: new summary size |
| 414 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 415 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 416 | xfs_calc_growrtfree_reservation( |
| 417 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 418 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 419 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 420 | xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) + |
| 421 | xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) + |
| 422 | xfs_calc_buf_res(1, mp->m_rsumsize); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 423 | } |
| 424 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 425 | /* |
| 426 | * Logging the inode modification timestamp on a synchronous write. |
| 427 | * inode |
| 428 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 429 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 430 | xfs_calc_swrite_reservation( |
| 431 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 432 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 433 | return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 434 | } |
| 435 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 436 | /* |
| 437 | * Logging the inode mode bits when writing a setuid/setgid file |
| 438 | * inode |
| 439 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 440 | STATIC uint |
| 441 | xfs_calc_writeid_reservation(xfs_mount_t *mp) |
| 442 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 443 | return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 444 | } |
| 445 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 446 | /* |
| 447 | * Converting the inode from non-attributed to attributed. |
| 448 | * the inode being converted: inode size |
| 449 | * agf block and superblock (for block allocation) |
| 450 | * the new block (directory sized) |
| 451 | * bmap blocks for the new directory block |
| 452 | * allocation btrees |
| 453 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 454 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 455 | xfs_calc_addafork_reservation( |
| 456 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 457 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 458 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 459 | xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 460 | xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + |
| 461 | xfs_calc_buf_res(1, mp->m_dirblksize) + |
| 462 | xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1, |
| 463 | XFS_FSB_TO_B(mp, 1)) + |
| 464 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1), |
| 465 | XFS_FSB_TO_B(mp, 1)); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 466 | } |
| 467 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 468 | /* |
| 469 | * Removing the attribute fork of a file |
| 470 | * the inode being truncated: inode size |
| 471 | * the inode's bmap btree: max depth * block size |
| 472 | * And the bmap_finish transaction can free the blocks and bmap blocks: |
| 473 | * the agf for each of the ags: 4 * sector size |
| 474 | * the agfl for each of the ags: 4 * sector size |
| 475 | * the super block to reflect the freed blocks: sector size |
| 476 | * worst case split in allocation btrees per extent assuming 4 extents: |
| 477 | * 4 exts * 2 trees * (2 * max depth - 1) * block size |
| 478 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 479 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 480 | xfs_calc_attrinval_reservation( |
| 481 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 482 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 483 | return MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 484 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK), |
| 485 | XFS_FSB_TO_B(mp, 1))), |
| 486 | (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) + |
| 487 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4), |
| 488 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 489 | } |
| 490 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 491 | /* |
| 492 | * Setting an attribute. |
| 493 | * the inode getting the attribute |
| 494 | * the superblock for allocations |
| 495 | * the agfs extents are allocated from |
| 496 | * the attribute btree * max depth |
| 497 | * the inode allocation btree |
| 498 | * Since attribute transaction space is dependent on the size of the attribute, |
| 499 | * the calculation is done partially at mount time and partially at runtime. |
| 500 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 501 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 502 | xfs_calc_attrset_reservation( |
| 503 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 504 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 505 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 506 | xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 507 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + |
| 508 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1)); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 509 | } |
| 510 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 511 | /* |
| 512 | * Removing an attribute. |
| 513 | * the inode: inode size |
| 514 | * the attribute btree could join: max depth * block size |
| 515 | * the inode bmap btree could join or split: max depth * block size |
| 516 | * And the bmap_finish transaction can free the attr blocks freed giving: |
| 517 | * the agf for the ag in which the blocks live: 2 * sector size |
| 518 | * the agfl for the ag in which the blocks live: 2 * sector size |
| 519 | * the superblock for the free block count: sector size |
| 520 | * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size |
| 521 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 522 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 523 | xfs_calc_attrrm_reservation( |
| 524 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 525 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 526 | return XFS_DQUOT_LOGRES(mp) + |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 527 | MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) + |
| 528 | xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, |
| 529 | XFS_FSB_TO_B(mp, 1)) + |
| 530 | (uint)XFS_FSB_TO_B(mp, |
| 531 | XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + |
| 532 | xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)), |
| 533 | (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) + |
| 534 | xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2), |
| 535 | XFS_FSB_TO_B(mp, 1)))); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 536 | } |
| 537 | |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 538 | /* |
| 539 | * Clearing a bad agino number in an agi hash bucket. |
| 540 | */ |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 541 | STATIC uint |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 542 | xfs_calc_clear_agi_bucket_reservation( |
| 543 | struct xfs_mount *mp) |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 544 | { |
Jeff Liu | 5b292ae | 2013-02-01 14:39:29 -0600 | [diff] [blame] | 545 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /* |
Jeff Liu | b0c10b98 | 2013-01-28 21:26:16 +0800 | [diff] [blame] | 549 | * Clearing the quotaflags in the superblock. |
| 550 | * the super block for changing quota flags: sector size |
| 551 | */ |
| 552 | STATIC uint |
| 553 | xfs_calc_qm_sbchange_reservation( |
| 554 | struct xfs_mount *mp) |
| 555 | { |
| 556 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 557 | } |
| 558 | |
| 559 | /* |
Jeff Liu | f0f2df9 | 2013-01-28 21:26:49 +0800 | [diff] [blame] | 560 | * Adjusting quota limits. |
| 561 | * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot) |
| 562 | */ |
| 563 | STATIC uint |
| 564 | xfs_calc_qm_setqlim_reservation( |
| 565 | struct xfs_mount *mp) |
| 566 | { |
| 567 | return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot)); |
| 568 | } |
| 569 | |
| 570 | /* |
Jeff Liu | 4800104 | 2013-01-28 21:27:04 +0800 | [diff] [blame] | 571 | * Allocating quota on disk if needed. |
| 572 | * the write transaction log space: XFS_WRITE_LOG_RES(mp) |
| 573 | * the unit of quota allocation: one system block size |
| 574 | */ |
| 575 | STATIC uint |
| 576 | xfs_calc_qm_dqalloc_reservation( |
| 577 | struct xfs_mount *mp) |
| 578 | { |
| 579 | return XFS_WRITE_LOG_RES(mp) + |
| 580 | xfs_calc_buf_res(1, |
| 581 | XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1); |
| 582 | } |
| 583 | |
| 584 | /* |
Jeff Liu | a1bd955 | 2013-01-28 21:27:15 +0800 | [diff] [blame] | 585 | * Turning off quotas. |
| 586 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 |
| 587 | * the superblock for the quota flags: sector size |
| 588 | */ |
| 589 | STATIC uint |
| 590 | xfs_calc_qm_quotaoff_reservation( |
| 591 | struct xfs_mount *mp) |
| 592 | { |
| 593 | return sizeof(struct xfs_qoff_logitem) * 2 + |
| 594 | xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 595 | } |
| 596 | |
| 597 | /* |
Jeff Liu | 762d7ba | 2013-01-28 21:27:21 +0800 | [diff] [blame] | 598 | * End of turning off quotas. |
| 599 | * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2 |
| 600 | */ |
| 601 | STATIC uint |
| 602 | xfs_calc_qm_quotaoff_end_reservation( |
| 603 | struct xfs_mount *mp) |
| 604 | { |
| 605 | return sizeof(struct xfs_qoff_logitem) * 2; |
| 606 | } |
| 607 | |
| 608 | /* |
Jeff Liu | a7bd794 | 2013-01-28 21:27:25 +0800 | [diff] [blame] | 609 | * Syncing the incore super block changes to disk. |
| 610 | * the super block to reflect the changes: sector size |
| 611 | */ |
| 612 | STATIC uint |
| 613 | xfs_calc_sb_reservation( |
| 614 | struct xfs_mount *mp) |
| 615 | { |
| 616 | return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); |
| 617 | } |
| 618 | |
| 619 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | * Initialize the precomputed transaction reservation values |
| 621 | * in the mount structure. |
| 622 | */ |
| 623 | void |
| 624 | xfs_trans_init( |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 625 | struct xfs_mount *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
Christoph Hellwig | 025101d | 2010-05-04 13:53:48 +0000 | [diff] [blame] | 627 | struct xfs_trans_reservations *resp = &mp->m_reservations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Nathan Scott | 8f79405 | 2006-03-14 13:32:41 +1100 | [diff] [blame] | 629 | resp->tr_write = xfs_calc_write_reservation(mp); |
| 630 | resp->tr_itruncate = xfs_calc_itruncate_reservation(mp); |
| 631 | resp->tr_rename = xfs_calc_rename_reservation(mp); |
| 632 | resp->tr_link = xfs_calc_link_reservation(mp); |
| 633 | resp->tr_remove = xfs_calc_remove_reservation(mp); |
| 634 | resp->tr_symlink = xfs_calc_symlink_reservation(mp); |
| 635 | resp->tr_create = xfs_calc_create_reservation(mp); |
| 636 | resp->tr_mkdir = xfs_calc_mkdir_reservation(mp); |
| 637 | resp->tr_ifree = xfs_calc_ifree_reservation(mp); |
| 638 | resp->tr_ichange = xfs_calc_ichange_reservation(mp); |
| 639 | resp->tr_growdata = xfs_calc_growdata_reservation(mp); |
| 640 | resp->tr_swrite = xfs_calc_swrite_reservation(mp); |
| 641 | resp->tr_writeid = xfs_calc_writeid_reservation(mp); |
| 642 | resp->tr_addafork = xfs_calc_addafork_reservation(mp); |
| 643 | resp->tr_attrinval = xfs_calc_attrinval_reservation(mp); |
| 644 | resp->tr_attrset = xfs_calc_attrset_reservation(mp); |
| 645 | resp->tr_attrrm = xfs_calc_attrrm_reservation(mp); |
| 646 | resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp); |
| 647 | resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp); |
| 648 | resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp); |
| 649 | resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp); |
Jeff Liu | b0c10b98 | 2013-01-28 21:26:16 +0800 | [diff] [blame] | 650 | resp->tr_qm_sbchange = xfs_calc_qm_sbchange_reservation(mp); |
Jeff Liu | f0f2df9 | 2013-01-28 21:26:49 +0800 | [diff] [blame] | 651 | resp->tr_qm_setqlim = xfs_calc_qm_setqlim_reservation(mp); |
Jeff Liu | 4800104 | 2013-01-28 21:27:04 +0800 | [diff] [blame] | 652 | resp->tr_qm_dqalloc = xfs_calc_qm_dqalloc_reservation(mp); |
Jeff Liu | a1bd955 | 2013-01-28 21:27:15 +0800 | [diff] [blame] | 653 | resp->tr_qm_quotaoff = xfs_calc_qm_quotaoff_reservation(mp); |
Jeff Liu | 762d7ba | 2013-01-28 21:27:21 +0800 | [diff] [blame] | 654 | resp->tr_qm_equotaoff = xfs_calc_qm_quotaoff_end_reservation(mp); |
Jeff Liu | a7bd794 | 2013-01-28 21:27:25 +0800 | [diff] [blame] | 655 | resp->tr_sb = xfs_calc_sb_reservation(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /* |
| 659 | * This routine is called to allocate a transaction structure. |
| 660 | * The type parameter indicates the type of the transaction. These |
| 661 | * are enumerated in xfs_trans.h. |
Alex Elder | b2ce397 | 2011-07-11 09:51:44 -0500 | [diff] [blame] | 662 | * |
| 663 | * Dynamically allocate the transaction structure from the transaction |
| 664 | * zone, initialize it, and return it to the caller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | */ |
Alex Elder | b2ce397 | 2011-07-11 09:51:44 -0500 | [diff] [blame] | 666 | xfs_trans_t * |
| 667 | xfs_trans_alloc( |
| 668 | xfs_mount_t *mp, |
| 669 | uint type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 671 | xfs_trans_t *tp; |
| 672 | |
| 673 | sb_start_intwrite(mp->m_super); |
| 674 | tp = _xfs_trans_alloc(mp, type, KM_SLEEP); |
| 675 | tp->t_flags |= XFS_TRANS_FREEZE_PROT; |
| 676 | return tp; |
Alex Elder | b2ce397 | 2011-07-11 09:51:44 -0500 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | xfs_trans_t * |
| 680 | _xfs_trans_alloc( |
| 681 | xfs_mount_t *mp, |
| 682 | uint type, |
Al Viro | 77ba787 | 2012-04-02 06:24:04 -0400 | [diff] [blame] | 683 | xfs_km_flags_t memflags) |
Alex Elder | b2ce397 | 2011-07-11 09:51:44 -0500 | [diff] [blame] | 684 | { |
| 685 | xfs_trans_t *tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 687 | WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE); |
Nathan Scott | 34327e1 | 2006-06-09 17:11:55 +1000 | [diff] [blame] | 688 | atomic_inc(&mp->m_active_trans); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Christoph Hellwig | 80641dc | 2009-10-19 04:00:03 +0000 | [diff] [blame] | 690 | tp = kmem_zone_zalloc(xfs_trans_zone, memflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | tp->t_magic = XFS_TRANS_MAGIC; |
| 692 | tp->t_type = type; |
| 693 | tp->t_mountp = mp; |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 694 | INIT_LIST_HEAD(&tp->t_items); |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 695 | INIT_LIST_HEAD(&tp->t_busy); |
Nathan Scott | 34327e1 | 2006-06-09 17:11:55 +1000 | [diff] [blame] | 696 | return tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* |
Dave Chinner | b1c1b5b | 2010-03-23 10:11:05 +1100 | [diff] [blame] | 700 | * Free the transaction structure. If there is more clean up |
| 701 | * to do when the structure is freed, add it here. |
| 702 | */ |
| 703 | STATIC void |
| 704 | xfs_trans_free( |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 705 | struct xfs_trans *tp) |
Dave Chinner | b1c1b5b | 2010-03-23 10:11:05 +1100 | [diff] [blame] | 706 | { |
Dave Chinner | 4ecbfe6 | 2012-04-29 10:41:10 +0000 | [diff] [blame] | 707 | xfs_extent_busy_sort(&tp->t_busy); |
| 708 | xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 709 | |
Dave Chinner | b1c1b5b | 2010-03-23 10:11:05 +1100 | [diff] [blame] | 710 | atomic_dec(&tp->t_mountp->m_active_trans); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 711 | if (tp->t_flags & XFS_TRANS_FREEZE_PROT) |
| 712 | sb_end_intwrite(tp->t_mountp->m_super); |
Dave Chinner | b1c1b5b | 2010-03-23 10:11:05 +1100 | [diff] [blame] | 713 | xfs_trans_free_dqinfo(tp); |
| 714 | kmem_zone_free(xfs_trans_zone, tp); |
| 715 | } |
| 716 | |
| 717 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | * This is called to create a new transaction which will share the |
| 719 | * permanent log reservation of the given transaction. The remaining |
| 720 | * unused block and rt extent reservations are also inherited. This |
| 721 | * implies that the original transaction is no longer allowed to allocate |
| 722 | * blocks. Locks and log items, however, are no inherited. They must |
| 723 | * be added to the new transaction explicitly. |
| 724 | */ |
| 725 | xfs_trans_t * |
| 726 | xfs_trans_dup( |
| 727 | xfs_trans_t *tp) |
| 728 | { |
| 729 | xfs_trans_t *ntp; |
| 730 | |
| 731 | ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP); |
| 732 | |
| 733 | /* |
| 734 | * Initialize the new transaction structure. |
| 735 | */ |
| 736 | ntp->t_magic = XFS_TRANS_MAGIC; |
| 737 | ntp->t_type = tp->t_type; |
| 738 | ntp->t_mountp = tp->t_mountp; |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 739 | INIT_LIST_HEAD(&ntp->t_items); |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 740 | INIT_LIST_HEAD(&ntp->t_busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | ASSERT(tp->t_ticket != NULL); |
Nathan Scott | cfcbbbd | 2005-11-02 15:12:04 +1100 | [diff] [blame] | 744 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 745 | ntp->t_flags = XFS_TRANS_PERM_LOG_RES | |
| 746 | (tp->t_flags & XFS_TRANS_RESERVE) | |
| 747 | (tp->t_flags & XFS_TRANS_FREEZE_PROT); |
| 748 | /* We gave our writer reference to the new transaction */ |
| 749 | tp->t_flags &= ~XFS_TRANS_FREEZE_PROT; |
Dave Chinner | cc09c0d | 2008-11-17 17:37:10 +1100 | [diff] [blame] | 750 | ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used; |
| 752 | tp->t_blk_res = tp->t_blk_res_used; |
| 753 | ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used; |
| 754 | tp->t_rtx_res = tp->t_rtx_res_used; |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 755 | ntp->t_pflags = tp->t_pflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 757 | xfs_trans_dup_dqinfo(tp, ntp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | atomic_inc(&tp->t_mountp->m_active_trans); |
| 760 | return ntp; |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * This is called to reserve free disk blocks and log space for the |
| 765 | * given transaction. This must be done before allocating any resources |
| 766 | * within the transaction. |
| 767 | * |
| 768 | * This will return ENOSPC if there are not enough blocks available. |
| 769 | * It will sleep waiting for available log space. |
| 770 | * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which |
| 771 | * is used by long running transactions. If any one of the reservations |
| 772 | * fails then they will all be backed out. |
| 773 | * |
| 774 | * This does not do quota reservations. That typically is done by the |
| 775 | * caller afterwards. |
| 776 | */ |
| 777 | int |
| 778 | xfs_trans_reserve( |
| 779 | xfs_trans_t *tp, |
| 780 | uint blocks, |
| 781 | uint logspace, |
| 782 | uint rtextents, |
| 783 | uint flags, |
| 784 | uint logcount) |
| 785 | { |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 786 | int error = 0; |
| 787 | int rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | /* Mark this thread as being in a transaction */ |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 790 | current_set_flags_nested(&tp->t_pflags, PF_FSTRANS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | /* |
| 793 | * Attempt to reserve the needed disk blocks by decrementing |
| 794 | * the number needed from the number available. This will |
| 795 | * fail if the count would go below zero. |
| 796 | */ |
| 797 | if (blocks > 0) { |
Christoph Hellwig | 96540c7 | 2010-09-30 02:25:55 +0000 | [diff] [blame] | 798 | error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS, |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 799 | -((int64_t)blocks), rsvd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | if (error != 0) { |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 801 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return (XFS_ERROR(ENOSPC)); |
| 803 | } |
| 804 | tp->t_blk_res += blocks; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Reserve the log space needed for this transaction. |
| 809 | */ |
| 810 | if (logspace > 0) { |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 811 | bool permanent = false; |
| 812 | |
| 813 | ASSERT(tp->t_log_res == 0 || tp->t_log_res == logspace); |
| 814 | ASSERT(tp->t_log_count == 0 || tp->t_log_count == logcount); |
| 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if (flags & XFS_TRANS_PERM_LOG_RES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | tp->t_flags |= XFS_TRANS_PERM_LOG_RES; |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 818 | permanent = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } else { |
| 820 | ASSERT(tp->t_ticket == NULL); |
| 821 | ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 824 | if (tp->t_ticket != NULL) { |
| 825 | ASSERT(flags & XFS_TRANS_PERM_LOG_RES); |
| 826 | error = xfs_log_regrant(tp->t_mountp, tp->t_ticket); |
| 827 | } else { |
| 828 | error = xfs_log_reserve(tp->t_mountp, logspace, |
| 829 | logcount, &tp->t_ticket, |
| 830 | XFS_TRANSACTION, permanent, |
| 831 | tp->t_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 833 | |
| 834 | if (error) |
| 835 | goto undo_blocks; |
| 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | tp->t_log_res = logspace; |
| 838 | tp->t_log_count = logcount; |
| 839 | } |
| 840 | |
| 841 | /* |
| 842 | * Attempt to reserve the needed realtime extents by decrementing |
| 843 | * the number needed from the number available. This will |
| 844 | * fail if the count would go below zero. |
| 845 | */ |
| 846 | if (rtextents > 0) { |
| 847 | error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS, |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 848 | -((int64_t)rtextents), rsvd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | if (error) { |
| 850 | error = XFS_ERROR(ENOSPC); |
| 851 | goto undo_log; |
| 852 | } |
| 853 | tp->t_rtx_res += rtextents; |
| 854 | } |
| 855 | |
| 856 | return 0; |
| 857 | |
| 858 | /* |
| 859 | * Error cases jump to one of these labels to undo any |
| 860 | * reservations which have already been performed. |
| 861 | */ |
| 862 | undo_log: |
| 863 | if (logspace > 0) { |
Christoph Hellwig | 9006fb9 | 2012-02-20 02:31:31 +0000 | [diff] [blame] | 864 | int log_flags; |
| 865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | if (flags & XFS_TRANS_PERM_LOG_RES) { |
| 867 | log_flags = XFS_LOG_REL_PERM_RESERV; |
| 868 | } else { |
| 869 | log_flags = 0; |
| 870 | } |
| 871 | xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags); |
| 872 | tp->t_ticket = NULL; |
| 873 | tp->t_log_res = 0; |
| 874 | tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES; |
| 875 | } |
| 876 | |
| 877 | undo_blocks: |
| 878 | if (blocks > 0) { |
Christoph Hellwig | 96540c7 | 2010-09-30 02:25:55 +0000 | [diff] [blame] | 879 | xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS, |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 880 | (int64_t)blocks, rsvd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | tp->t_blk_res = 0; |
| 882 | } |
| 883 | |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 884 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 886 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | * Record the indicated change to the given field for application |
| 891 | * to the file system's superblock when the transaction commits. |
| 892 | * For now, just store the change in the transaction structure. |
| 893 | * |
| 894 | * Mark the transaction structure to indicate that the superblock |
| 895 | * needs to be updated before committing. |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 896 | * |
| 897 | * Because we may not be keeping track of allocated/free inodes and |
| 898 | * used filesystem blocks in the superblock, we do not mark the |
| 899 | * superblock dirty in this transaction if we modify these fields. |
| 900 | * We still need to update the transaction deltas so that they get |
| 901 | * applied to the incore superblock, but we don't want them to |
| 902 | * cause the superblock to get locked and logged if these are the |
| 903 | * only fields in the superblock that the transaction modifies. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | */ |
| 905 | void |
| 906 | xfs_trans_mod_sb( |
| 907 | xfs_trans_t *tp, |
| 908 | uint field, |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 909 | int64_t delta) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | { |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 911 | uint32_t flags = (XFS_TRANS_DIRTY|XFS_TRANS_SB_DIRTY); |
| 912 | xfs_mount_t *mp = tp->t_mountp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | switch (field) { |
| 915 | case XFS_TRANS_SB_ICOUNT: |
| 916 | tp->t_icount_delta += delta; |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 917 | if (xfs_sb_version_haslazysbcount(&mp->m_sb)) |
| 918 | flags &= ~XFS_TRANS_SB_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | break; |
| 920 | case XFS_TRANS_SB_IFREE: |
| 921 | tp->t_ifree_delta += delta; |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 922 | if (xfs_sb_version_haslazysbcount(&mp->m_sb)) |
| 923 | flags &= ~XFS_TRANS_SB_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | break; |
| 925 | case XFS_TRANS_SB_FDBLOCKS: |
| 926 | /* |
| 927 | * Track the number of blocks allocated in the |
| 928 | * transaction. Make sure it does not exceed the |
| 929 | * number reserved. |
| 930 | */ |
| 931 | if (delta < 0) { |
| 932 | tp->t_blk_res_used += (uint)-delta; |
| 933 | ASSERT(tp->t_blk_res_used <= tp->t_blk_res); |
| 934 | } |
| 935 | tp->t_fdblocks_delta += delta; |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 936 | if (xfs_sb_version_haslazysbcount(&mp->m_sb)) |
| 937 | flags &= ~XFS_TRANS_SB_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | break; |
| 939 | case XFS_TRANS_SB_RES_FDBLOCKS: |
| 940 | /* |
| 941 | * The allocation has already been applied to the |
| 942 | * in-core superblock's counter. This should only |
| 943 | * be applied to the on-disk superblock. |
| 944 | */ |
| 945 | ASSERT(delta < 0); |
| 946 | tp->t_res_fdblocks_delta += delta; |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 947 | if (xfs_sb_version_haslazysbcount(&mp->m_sb)) |
| 948 | flags &= ~XFS_TRANS_SB_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | break; |
| 950 | case XFS_TRANS_SB_FREXTENTS: |
| 951 | /* |
| 952 | * Track the number of blocks allocated in the |
| 953 | * transaction. Make sure it does not exceed the |
| 954 | * number reserved. |
| 955 | */ |
| 956 | if (delta < 0) { |
| 957 | tp->t_rtx_res_used += (uint)-delta; |
| 958 | ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res); |
| 959 | } |
| 960 | tp->t_frextents_delta += delta; |
| 961 | break; |
| 962 | case XFS_TRANS_SB_RES_FREXTENTS: |
| 963 | /* |
| 964 | * The allocation has already been applied to the |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 965 | * in-core superblock's counter. This should only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | * be applied to the on-disk superblock. |
| 967 | */ |
| 968 | ASSERT(delta < 0); |
| 969 | tp->t_res_frextents_delta += delta; |
| 970 | break; |
| 971 | case XFS_TRANS_SB_DBLOCKS: |
| 972 | ASSERT(delta > 0); |
| 973 | tp->t_dblocks_delta += delta; |
| 974 | break; |
| 975 | case XFS_TRANS_SB_AGCOUNT: |
| 976 | ASSERT(delta > 0); |
| 977 | tp->t_agcount_delta += delta; |
| 978 | break; |
| 979 | case XFS_TRANS_SB_IMAXPCT: |
| 980 | tp->t_imaxpct_delta += delta; |
| 981 | break; |
| 982 | case XFS_TRANS_SB_REXTSIZE: |
| 983 | tp->t_rextsize_delta += delta; |
| 984 | break; |
| 985 | case XFS_TRANS_SB_RBMBLOCKS: |
| 986 | tp->t_rbmblocks_delta += delta; |
| 987 | break; |
| 988 | case XFS_TRANS_SB_RBLOCKS: |
| 989 | tp->t_rblocks_delta += delta; |
| 990 | break; |
| 991 | case XFS_TRANS_SB_REXTENTS: |
| 992 | tp->t_rextents_delta += delta; |
| 993 | break; |
| 994 | case XFS_TRANS_SB_REXTSLOG: |
| 995 | tp->t_rextslog_delta += delta; |
| 996 | break; |
| 997 | default: |
| 998 | ASSERT(0); |
| 999 | return; |
| 1000 | } |
| 1001 | |
David Chinner | 210c6f1 | 2007-05-24 15:26:51 +1000 | [diff] [blame] | 1002 | tp->t_flags |= flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /* |
| 1006 | * xfs_trans_apply_sb_deltas() is called from the commit code |
| 1007 | * to bring the superblock buffer into the current transaction |
| 1008 | * and modify it as requested by earlier calls to xfs_trans_mod_sb(). |
| 1009 | * |
| 1010 | * For now we just look at each field allowed to change and change |
| 1011 | * it if necessary. |
| 1012 | */ |
| 1013 | STATIC void |
| 1014 | xfs_trans_apply_sb_deltas( |
| 1015 | xfs_trans_t *tp) |
| 1016 | { |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1017 | xfs_dsb_t *sbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | xfs_buf_t *bp; |
| 1019 | int whole = 0; |
| 1020 | |
| 1021 | bp = xfs_trans_getsb(tp, tp->t_mountp, 0); |
| 1022 | sbp = XFS_BUF_TO_SBP(bp); |
| 1023 | |
| 1024 | /* |
| 1025 | * Check that superblock mods match the mods made to AGF counters. |
| 1026 | */ |
| 1027 | ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) == |
| 1028 | (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta + |
| 1029 | tp->t_ag_btree_delta)); |
| 1030 | |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 1031 | /* |
| 1032 | * Only update the superblock counters if we are logging them |
| 1033 | */ |
| 1034 | if (!xfs_sb_version_haslazysbcount(&(tp->t_mountp->m_sb))) { |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1035 | if (tp->t_icount_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1036 | be64_add_cpu(&sbp->sb_icount, tp->t_icount_delta); |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1037 | if (tp->t_ifree_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1038 | be64_add_cpu(&sbp->sb_ifree, tp->t_ifree_delta); |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1039 | if (tp->t_fdblocks_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1040 | be64_add_cpu(&sbp->sb_fdblocks, tp->t_fdblocks_delta); |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1041 | if (tp->t_res_fdblocks_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1042 | be64_add_cpu(&sbp->sb_fdblocks, tp->t_res_fdblocks_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1045 | if (tp->t_frextents_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1046 | be64_add_cpu(&sbp->sb_frextents, tp->t_frextents_delta); |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1047 | if (tp->t_res_frextents_delta) |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1048 | be64_add_cpu(&sbp->sb_frextents, tp->t_res_frextents_delta); |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1049 | |
| 1050 | if (tp->t_dblocks_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1051 | be64_add_cpu(&sbp->sb_dblocks, tp->t_dblocks_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | whole = 1; |
| 1053 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1054 | if (tp->t_agcount_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1055 | be32_add_cpu(&sbp->sb_agcount, tp->t_agcount_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | whole = 1; |
| 1057 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1058 | if (tp->t_imaxpct_delta) { |
| 1059 | sbp->sb_imax_pct += tp->t_imaxpct_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | whole = 1; |
| 1061 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1062 | if (tp->t_rextsize_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1063 | be32_add_cpu(&sbp->sb_rextsize, tp->t_rextsize_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | whole = 1; |
| 1065 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1066 | if (tp->t_rbmblocks_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1067 | be32_add_cpu(&sbp->sb_rbmblocks, tp->t_rbmblocks_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | whole = 1; |
| 1069 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1070 | if (tp->t_rblocks_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1071 | be64_add_cpu(&sbp->sb_rblocks, tp->t_rblocks_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | whole = 1; |
| 1073 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1074 | if (tp->t_rextents_delta) { |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 1075 | be64_add_cpu(&sbp->sb_rextents, tp->t_rextents_delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | whole = 1; |
| 1077 | } |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1078 | if (tp->t_rextslog_delta) { |
| 1079 | sbp->sb_rextslog += tp->t_rextslog_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | whole = 1; |
| 1081 | } |
| 1082 | |
| 1083 | if (whole) |
| 1084 | /* |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1085 | * Log the whole thing, the fields are noncontiguous. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | */ |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1087 | xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_dsb_t) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | else |
| 1089 | /* |
| 1090 | * Since all the modifiable fields are contiguous, we |
| 1091 | * can get away with this. |
| 1092 | */ |
Christoph Hellwig | 2bdf7cd | 2007-08-28 13:58:06 +1000 | [diff] [blame] | 1093 | xfs_trans_log_buf(tp, bp, offsetof(xfs_dsb_t, sb_icount), |
| 1094 | offsetof(xfs_dsb_t, sb_frextents) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | sizeof(sbp->sb_frextents) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /* |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1099 | * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations |
| 1100 | * and apply superblock counter changes to the in-core superblock. The |
| 1101 | * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT |
| 1102 | * applied to the in-core superblock. The idea is that that has already been |
| 1103 | * done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | * |
| 1105 | * This is done efficiently with a single call to xfs_mod_incore_sb_batch(). |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1106 | * However, we have to ensure that we only modify each superblock field only |
| 1107 | * once because the application of the delta values may not be atomic. That can |
| 1108 | * lead to ENOSPC races occurring if we have two separate modifcations of the |
| 1109 | * free space counter to put back the entire reservation and then take away |
| 1110 | * what we used. |
| 1111 | * |
| 1112 | * If we are not logging superblock counters, then the inode allocated/free and |
| 1113 | * used block counts are not updated in the on disk superblock. In this case, |
| 1114 | * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we |
| 1115 | * still need to update the incore superblock with the changes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | */ |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 1117 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | xfs_trans_unreserve_and_mod_sb( |
| 1119 | xfs_trans_t *tp) |
| 1120 | { |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1121 | xfs_mod_sb_t msb[9]; /* If you add cases, add entries */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | xfs_mod_sb_t *msbp; |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 1123 | xfs_mount_t *mp = tp->t_mountp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | /* REFERENCED */ |
| 1125 | int error; |
| 1126 | int rsvd; |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1127 | int64_t blkdelta = 0; |
| 1128 | int64_t rtxdelta = 0; |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1129 | int64_t idelta = 0; |
| 1130 | int64_t ifreedelta = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
| 1132 | msbp = msb; |
| 1133 | rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; |
| 1134 | |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1135 | /* calculate deltas */ |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1136 | if (tp->t_blk_res > 0) |
| 1137 | blkdelta = tp->t_blk_res; |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1138 | if ((tp->t_fdblocks_delta != 0) && |
| 1139 | (xfs_sb_version_haslazysbcount(&mp->m_sb) || |
| 1140 | (tp->t_flags & XFS_TRANS_SB_DIRTY))) |
| 1141 | blkdelta += tp->t_fdblocks_delta; |
| 1142 | |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1143 | if (tp->t_rtx_res > 0) |
| 1144 | rtxdelta = tp->t_rtx_res; |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1145 | if ((tp->t_frextents_delta != 0) && |
| 1146 | (tp->t_flags & XFS_TRANS_SB_DIRTY)) |
| 1147 | rtxdelta += tp->t_frextents_delta; |
| 1148 | |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1149 | if (xfs_sb_version_haslazysbcount(&mp->m_sb) || |
| 1150 | (tp->t_flags & XFS_TRANS_SB_DIRTY)) { |
| 1151 | idelta = tp->t_icount_delta; |
| 1152 | ifreedelta = tp->t_ifree_delta; |
| 1153 | } |
| 1154 | |
| 1155 | /* apply the per-cpu counters */ |
| 1156 | if (blkdelta) { |
| 1157 | error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, |
| 1158 | blkdelta, rsvd); |
| 1159 | if (error) |
| 1160 | goto out; |
| 1161 | } |
| 1162 | |
| 1163 | if (idelta) { |
| 1164 | error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, |
| 1165 | idelta, rsvd); |
| 1166 | if (error) |
| 1167 | goto out_undo_fdblocks; |
| 1168 | } |
| 1169 | |
| 1170 | if (ifreedelta) { |
| 1171 | error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, |
| 1172 | ifreedelta, rsvd); |
| 1173 | if (error) |
| 1174 | goto out_undo_icount; |
| 1175 | } |
| 1176 | |
| 1177 | /* apply remaining deltas */ |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1178 | if (rtxdelta != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | msbp->msb_field = XFS_SBS_FREXTENTS; |
David Chinner | 45c3414 | 2007-06-18 16:49:44 +1000 | [diff] [blame] | 1180 | msbp->msb_delta = rtxdelta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | msbp++; |
| 1182 | } |
| 1183 | |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 1184 | if (tp->t_flags & XFS_TRANS_SB_DIRTY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | if (tp->t_dblocks_delta != 0) { |
| 1186 | msbp->msb_field = XFS_SBS_DBLOCKS; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1187 | msbp->msb_delta = tp->t_dblocks_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | msbp++; |
| 1189 | } |
| 1190 | if (tp->t_agcount_delta != 0) { |
| 1191 | msbp->msb_field = XFS_SBS_AGCOUNT; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1192 | msbp->msb_delta = tp->t_agcount_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | msbp++; |
| 1194 | } |
| 1195 | if (tp->t_imaxpct_delta != 0) { |
| 1196 | msbp->msb_field = XFS_SBS_IMAX_PCT; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1197 | msbp->msb_delta = tp->t_imaxpct_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | msbp++; |
| 1199 | } |
| 1200 | if (tp->t_rextsize_delta != 0) { |
| 1201 | msbp->msb_field = XFS_SBS_REXTSIZE; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1202 | msbp->msb_delta = tp->t_rextsize_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | msbp++; |
| 1204 | } |
| 1205 | if (tp->t_rbmblocks_delta != 0) { |
| 1206 | msbp->msb_field = XFS_SBS_RBMBLOCKS; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1207 | msbp->msb_delta = tp->t_rbmblocks_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | msbp++; |
| 1209 | } |
| 1210 | if (tp->t_rblocks_delta != 0) { |
| 1211 | msbp->msb_field = XFS_SBS_RBLOCKS; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1212 | msbp->msb_delta = tp->t_rblocks_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | msbp++; |
| 1214 | } |
| 1215 | if (tp->t_rextents_delta != 0) { |
| 1216 | msbp->msb_field = XFS_SBS_REXTENTS; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1217 | msbp->msb_delta = tp->t_rextents_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | msbp++; |
| 1219 | } |
| 1220 | if (tp->t_rextslog_delta != 0) { |
| 1221 | msbp->msb_field = XFS_SBS_REXTSLOG; |
David Chinner | 20f4ebf | 2007-02-10 18:36:10 +1100 | [diff] [blame] | 1222 | msbp->msb_delta = tp->t_rextslog_delta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | msbp++; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | /* |
| 1228 | * If we need to change anything, do it. |
| 1229 | */ |
| 1230 | if (msbp > msb) { |
| 1231 | error = xfs_mod_incore_sb_batch(tp->t_mountp, msb, |
| 1232 | (uint)(msbp - msb), rsvd); |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1233 | if (error) |
| 1234 | goto out_undo_ifreecount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1236 | |
| 1237 | return; |
| 1238 | |
| 1239 | out_undo_ifreecount: |
| 1240 | if (ifreedelta) |
| 1241 | xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd); |
| 1242 | out_undo_icount: |
| 1243 | if (idelta) |
| 1244 | xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd); |
| 1245 | out_undo_fdblocks: |
| 1246 | if (blkdelta) |
| 1247 | xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd); |
| 1248 | out: |
Jesper Juhl | 1884bd8 | 2010-12-25 20:14:53 +0000 | [diff] [blame] | 1249 | ASSERT(error == 0); |
Christoph Hellwig | 1b04071 | 2010-09-30 02:25:56 +0000 | [diff] [blame] | 1250 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1253 | /* |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1254 | * Add the given log item to the transaction's list of log items. |
| 1255 | * |
| 1256 | * The log item will now point to its new descriptor with its li_desc field. |
| 1257 | */ |
| 1258 | void |
| 1259 | xfs_trans_add_item( |
| 1260 | struct xfs_trans *tp, |
| 1261 | struct xfs_log_item *lip) |
| 1262 | { |
| 1263 | struct xfs_log_item_desc *lidp; |
| 1264 | |
Jesper Juhl | f65020a | 2012-02-13 20:51:05 +0000 | [diff] [blame] | 1265 | ASSERT(lip->li_mountp == tp->t_mountp); |
| 1266 | ASSERT(lip->li_ailp == tp->t_mountp->m_ail); |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1267 | |
Dave Chinner | 4386970 | 2010-07-20 17:53:44 +1000 | [diff] [blame] | 1268 | lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS); |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1269 | |
| 1270 | lidp->lid_item = lip; |
| 1271 | lidp->lid_flags = 0; |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1272 | list_add_tail(&lidp->lid_trans, &tp->t_items); |
| 1273 | |
| 1274 | lip->li_desc = lidp; |
| 1275 | } |
| 1276 | |
| 1277 | STATIC void |
| 1278 | xfs_trans_free_item_desc( |
| 1279 | struct xfs_log_item_desc *lidp) |
| 1280 | { |
| 1281 | list_del_init(&lidp->lid_trans); |
| 1282 | kmem_zone_free(xfs_log_item_desc_zone, lidp); |
| 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | * Unlink and free the given descriptor. |
| 1287 | */ |
| 1288 | void |
| 1289 | xfs_trans_del_item( |
| 1290 | struct xfs_log_item *lip) |
| 1291 | { |
| 1292 | xfs_trans_free_item_desc(lip->li_desc); |
| 1293 | lip->li_desc = NULL; |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * Unlock all of the items of a transaction and free all the descriptors |
| 1298 | * of that transaction. |
| 1299 | */ |
Dave Chinner | d17c701 | 2010-08-24 11:42:52 +1000 | [diff] [blame] | 1300 | void |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1301 | xfs_trans_free_items( |
| 1302 | struct xfs_trans *tp, |
| 1303 | xfs_lsn_t commit_lsn, |
| 1304 | int flags) |
| 1305 | { |
| 1306 | struct xfs_log_item_desc *lidp, *next; |
| 1307 | |
| 1308 | list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) { |
| 1309 | struct xfs_log_item *lip = lidp->lid_item; |
| 1310 | |
| 1311 | lip->li_desc = NULL; |
| 1312 | |
| 1313 | if (commit_lsn != NULLCOMMITLSN) |
| 1314 | IOP_COMMITTING(lip, commit_lsn); |
| 1315 | if (flags & XFS_TRANS_ABORT) |
| 1316 | lip->li_flags |= XFS_LI_ABORTED; |
| 1317 | IOP_UNLOCK(lip); |
| 1318 | |
| 1319 | xfs_trans_free_item_desc(lidp); |
| 1320 | } |
| 1321 | } |
| 1322 | |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1323 | static inline void |
| 1324 | xfs_log_item_batch_insert( |
| 1325 | struct xfs_ail *ailp, |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1326 | struct xfs_ail_cursor *cur, |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1327 | struct xfs_log_item **log_items, |
| 1328 | int nr_items, |
| 1329 | xfs_lsn_t commit_lsn) |
| 1330 | { |
| 1331 | int i; |
| 1332 | |
| 1333 | spin_lock(&ailp->xa_lock); |
| 1334 | /* xfs_trans_ail_update_bulk drops ailp->xa_lock */ |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1335 | xfs_trans_ail_update_bulk(ailp, cur, log_items, nr_items, commit_lsn); |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1336 | |
| 1337 | for (i = 0; i < nr_items; i++) |
| 1338 | IOP_UNPIN(log_items[i], 0); |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * Bulk operation version of xfs_trans_committed that takes a log vector of |
| 1343 | * items to insert into the AIL. This uses bulk AIL insertion techniques to |
| 1344 | * minimise lock traffic. |
Dave Chinner | e34a314 | 2011-01-27 12:13:35 +1100 | [diff] [blame] | 1345 | * |
| 1346 | * If we are called with the aborted flag set, it is because a log write during |
| 1347 | * a CIL checkpoint commit has failed. In this case, all the items in the |
| 1348 | * checkpoint have already gone through IOP_COMMITED and IOP_UNLOCK, which |
| 1349 | * means that checkpoint commit abort handling is treated exactly the same |
| 1350 | * as an iclog write error even though we haven't started any IO yet. Hence in |
| 1351 | * this case all we need to do is IOP_COMMITTED processing, followed by an |
| 1352 | * IOP_UNPIN(aborted) call. |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1353 | * |
| 1354 | * The AIL cursor is used to optimise the insert process. If commit_lsn is not |
| 1355 | * at the end of the AIL, the insert cursor avoids the need to walk |
| 1356 | * the AIL to find the insertion point on every xfs_log_item_batch_insert() |
| 1357 | * call. This saves a lot of needless list walking and is a net win, even |
| 1358 | * though it slightly increases that amount of AIL lock traffic to set it up |
| 1359 | * and tear it down. |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1360 | */ |
| 1361 | void |
| 1362 | xfs_trans_committed_bulk( |
| 1363 | struct xfs_ail *ailp, |
| 1364 | struct xfs_log_vec *log_vector, |
| 1365 | xfs_lsn_t commit_lsn, |
| 1366 | int aborted) |
| 1367 | { |
| 1368 | #define LOG_ITEM_BATCH_SIZE 32 |
| 1369 | struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE]; |
| 1370 | struct xfs_log_vec *lv; |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1371 | struct xfs_ail_cursor cur; |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1372 | int i = 0; |
| 1373 | |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1374 | spin_lock(&ailp->xa_lock); |
| 1375 | xfs_trans_ail_cursor_last(ailp, &cur, commit_lsn); |
| 1376 | spin_unlock(&ailp->xa_lock); |
| 1377 | |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1378 | /* unpin all the log items */ |
| 1379 | for (lv = log_vector; lv; lv = lv->lv_next ) { |
| 1380 | struct xfs_log_item *lip = lv->lv_item; |
| 1381 | xfs_lsn_t item_lsn; |
| 1382 | |
| 1383 | if (aborted) |
| 1384 | lip->li_flags |= XFS_LI_ABORTED; |
| 1385 | item_lsn = IOP_COMMITTED(lip, commit_lsn); |
| 1386 | |
Dave Chinner | 1316d4d | 2011-07-04 05:27:36 +0000 | [diff] [blame] | 1387 | /* item_lsn of -1 means the item needs no further processing */ |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1388 | if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0) |
| 1389 | continue; |
| 1390 | |
Dave Chinner | e34a314 | 2011-01-27 12:13:35 +1100 | [diff] [blame] | 1391 | /* |
| 1392 | * if we are aborting the operation, no point in inserting the |
| 1393 | * object into the AIL as we are in a shutdown situation. |
| 1394 | */ |
| 1395 | if (aborted) { |
| 1396 | ASSERT(XFS_FORCED_SHUTDOWN(ailp->xa_mount)); |
| 1397 | IOP_UNPIN(lip, 1); |
| 1398 | continue; |
| 1399 | } |
| 1400 | |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1401 | if (item_lsn != commit_lsn) { |
| 1402 | |
| 1403 | /* |
| 1404 | * Not a bulk update option due to unusual item_lsn. |
| 1405 | * Push into AIL immediately, rechecking the lsn once |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1406 | * we have the ail lock. Then unpin the item. This does |
| 1407 | * not affect the AIL cursor the bulk insert path is |
| 1408 | * using. |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1409 | */ |
| 1410 | spin_lock(&ailp->xa_lock); |
| 1411 | if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0) |
| 1412 | xfs_trans_ail_update(ailp, lip, item_lsn); |
| 1413 | else |
| 1414 | spin_unlock(&ailp->xa_lock); |
| 1415 | IOP_UNPIN(lip, 0); |
| 1416 | continue; |
| 1417 | } |
| 1418 | |
| 1419 | /* Item is a candidate for bulk AIL insert. */ |
| 1420 | log_items[i++] = lv->lv_item; |
| 1421 | if (i >= LOG_ITEM_BATCH_SIZE) { |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1422 | xfs_log_item_batch_insert(ailp, &cur, log_items, |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1423 | LOG_ITEM_BATCH_SIZE, commit_lsn); |
| 1424 | i = 0; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | /* make sure we insert the remainder! */ |
| 1429 | if (i) |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 1430 | xfs_log_item_batch_insert(ailp, &cur, log_items, i, commit_lsn); |
| 1431 | |
| 1432 | spin_lock(&ailp->xa_lock); |
| 1433 | xfs_trans_ail_cursor_done(ailp, &cur); |
| 1434 | spin_unlock(&ailp->xa_lock); |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 1435 | } |
| 1436 | |
Dave Chinner | b1c1b5b | 2010-03-23 10:11:05 +1100 | [diff] [blame] | 1437 | /* |
Christoph Hellwig | b103705 | 2011-09-19 14:55:51 +0000 | [diff] [blame] | 1438 | * Commit the given transaction to the log. |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1439 | * |
| 1440 | * XFS disk error handling mechanism is not based on a typical |
| 1441 | * transaction abort mechanism. Logically after the filesystem |
| 1442 | * gets marked 'SHUTDOWN', we can't let any new transactions |
| 1443 | * be durable - ie. committed to disk - because some metadata might |
| 1444 | * be inconsistent. In such cases, this returns an error, and the |
| 1445 | * caller may assume that all locked objects joined to the transaction |
| 1446 | * have already been unlocked as if the commit had succeeded. |
| 1447 | * Do not reference the transaction structure after this call. |
| 1448 | */ |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1449 | int |
Christoph Hellwig | b103705 | 2011-09-19 14:55:51 +0000 | [diff] [blame] | 1450 | xfs_trans_commit( |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1451 | struct xfs_trans *tp, |
Christoph Hellwig | b103705 | 2011-09-19 14:55:51 +0000 | [diff] [blame] | 1452 | uint flags) |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1453 | { |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1454 | struct xfs_mount *mp = tp->t_mountp; |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1455 | xfs_lsn_t commit_lsn = -1; |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1456 | int error = 0; |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1457 | int log_flags = 0; |
| 1458 | int sync = tp->t_flags & XFS_TRANS_SYNC; |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1459 | |
| 1460 | /* |
| 1461 | * Determine whether this commit is releasing a permanent |
| 1462 | * log reservation or not. |
| 1463 | */ |
| 1464 | if (flags & XFS_TRANS_RELEASE_LOG_RES) { |
| 1465 | ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); |
| 1466 | log_flags = XFS_LOG_REL_PERM_RESERV; |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * If there is nothing to be logged by the transaction, |
| 1471 | * then unlock all of the items associated with the |
| 1472 | * transaction and free the transaction structure. |
| 1473 | * Also make sure to return any reserved blocks to |
| 1474 | * the free pool. |
| 1475 | */ |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1476 | if (!(tp->t_flags & XFS_TRANS_DIRTY)) |
| 1477 | goto out_unreserve; |
| 1478 | |
| 1479 | if (XFS_FORCED_SHUTDOWN(mp)) { |
| 1480 | error = XFS_ERROR(EIO); |
| 1481 | goto out_unreserve; |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1482 | } |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1483 | |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1484 | ASSERT(tp->t_ticket != NULL); |
| 1485 | |
| 1486 | /* |
| 1487 | * If we need to update the superblock, then do it now. |
| 1488 | */ |
| 1489 | if (tp->t_flags & XFS_TRANS_SB_DIRTY) |
| 1490 | xfs_trans_apply_sb_deltas(tp); |
| 1491 | xfs_trans_apply_dquot_deltas(tp); |
| 1492 | |
Christoph Hellwig | 0244b96 | 2011-12-06 21:58:08 +0000 | [diff] [blame] | 1493 | error = xfs_log_commit_cil(mp, tp, &commit_lsn, flags); |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1494 | if (error == ENOMEM) { |
| 1495 | xfs_force_shutdown(mp, SHUTDOWN_LOG_IO_ERROR); |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1496 | error = XFS_ERROR(EIO); |
| 1497 | goto out_unreserve; |
Dave Chinner | 0924378 | 2010-03-08 11:28:28 +1100 | [diff] [blame] | 1498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
Christoph Hellwig | 0244b96 | 2011-12-06 21:58:08 +0000 | [diff] [blame] | 1500 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
| 1501 | xfs_trans_free(tp); |
| 1502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | /* |
| 1504 | * If the transaction needs to be synchronous, then force the |
| 1505 | * log out now and wait for it. |
| 1506 | */ |
| 1507 | if (sync) { |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 1508 | if (!error) { |
Christoph Hellwig | a14a348 | 2010-01-19 09:56:46 +0000 | [diff] [blame] | 1509 | error = _xfs_log_force_lsn(mp, commit_lsn, |
Christoph Hellwig | b103705 | 2011-09-19 14:55:51 +0000 | [diff] [blame] | 1510 | XFS_LOG_SYNC, NULL); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 1511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | XFS_STATS_INC(xs_trans_sync); |
| 1513 | } else { |
| 1514 | XFS_STATS_INC(xs_trans_async); |
| 1515 | } |
| 1516 | |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1517 | return error; |
| 1518 | |
| 1519 | out_unreserve: |
| 1520 | xfs_trans_unreserve_and_mod_sb(tp); |
| 1521 | |
| 1522 | /* |
| 1523 | * It is indeed possible for the transaction to be not dirty but |
| 1524 | * the dqinfo portion to be. All that means is that we have some |
| 1525 | * (non-persistent) quota reservations that need to be unreserved. |
| 1526 | */ |
| 1527 | xfs_trans_unreserve_and_mod_dquots(tp); |
| 1528 | if (tp->t_ticket) { |
| 1529 | commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, log_flags); |
| 1530 | if (commit_lsn == -1 && !error) |
| 1531 | error = XFS_ERROR(EIO); |
| 1532 | } |
| 1533 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 1534 | xfs_trans_free_items(tp, NULLCOMMITLSN, error ? XFS_TRANS_ABORT : 0); |
Christoph Hellwig | a3ccd2c | 2010-03-15 12:52:49 +1100 | [diff] [blame] | 1535 | xfs_trans_free(tp); |
| 1536 | |
| 1537 | XFS_STATS_INC(xs_trans_empty); |
| 1538 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | * Unlock all of the transaction's items and free the transaction. |
| 1543 | * The transaction must not have modified any of its items, because |
| 1544 | * there is no way to restore them to their previous state. |
| 1545 | * |
| 1546 | * If the transaction has made a log reservation, make sure to release |
| 1547 | * it as well. |
| 1548 | */ |
| 1549 | void |
| 1550 | xfs_trans_cancel( |
| 1551 | xfs_trans_t *tp, |
| 1552 | int flags) |
| 1553 | { |
| 1554 | int log_flags; |
Ryan Hankins | 0733af2 | 2006-01-11 15:36:44 +1100 | [diff] [blame] | 1555 | xfs_mount_t *mp = tp->t_mountp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
| 1557 | /* |
| 1558 | * See if the caller is being too lazy to figure out if |
| 1559 | * the transaction really needs an abort. |
| 1560 | */ |
| 1561 | if ((flags & XFS_TRANS_ABORT) && !(tp->t_flags & XFS_TRANS_DIRTY)) |
| 1562 | flags &= ~XFS_TRANS_ABORT; |
| 1563 | /* |
| 1564 | * See if the caller is relying on us to shut down the |
| 1565 | * filesystem. This happens in paths where we detect |
| 1566 | * corruption and decide to give up. |
| 1567 | */ |
Nathan Scott | 60a204f | 2006-01-11 15:37:00 +1100 | [diff] [blame] | 1568 | if ((tp->t_flags & XFS_TRANS_DIRTY) && !XFS_FORCED_SHUTDOWN(mp)) { |
Ryan Hankins | 0733af2 | 2006-01-11 15:36:44 +1100 | [diff] [blame] | 1569 | XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp); |
Nathan Scott | 7d04a33 | 2006-06-09 14:58:38 +1000 | [diff] [blame] | 1570 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
Nathan Scott | 60a204f | 2006-01-11 15:37:00 +1100 | [diff] [blame] | 1571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | #ifdef DEBUG |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1573 | if (!(flags & XFS_TRANS_ABORT) && !XFS_FORCED_SHUTDOWN(mp)) { |
| 1574 | struct xfs_log_item_desc *lidp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1576 | list_for_each_entry(lidp, &tp->t_items, lid_trans) |
| 1577 | ASSERT(!(lidp->lid_item->li_type == XFS_LI_EFD)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | } |
| 1579 | #endif |
| 1580 | xfs_trans_unreserve_and_mod_sb(tp); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1581 | xfs_trans_unreserve_and_mod_dquots(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
| 1583 | if (tp->t_ticket) { |
| 1584 | if (flags & XFS_TRANS_RELEASE_LOG_RES) { |
| 1585 | ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); |
| 1586 | log_flags = XFS_LOG_REL_PERM_RESERV; |
| 1587 | } else { |
| 1588 | log_flags = 0; |
| 1589 | } |
Ryan Hankins | 0733af2 | 2006-01-11 15:36:44 +1100 | [diff] [blame] | 1590 | xfs_log_done(mp, tp->t_ticket, NULL, log_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /* mark this thread as no longer being in a transaction */ |
Nathan Scott | 59c1b08 | 2006-06-09 14:59:13 +1000 | [diff] [blame] | 1594 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 1596 | xfs_trans_free_items(tp, NULLCOMMITLSN, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | xfs_trans_free(tp); |
| 1598 | } |
| 1599 | |
Niv Sardi | 322ff6b | 2008-08-13 16:05:49 +1000 | [diff] [blame] | 1600 | /* |
| 1601 | * Roll from one trans in the sequence of PERMANENT transactions to |
| 1602 | * the next: permanent transactions are only flushed out when |
| 1603 | * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon |
| 1604 | * as possible to let chunks of it go to the log. So we commit the |
| 1605 | * chunk we've been working on and get a new transaction to continue. |
| 1606 | */ |
| 1607 | int |
| 1608 | xfs_trans_roll( |
| 1609 | struct xfs_trans **tpp, |
| 1610 | struct xfs_inode *dp) |
| 1611 | { |
| 1612 | struct xfs_trans *trans; |
| 1613 | unsigned int logres, count; |
| 1614 | int error; |
| 1615 | |
| 1616 | /* |
| 1617 | * Ensure that the inode is always logged. |
| 1618 | */ |
| 1619 | trans = *tpp; |
| 1620 | xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE); |
| 1621 | |
| 1622 | /* |
| 1623 | * Copy the critical parameters from one trans to the next. |
| 1624 | */ |
| 1625 | logres = trans->t_log_res; |
| 1626 | count = trans->t_log_count; |
| 1627 | *tpp = xfs_trans_dup(trans); |
| 1628 | |
| 1629 | /* |
| 1630 | * Commit the current transaction. |
| 1631 | * If this commit failed, then it'd just unlock those items that |
| 1632 | * are not marked ihold. That also means that a filesystem shutdown |
| 1633 | * is in progress. The caller takes the responsibility to cancel |
| 1634 | * the duplicate transaction that gets returned. |
| 1635 | */ |
| 1636 | error = xfs_trans_commit(trans, 0); |
| 1637 | if (error) |
| 1638 | return (error); |
| 1639 | |
| 1640 | trans = *tpp; |
| 1641 | |
| 1642 | /* |
Dave Chinner | cc09c0d | 2008-11-17 17:37:10 +1100 | [diff] [blame] | 1643 | * transaction commit worked ok so we can drop the extra ticket |
| 1644 | * reference that we gained in xfs_trans_dup() |
| 1645 | */ |
| 1646 | xfs_log_ticket_put(trans->t_ticket); |
| 1647 | |
| 1648 | |
| 1649 | /* |
Niv Sardi | 322ff6b | 2008-08-13 16:05:49 +1000 | [diff] [blame] | 1650 | * Reserve space in the log for th next transaction. |
| 1651 | * This also pushes items in the "AIL", the list of logged items, |
| 1652 | * out to disk if they are taking up space at the tail of the log |
| 1653 | * that we want to use. This requires that either nothing be locked |
| 1654 | * across this call, or that anything that is locked be logged in |
| 1655 | * the prior and the next transactions. |
| 1656 | */ |
| 1657 | error = xfs_trans_reserve(trans, 0, logres, 0, |
| 1658 | XFS_TRANS_PERM_LOG_RES, count); |
| 1659 | /* |
| 1660 | * Ensure that the inode is in the new transaction and locked. |
| 1661 | */ |
| 1662 | if (error) |
| 1663 | return error; |
| 1664 | |
Christoph Hellwig | ddc3415 | 2011-09-19 15:00:54 +0000 | [diff] [blame] | 1665 | xfs_trans_ijoin(trans, dp, 0); |
Niv Sardi | 322ff6b | 2008-08-13 16:05:49 +1000 | [diff] [blame] | 1666 | return 0; |
| 1667 | } |