David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | #include "xfs.h" |
| 19 | #include "xfs_fs.h" |
| 20 | #include "xfs_types.h" |
| 21 | #include "xfs_bit.h" |
| 22 | #include "xfs_log.h" |
| 23 | #include "xfs_inum.h" |
| 24 | #include "xfs_trans.h" |
| 25 | #include "xfs_sb.h" |
| 26 | #include "xfs_ag.h" |
| 27 | #include "xfs_dir2.h" |
| 28 | #include "xfs_dmapi.h" |
| 29 | #include "xfs_mount.h" |
| 30 | #include "xfs_bmap_btree.h" |
| 31 | #include "xfs_alloc_btree.h" |
| 32 | #include "xfs_ialloc_btree.h" |
| 33 | #include "xfs_btree.h" |
| 34 | #include "xfs_dir2_sf.h" |
| 35 | #include "xfs_attr_sf.h" |
| 36 | #include "xfs_inode.h" |
| 37 | #include "xfs_dinode.h" |
| 38 | #include "xfs_error.h" |
| 39 | #include "xfs_mru_cache.h" |
| 40 | #include "xfs_filestream.h" |
| 41 | #include "xfs_vnodeops.h" |
| 42 | #include "xfs_utils.h" |
| 43 | #include "xfs_buf_item.h" |
| 44 | #include "xfs_inode_item.h" |
| 45 | #include "xfs_rw.h" |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 46 | #include "xfs_quota.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 47 | #include "xfs_trace.h" |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 48 | |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 49 | #include <linux/kthread.h> |
| 50 | #include <linux/freezer.h> |
| 51 | |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 52 | |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 53 | STATIC xfs_inode_t * |
| 54 | xfs_inode_ag_lookup( |
| 55 | struct xfs_mount *mp, |
| 56 | struct xfs_perag *pag, |
| 57 | uint32_t *first_index, |
| 58 | int tag) |
| 59 | { |
| 60 | int nr_found; |
| 61 | struct xfs_inode *ip; |
| 62 | |
| 63 | /* |
| 64 | * use a gang lookup to find the next inode in the tree |
| 65 | * as the tree is sparse and a gang lookup walks to find |
| 66 | * the number of objects requested. |
| 67 | */ |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 68 | if (tag == XFS_ICI_NO_TAG) { |
| 69 | nr_found = radix_tree_gang_lookup(&pag->pag_ici_root, |
| 70 | (void **)&ip, *first_index, 1); |
| 71 | } else { |
| 72 | nr_found = radix_tree_gang_lookup_tag(&pag->pag_ici_root, |
| 73 | (void **)&ip, *first_index, 1, tag); |
| 74 | } |
| 75 | if (!nr_found) |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 76 | return NULL; |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Update the index for the next lookup. Catch overflows |
| 80 | * into the next AG range which can occur if we have inodes |
| 81 | * in the last block of the AG and we are currently |
| 82 | * pointing to the last inode. |
| 83 | */ |
| 84 | *first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1); |
| 85 | if (*first_index < XFS_INO_TO_AGINO(mp, ip->i_ino)) |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 86 | return NULL; |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 87 | return ip; |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | STATIC int |
| 91 | xfs_inode_ag_walk( |
| 92 | struct xfs_mount *mp, |
| 93 | xfs_agnumber_t ag, |
| 94 | int (*execute)(struct xfs_inode *ip, |
| 95 | struct xfs_perag *pag, int flags), |
| 96 | int flags, |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 97 | int tag, |
| 98 | int exclusive) |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 99 | { |
| 100 | struct xfs_perag *pag = &mp->m_perag[ag]; |
| 101 | uint32_t first_index; |
| 102 | int last_error = 0; |
| 103 | int skipped; |
| 104 | |
| 105 | restart: |
| 106 | skipped = 0; |
| 107 | first_index = 0; |
| 108 | do { |
| 109 | int error = 0; |
| 110 | xfs_inode_t *ip; |
| 111 | |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 112 | if (exclusive) |
| 113 | write_lock(&pag->pag_ici_lock); |
| 114 | else |
| 115 | read_lock(&pag->pag_ici_lock); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 116 | ip = xfs_inode_ag_lookup(mp, pag, &first_index, tag); |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 117 | if (!ip) { |
| 118 | if (exclusive) |
| 119 | write_unlock(&pag->pag_ici_lock); |
| 120 | else |
| 121 | read_unlock(&pag->pag_ici_lock); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 122 | break; |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 123 | } |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 124 | |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 125 | /* execute releases pag->pag_ici_lock */ |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 126 | error = execute(ip, pag, flags); |
| 127 | if (error == EAGAIN) { |
| 128 | skipped++; |
| 129 | continue; |
| 130 | } |
| 131 | if (error) |
| 132 | last_error = error; |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 133 | |
| 134 | /* bail out if the filesystem is corrupted. */ |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 135 | if (error == EFSCORRUPTED) |
| 136 | break; |
| 137 | |
| 138 | } while (1); |
| 139 | |
| 140 | if (skipped) { |
| 141 | delay(1); |
| 142 | goto restart; |
| 143 | } |
| 144 | |
| 145 | xfs_put_perag(mp, pag); |
| 146 | return last_error; |
| 147 | } |
| 148 | |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 149 | int |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 150 | xfs_inode_ag_iterator( |
| 151 | struct xfs_mount *mp, |
| 152 | int (*execute)(struct xfs_inode *ip, |
| 153 | struct xfs_perag *pag, int flags), |
| 154 | int flags, |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 155 | int tag, |
| 156 | int exclusive) |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 157 | { |
| 158 | int error = 0; |
| 159 | int last_error = 0; |
| 160 | xfs_agnumber_t ag; |
| 161 | |
| 162 | for (ag = 0; ag < mp->m_sb.sb_agcount; ag++) { |
| 163 | if (!mp->m_perag[ag].pag_ici_init) |
| 164 | continue; |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 165 | error = xfs_inode_ag_walk(mp, ag, execute, flags, tag, |
| 166 | exclusive); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 167 | if (error) { |
| 168 | last_error = error; |
| 169 | if (error == EFSCORRUPTED) |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | return XFS_ERROR(last_error); |
| 174 | } |
| 175 | |
Dave Chinner | 1da8eec | 2009-06-08 15:35:07 +0200 | [diff] [blame] | 176 | /* must be called with pag_ici_lock held and releases it */ |
Christoph Hellwig | fe588ed | 2009-06-08 15:35:27 +0200 | [diff] [blame] | 177 | int |
Dave Chinner | 1da8eec | 2009-06-08 15:35:07 +0200 | [diff] [blame] | 178 | xfs_sync_inode_valid( |
| 179 | struct xfs_inode *ip, |
| 180 | struct xfs_perag *pag) |
| 181 | { |
| 182 | struct inode *inode = VFS_I(ip); |
| 183 | |
| 184 | /* nothing to sync during shutdown */ |
| 185 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
| 186 | read_unlock(&pag->pag_ici_lock); |
| 187 | return EFSCORRUPTED; |
| 188 | } |
| 189 | |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 190 | /* If we can't get a reference on the inode, it must be in reclaim. */ |
Dave Chinner | 1da8eec | 2009-06-08 15:35:07 +0200 | [diff] [blame] | 191 | if (!igrab(inode)) { |
| 192 | read_unlock(&pag->pag_ici_lock); |
| 193 | return ENOENT; |
| 194 | } |
| 195 | read_unlock(&pag->pag_ici_lock); |
| 196 | |
| 197 | if (is_bad_inode(inode) || xfs_iflags_test(ip, XFS_INEW)) { |
| 198 | IRELE(ip); |
| 199 | return ENOENT; |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 205 | STATIC int |
| 206 | xfs_sync_inode_data( |
| 207 | struct xfs_inode *ip, |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 208 | struct xfs_perag *pag, |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 209 | int flags) |
| 210 | { |
| 211 | struct inode *inode = VFS_I(ip); |
| 212 | struct address_space *mapping = inode->i_mapping; |
| 213 | int error = 0; |
| 214 | |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 215 | error = xfs_sync_inode_valid(ip, pag); |
| 216 | if (error) |
| 217 | return error; |
| 218 | |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 219 | if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) |
| 220 | goto out_wait; |
| 221 | |
| 222 | if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) { |
| 223 | if (flags & SYNC_TRYLOCK) |
| 224 | goto out_wait; |
| 225 | xfs_ilock(ip, XFS_IOLOCK_SHARED); |
| 226 | } |
| 227 | |
| 228 | error = xfs_flush_pages(ip, 0, -1, (flags & SYNC_WAIT) ? |
| 229 | 0 : XFS_B_ASYNC, FI_NONE); |
| 230 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); |
| 231 | |
| 232 | out_wait: |
Christoph Hellwig | b0710cc | 2009-06-08 15:37:11 +0200 | [diff] [blame] | 233 | if (flags & SYNC_WAIT) |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 234 | xfs_ioend_wait(ip); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 235 | IRELE(ip); |
Dave Chinner | 5a34d5c | 2009-06-08 15:35:03 +0200 | [diff] [blame] | 236 | return error; |
| 237 | } |
| 238 | |
Christoph Hellwig | 845b6d0 | 2009-06-08 15:35:05 +0200 | [diff] [blame] | 239 | STATIC int |
| 240 | xfs_sync_inode_attr( |
| 241 | struct xfs_inode *ip, |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 242 | struct xfs_perag *pag, |
Christoph Hellwig | 845b6d0 | 2009-06-08 15:35:05 +0200 | [diff] [blame] | 243 | int flags) |
| 244 | { |
| 245 | int error = 0; |
| 246 | |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 247 | error = xfs_sync_inode_valid(ip, pag); |
| 248 | if (error) |
| 249 | return error; |
| 250 | |
Christoph Hellwig | 845b6d0 | 2009-06-08 15:35:05 +0200 | [diff] [blame] | 251 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
| 252 | if (xfs_inode_clean(ip)) |
| 253 | goto out_unlock; |
| 254 | if (!xfs_iflock_nowait(ip)) { |
| 255 | if (!(flags & SYNC_WAIT)) |
| 256 | goto out_unlock; |
| 257 | xfs_iflock(ip); |
| 258 | } |
| 259 | |
| 260 | if (xfs_inode_clean(ip)) { |
| 261 | xfs_ifunlock(ip); |
| 262 | goto out_unlock; |
| 263 | } |
| 264 | |
| 265 | error = xfs_iflush(ip, (flags & SYNC_WAIT) ? |
| 266 | XFS_IFLUSH_SYNC : XFS_IFLUSH_DELWRI); |
| 267 | |
| 268 | out_unlock: |
| 269 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 270 | IRELE(ip); |
Christoph Hellwig | 845b6d0 | 2009-06-08 15:35:05 +0200 | [diff] [blame] | 271 | return error; |
| 272 | } |
| 273 | |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 274 | /* |
| 275 | * Write out pagecache data for the whole filesystem. |
| 276 | */ |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 277 | int |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 278 | xfs_sync_data( |
| 279 | struct xfs_mount *mp, |
| 280 | int flags) |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 281 | { |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 282 | int error; |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 283 | |
Christoph Hellwig | b0710cc | 2009-06-08 15:37:11 +0200 | [diff] [blame] | 284 | ASSERT((flags & ~(SYNC_TRYLOCK|SYNC_WAIT)) == 0); |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 285 | |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 286 | error = xfs_inode_ag_iterator(mp, xfs_sync_inode_data, flags, |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 287 | XFS_ICI_NO_TAG, 0); |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 288 | if (error) |
| 289 | return XFS_ERROR(error); |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 290 | |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 291 | xfs_log_force(mp, 0, |
| 292 | (flags & SYNC_WAIT) ? |
| 293 | XFS_LOG_FORCE | XFS_LOG_SYNC : |
| 294 | XFS_LOG_FORCE); |
| 295 | return 0; |
| 296 | } |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 297 | |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 298 | /* |
| 299 | * Write out inode metadata (attributes) for the whole filesystem. |
| 300 | */ |
| 301 | int |
| 302 | xfs_sync_attr( |
| 303 | struct xfs_mount *mp, |
| 304 | int flags) |
| 305 | { |
| 306 | ASSERT((flags & ~SYNC_WAIT) == 0); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 307 | |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 308 | return xfs_inode_ag_iterator(mp, xfs_sync_inode_attr, flags, |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 309 | XFS_ICI_NO_TAG, 0); |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 310 | } |
| 311 | |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 312 | STATIC int |
| 313 | xfs_commit_dummy_trans( |
| 314 | struct xfs_mount *mp, |
Dave Chinner | dce5065 | 2009-10-06 20:29:30 +0000 | [diff] [blame] | 315 | uint flags) |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 316 | { |
| 317 | struct xfs_inode *ip = mp->m_rootip; |
| 318 | struct xfs_trans *tp; |
| 319 | int error; |
Dave Chinner | dce5065 | 2009-10-06 20:29:30 +0000 | [diff] [blame] | 320 | int log_flags = XFS_LOG_FORCE; |
| 321 | |
| 322 | if (flags & SYNC_WAIT) |
| 323 | log_flags |= XFS_LOG_SYNC; |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * Put a dummy transaction in the log to tell recovery |
| 327 | * that all others are OK. |
| 328 | */ |
| 329 | tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1); |
| 330 | error = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0); |
| 331 | if (error) { |
| 332 | xfs_trans_cancel(tp, 0); |
| 333 | return error; |
| 334 | } |
| 335 | |
| 336 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 337 | |
| 338 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 339 | xfs_trans_ihold(tp, ip); |
| 340 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 341 | error = xfs_trans_commit(tp, 0); |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 342 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 343 | |
Dave Chinner | dce5065 | 2009-10-06 20:29:30 +0000 | [diff] [blame] | 344 | /* the log force ensures this transaction is pushed to disk */ |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 345 | xfs_log_force(mp, 0, log_flags); |
Dave Chinner | dce5065 | 2009-10-06 20:29:30 +0000 | [diff] [blame] | 346 | return error; |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 347 | } |
| 348 | |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 349 | int |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 350 | xfs_sync_fsdata( |
| 351 | struct xfs_mount *mp, |
| 352 | int flags) |
| 353 | { |
| 354 | struct xfs_buf *bp; |
| 355 | struct xfs_buf_log_item *bip; |
| 356 | int error = 0; |
| 357 | |
| 358 | /* |
| 359 | * If this is xfssyncd() then only sync the superblock if we can |
| 360 | * lock it without sleeping and it is not pinned. |
| 361 | */ |
Christoph Hellwig | 8b5403a | 2009-06-08 15:37:16 +0200 | [diff] [blame] | 362 | if (flags & SYNC_TRYLOCK) { |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 363 | ASSERT(!(flags & SYNC_WAIT)); |
| 364 | |
| 365 | bp = xfs_getsb(mp, XFS_BUF_TRYLOCK); |
| 366 | if (!bp) |
| 367 | goto out; |
| 368 | |
| 369 | bip = XFS_BUF_FSPRIVATE(bp, struct xfs_buf_log_item *); |
| 370 | if (!bip || !xfs_buf_item_dirty(bip) || XFS_BUF_ISPINNED(bp)) |
| 371 | goto out_brelse; |
| 372 | } else { |
| 373 | bp = xfs_getsb(mp, 0); |
| 374 | |
| 375 | /* |
| 376 | * If the buffer is pinned then push on the log so we won't |
| 377 | * get stuck waiting in the write for someone, maybe |
| 378 | * ourselves, to flush the log. |
| 379 | * |
| 380 | * Even though we just pushed the log above, we did not have |
| 381 | * the superblock buffer locked at that point so it can |
| 382 | * become pinned in between there and here. |
| 383 | */ |
| 384 | if (XFS_BUF_ISPINNED(bp)) |
| 385 | xfs_log_force(mp, 0, XFS_LOG_FORCE); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | if (flags & SYNC_WAIT) |
| 390 | XFS_BUF_UNASYNC(bp); |
| 391 | else |
| 392 | XFS_BUF_ASYNC(bp); |
| 393 | |
Dave Chinner | dce5065 | 2009-10-06 20:29:30 +0000 | [diff] [blame] | 394 | error = xfs_bwrite(mp, bp); |
| 395 | if (error) |
| 396 | return error; |
| 397 | |
| 398 | /* |
| 399 | * If this is a data integrity sync make sure all pending buffers |
| 400 | * are flushed out for the log coverage check below. |
| 401 | */ |
| 402 | if (flags & SYNC_WAIT) |
| 403 | xfs_flush_buftarg(mp->m_ddev_targp, 1); |
| 404 | |
| 405 | if (xfs_log_need_covered(mp)) |
| 406 | error = xfs_commit_dummy_trans(mp, flags); |
| 407 | return error; |
Christoph Hellwig | 2af75df | 2008-10-30 17:14:53 +1100 | [diff] [blame] | 408 | |
| 409 | out_brelse: |
| 410 | xfs_buf_relse(bp); |
| 411 | out: |
| 412 | return error; |
| 413 | } |
| 414 | |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame] | 415 | /* |
David Chinner | a4e4c4f | 2008-10-30 17:16:11 +1100 | [diff] [blame] | 416 | * When remounting a filesystem read-only or freezing the filesystem, we have |
| 417 | * two phases to execute. This first phase is syncing the data before we |
| 418 | * quiesce the filesystem, and the second is flushing all the inodes out after |
| 419 | * we've waited for all the transactions created by the first phase to |
| 420 | * complete. The second phase ensures that the inodes are written to their |
| 421 | * location on disk rather than just existing in transactions in the log. This |
| 422 | * means after a quiesce there is no log replay required to write the inodes to |
| 423 | * disk (this is the main difference between a sync and a quiesce). |
| 424 | */ |
| 425 | /* |
| 426 | * First stage of freeze - no writers will make progress now we are here, |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 427 | * so we flush delwri and delalloc buffers here, then wait for all I/O to |
| 428 | * complete. Data is frozen at that point. Metadata is not frozen, |
David Chinner | a4e4c4f | 2008-10-30 17:16:11 +1100 | [diff] [blame] | 429 | * transactions can still occur here so don't bother flushing the buftarg |
| 430 | * because it'll just get dirty again. |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 431 | */ |
| 432 | int |
| 433 | xfs_quiesce_data( |
| 434 | struct xfs_mount *mp) |
| 435 | { |
| 436 | int error; |
| 437 | |
| 438 | /* push non-blocking */ |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 439 | xfs_sync_data(mp, 0); |
Christoph Hellwig | 8b5403a | 2009-06-08 15:37:16 +0200 | [diff] [blame] | 440 | xfs_qm_sync(mp, SYNC_TRYLOCK); |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 441 | |
Dave Chinner | c90b07e | 2009-10-06 20:29:27 +0000 | [diff] [blame] | 442 | /* push and block till complete */ |
Christoph Hellwig | b0710cc | 2009-06-08 15:37:11 +0200 | [diff] [blame] | 443 | xfs_sync_data(mp, SYNC_WAIT); |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 444 | xfs_qm_sync(mp, SYNC_WAIT); |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 445 | |
Dave Chinner | c90b07e | 2009-10-06 20:29:27 +0000 | [diff] [blame] | 446 | /* drop inode references pinned by filestreams */ |
| 447 | xfs_filestream_flush(mp); |
| 448 | |
David Chinner | a4e4c4f | 2008-10-30 17:16:11 +1100 | [diff] [blame] | 449 | /* write superblock and hoover up shutdown errors */ |
Dave Chinner | c90b07e | 2009-10-06 20:29:27 +0000 | [diff] [blame] | 450 | error = xfs_sync_fsdata(mp, SYNC_WAIT); |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 451 | |
David Chinner | a4e4c4f | 2008-10-30 17:16:11 +1100 | [diff] [blame] | 452 | /* flush data-only devices */ |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 453 | if (mp->m_rtdev_targp) |
| 454 | XFS_bflush(mp->m_rtdev_targp); |
| 455 | |
| 456 | return error; |
| 457 | } |
| 458 | |
David Chinner | 76bf105 | 2008-10-30 17:16:21 +1100 | [diff] [blame] | 459 | STATIC void |
| 460 | xfs_quiesce_fs( |
| 461 | struct xfs_mount *mp) |
| 462 | { |
| 463 | int count = 0, pincount; |
| 464 | |
| 465 | xfs_flush_buftarg(mp->m_ddev_targp, 0); |
Dave Chinner | abc1064 | 2009-06-08 15:35:12 +0200 | [diff] [blame] | 466 | xfs_reclaim_inodes(mp, XFS_IFLUSH_DELWRI_ELSE_ASYNC); |
David Chinner | 76bf105 | 2008-10-30 17:16:21 +1100 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * This loop must run at least twice. The first instance of the loop |
| 470 | * will flush most meta data but that will generate more meta data |
| 471 | * (typically directory updates). Which then must be flushed and |
| 472 | * logged before we can write the unmount record. |
| 473 | */ |
| 474 | do { |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 475 | xfs_sync_attr(mp, SYNC_WAIT); |
David Chinner | 76bf105 | 2008-10-30 17:16:21 +1100 | [diff] [blame] | 476 | pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1); |
| 477 | if (!pincount) { |
| 478 | delay(50); |
| 479 | count++; |
| 480 | } |
| 481 | } while (count < 2); |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Second stage of a quiesce. The data is already synced, now we have to take |
| 486 | * care of the metadata. New transactions are already blocked, so we need to |
| 487 | * wait for any remaining transactions to drain out before proceding. |
| 488 | */ |
| 489 | void |
| 490 | xfs_quiesce_attr( |
| 491 | struct xfs_mount *mp) |
| 492 | { |
| 493 | int error = 0; |
| 494 | |
| 495 | /* wait for all modifications to complete */ |
| 496 | while (atomic_read(&mp->m_active_trans) > 0) |
| 497 | delay(100); |
| 498 | |
| 499 | /* flush inodes and push all remaining buffers out to disk */ |
| 500 | xfs_quiesce_fs(mp); |
| 501 | |
Felix Blyakher | 5e10657 | 2009-01-22 21:34:05 -0600 | [diff] [blame] | 502 | /* |
| 503 | * Just warn here till VFS can correctly support |
| 504 | * read-only remount without racing. |
| 505 | */ |
| 506 | WARN_ON(atomic_read(&mp->m_active_trans) != 0); |
David Chinner | 76bf105 | 2008-10-30 17:16:21 +1100 | [diff] [blame] | 507 | |
| 508 | /* Push the superblock and write an unmount record */ |
| 509 | error = xfs_log_sbcount(mp, 1); |
| 510 | if (error) |
| 511 | xfs_fs_cmn_err(CE_WARN, mp, |
| 512 | "xfs_attr_quiesce: failed to log sb changes. " |
| 513 | "Frozen image may not be consistent."); |
| 514 | xfs_log_unmount_write(mp); |
| 515 | xfs_unmountfs_writesb(mp); |
| 516 | } |
| 517 | |
David Chinner | e9f1c6e | 2008-10-30 17:15:50 +1100 | [diff] [blame] | 518 | /* |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 519 | * Enqueue a work item to be picked up by the vfs xfssyncd thread. |
| 520 | * Doing this has two advantages: |
| 521 | * - It saves on stack space, which is tight in certain situations |
| 522 | * - It can be used (with care) as a mechanism to avoid deadlocks. |
| 523 | * Flushing while allocating in a full filesystem requires both. |
| 524 | */ |
| 525 | STATIC void |
| 526 | xfs_syncd_queue_work( |
| 527 | struct xfs_mount *mp, |
| 528 | void *data, |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 529 | void (*syncer)(struct xfs_mount *, void *), |
| 530 | struct completion *completion) |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 531 | { |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 532 | struct xfs_sync_work *work; |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 533 | |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 534 | work = kmem_alloc(sizeof(struct xfs_sync_work), KM_SLEEP); |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 535 | INIT_LIST_HEAD(&work->w_list); |
| 536 | work->w_syncer = syncer; |
| 537 | work->w_data = data; |
| 538 | work->w_mount = mp; |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 539 | work->w_completion = completion; |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 540 | spin_lock(&mp->m_sync_lock); |
| 541 | list_add_tail(&work->w_list, &mp->m_sync_list); |
| 542 | spin_unlock(&mp->m_sync_lock); |
| 543 | wake_up_process(mp->m_sync_task); |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * Flush delayed allocate data, attempting to free up reserved space |
| 548 | * from existing allocations. At this point a new allocation attempt |
| 549 | * has failed with ENOSPC and we are in the process of scratching our |
| 550 | * heads, looking about for more room... |
| 551 | */ |
| 552 | STATIC void |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 553 | xfs_flush_inodes_work( |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 554 | struct xfs_mount *mp, |
| 555 | void *arg) |
| 556 | { |
| 557 | struct inode *inode = arg; |
Christoph Hellwig | 075fe10 | 2009-06-08 15:35:48 +0200 | [diff] [blame] | 558 | xfs_sync_data(mp, SYNC_TRYLOCK); |
Christoph Hellwig | b0710cc | 2009-06-08 15:37:11 +0200 | [diff] [blame] | 559 | xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT); |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 560 | iput(inode); |
| 561 | } |
| 562 | |
| 563 | void |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 564 | xfs_flush_inodes( |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 565 | xfs_inode_t *ip) |
| 566 | { |
| 567 | struct inode *inode = VFS_I(ip); |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 568 | DECLARE_COMPLETION_ONSTACK(completion); |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 569 | |
| 570 | igrab(inode); |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 571 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inodes_work, &completion); |
| 572 | wait_for_completion(&completion); |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 573 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); |
| 574 | } |
| 575 | |
David Chinner | aacaa88 | 2008-10-30 17:15:29 +1100 | [diff] [blame] | 576 | /* |
| 577 | * Every sync period we need to unpin all items, reclaim inodes, sync |
| 578 | * quota and write out the superblock. We might need to cover the log |
| 579 | * to indicate it is idle. |
| 580 | */ |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 581 | STATIC void |
| 582 | xfs_sync_worker( |
| 583 | struct xfs_mount *mp, |
| 584 | void *unused) |
| 585 | { |
| 586 | int error; |
| 587 | |
David Chinner | aacaa88 | 2008-10-30 17:15:29 +1100 | [diff] [blame] | 588 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
| 589 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE); |
Dave Chinner | abc1064 | 2009-06-08 15:35:12 +0200 | [diff] [blame] | 590 | xfs_reclaim_inodes(mp, XFS_IFLUSH_DELWRI_ELSE_ASYNC); |
David Chinner | aacaa88 | 2008-10-30 17:15:29 +1100 | [diff] [blame] | 591 | /* dgc: errors ignored here */ |
Christoph Hellwig | 8b5403a | 2009-06-08 15:37:16 +0200 | [diff] [blame] | 592 | error = xfs_qm_sync(mp, SYNC_TRYLOCK); |
| 593 | error = xfs_sync_fsdata(mp, SYNC_TRYLOCK); |
David Chinner | aacaa88 | 2008-10-30 17:15:29 +1100 | [diff] [blame] | 594 | } |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 595 | mp->m_sync_seq++; |
| 596 | wake_up(&mp->m_wait_single_sync_task); |
| 597 | } |
| 598 | |
| 599 | STATIC int |
| 600 | xfssyncd( |
| 601 | void *arg) |
| 602 | { |
| 603 | struct xfs_mount *mp = arg; |
| 604 | long timeleft; |
Dave Chinner | a8d770d | 2009-04-06 18:44:54 +0200 | [diff] [blame] | 605 | xfs_sync_work_t *work, *n; |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 606 | LIST_HEAD (tmp); |
| 607 | |
| 608 | set_freezable(); |
| 609 | timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10); |
| 610 | for (;;) { |
| 611 | timeleft = schedule_timeout_interruptible(timeleft); |
| 612 | /* swsusp */ |
| 613 | try_to_freeze(); |
| 614 | if (kthread_should_stop() && list_empty(&mp->m_sync_list)) |
| 615 | break; |
| 616 | |
| 617 | spin_lock(&mp->m_sync_lock); |
| 618 | /* |
| 619 | * We can get woken by laptop mode, to do a sync - |
| 620 | * that's the (only!) case where the list would be |
| 621 | * empty with time remaining. |
| 622 | */ |
| 623 | if (!timeleft || list_empty(&mp->m_sync_list)) { |
| 624 | if (!timeleft) |
| 625 | timeleft = xfs_syncd_centisecs * |
| 626 | msecs_to_jiffies(10); |
| 627 | INIT_LIST_HEAD(&mp->m_sync_work.w_list); |
| 628 | list_add_tail(&mp->m_sync_work.w_list, |
| 629 | &mp->m_sync_list); |
| 630 | } |
| 631 | list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list) |
| 632 | list_move(&work->w_list, &tmp); |
| 633 | spin_unlock(&mp->m_sync_lock); |
| 634 | |
| 635 | list_for_each_entry_safe(work, n, &tmp, w_list) { |
| 636 | (*work->w_syncer)(mp, work->w_data); |
| 637 | list_del(&work->w_list); |
| 638 | if (work == &mp->m_sync_work) |
| 639 | continue; |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 640 | if (work->w_completion) |
| 641 | complete(work->w_completion); |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 642 | kmem_free(work); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | int |
| 650 | xfs_syncd_init( |
| 651 | struct xfs_mount *mp) |
| 652 | { |
| 653 | mp->m_sync_work.w_syncer = xfs_sync_worker; |
| 654 | mp->m_sync_work.w_mount = mp; |
Dave Chinner | e43afd7 | 2009-04-06 18:47:27 +0200 | [diff] [blame] | 655 | mp->m_sync_work.w_completion = NULL; |
David Chinner | a167b17 | 2008-10-30 17:06:18 +1100 | [diff] [blame] | 656 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); |
| 657 | if (IS_ERR(mp->m_sync_task)) |
| 658 | return -PTR_ERR(mp->m_sync_task); |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | void |
| 663 | xfs_syncd_stop( |
| 664 | struct xfs_mount *mp) |
| 665 | { |
| 666 | kthread_stop(mp->m_sync_task); |
| 667 | } |
| 668 | |
Christoph Hellwig | bc990f5 | 2009-08-16 20:36:34 -0400 | [diff] [blame] | 669 | void |
| 670 | __xfs_inode_set_reclaim_tag( |
| 671 | struct xfs_perag *pag, |
| 672 | struct xfs_inode *ip) |
| 673 | { |
| 674 | radix_tree_tag_set(&pag->pag_ici_root, |
| 675 | XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino), |
| 676 | XFS_ICI_RECLAIM_TAG); |
| 677 | } |
| 678 | |
David Chinner | 1165451 | 2008-10-30 17:37:49 +1100 | [diff] [blame] | 679 | /* |
| 680 | * We set the inode flag atomically with the radix tree tag. |
| 681 | * Once we get tag lookups on the radix tree, this inode flag |
| 682 | * can go away. |
| 683 | */ |
David Chinner | 396beb8 | 2008-10-30 17:37:26 +1100 | [diff] [blame] | 684 | void |
| 685 | xfs_inode_set_reclaim_tag( |
| 686 | xfs_inode_t *ip) |
| 687 | { |
| 688 | xfs_mount_t *mp = ip->i_mount; |
| 689 | xfs_perag_t *pag = xfs_get_perag(mp, ip->i_ino); |
| 690 | |
| 691 | read_lock(&pag->pag_ici_lock); |
| 692 | spin_lock(&ip->i_flags_lock); |
Christoph Hellwig | bc990f5 | 2009-08-16 20:36:34 -0400 | [diff] [blame] | 693 | __xfs_inode_set_reclaim_tag(pag, ip); |
David Chinner | 1165451 | 2008-10-30 17:37:49 +1100 | [diff] [blame] | 694 | __xfs_iflags_set(ip, XFS_IRECLAIMABLE); |
David Chinner | 396beb8 | 2008-10-30 17:37:26 +1100 | [diff] [blame] | 695 | spin_unlock(&ip->i_flags_lock); |
| 696 | read_unlock(&pag->pag_ici_lock); |
| 697 | xfs_put_perag(mp, pag); |
| 698 | } |
| 699 | |
| 700 | void |
| 701 | __xfs_inode_clear_reclaim_tag( |
| 702 | xfs_mount_t *mp, |
| 703 | xfs_perag_t *pag, |
| 704 | xfs_inode_t *ip) |
| 705 | { |
| 706 | radix_tree_tag_clear(&pag->pag_ici_root, |
| 707 | XFS_INO_TO_AGINO(mp, ip->i_ino), XFS_ICI_RECLAIM_TAG); |
| 708 | } |
| 709 | |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 710 | STATIC int |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 711 | xfs_reclaim_inode( |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 712 | struct xfs_inode *ip, |
| 713 | struct xfs_perag *pag, |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 714 | int sync_mode) |
David Chinner | 7a3be02 | 2008-10-30 17:37:37 +1100 | [diff] [blame] | 715 | { |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 716 | /* |
| 717 | * The radix tree lock here protects a thread in xfs_iget from racing |
| 718 | * with us starting reclaim on the inode. Once we have the |
| 719 | * XFS_IRECLAIM flag set it will not touch us. |
| 720 | */ |
| 721 | spin_lock(&ip->i_flags_lock); |
| 722 | ASSERT_ALWAYS(__xfs_iflags_test(ip, XFS_IRECLAIMABLE)); |
| 723 | if (__xfs_iflags_test(ip, XFS_IRECLAIM)) { |
| 724 | /* ignore as it is already under reclaim */ |
| 725 | spin_unlock(&ip->i_flags_lock); |
| 726 | write_unlock(&pag->pag_ici_lock); |
Dave Chinner | 75f3cb1 | 2009-06-08 15:35:14 +0200 | [diff] [blame] | 727 | return 0; |
David Chinner | 7a3be02 | 2008-10-30 17:37:37 +1100 | [diff] [blame] | 728 | } |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 729 | __xfs_iflags_set(ip, XFS_IRECLAIM); |
| 730 | spin_unlock(&ip->i_flags_lock); |
| 731 | write_unlock(&pag->pag_ici_lock); |
David Chinner | 7a3be02 | 2008-10-30 17:37:37 +1100 | [diff] [blame] | 732 | |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 733 | /* |
| 734 | * If the inode is still dirty, then flush it out. If the inode |
| 735 | * is not in the AIL, then it will be OK to flush it delwri as |
| 736 | * long as xfs_iflush() does not keep any references to the inode. |
| 737 | * We leave that decision up to xfs_iflush() since it has the |
| 738 | * knowledge of whether it's OK to simply do a delwri flush of |
| 739 | * the inode or whether we need to wait until the inode is |
| 740 | * pulled from the AIL. |
| 741 | * We get the flush lock regardless, though, just to make sure |
| 742 | * we don't free it while it is being flushed. |
| 743 | */ |
| 744 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 745 | xfs_iflock(ip); |
| 746 | |
| 747 | /* |
| 748 | * In the case of a forced shutdown we rely on xfs_iflush() to |
| 749 | * wait for the inode to be unpinned before returning an error. |
| 750 | */ |
| 751 | if (!is_bad_inode(VFS_I(ip)) && xfs_iflush(ip, sync_mode) == 0) { |
| 752 | /* synchronize with xfs_iflush_done */ |
| 753 | xfs_iflock(ip); |
| 754 | xfs_ifunlock(ip); |
| 755 | } |
| 756 | |
| 757 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 758 | xfs_ireclaim(ip); |
| 759 | return 0; |
David Chinner | 7a3be02 | 2008-10-30 17:37:37 +1100 | [diff] [blame] | 760 | } |
| 761 | |
David Chinner | fce08f2 | 2008-10-30 17:37:03 +1100 | [diff] [blame] | 762 | int |
David Chinner | 1dc3318 | 2008-10-30 17:37:15 +1100 | [diff] [blame] | 763 | xfs_reclaim_inodes( |
David Chinner | fce08f2 | 2008-10-30 17:37:03 +1100 | [diff] [blame] | 764 | xfs_mount_t *mp, |
David Chinner | fce08f2 | 2008-10-30 17:37:03 +1100 | [diff] [blame] | 765 | int mode) |
| 766 | { |
Dave Chinner | c8e20be | 2010-01-10 23:51:45 +0000 | [diff] [blame^] | 767 | return xfs_inode_ag_iterator(mp, xfs_reclaim_inode, mode, |
| 768 | XFS_ICI_RECLAIM_TAG, 1); |
David Chinner | fce08f2 | 2008-10-30 17:37:03 +1100 | [diff] [blame] | 769 | } |