xfs_sync.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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"
  46. #include <linux/kthread.h>
  47. #include <linux/freezer.h>
  48. /*
  49. * Sync all the inodes in the given AG according to the
  50. * direction given by the flags.
  51. */
  52. STATIC int
  53. xfs_sync_inodes_ag(
  54. xfs_mount_t *mp,
  55. int ag,
  56. int flags)
  57. {
  58. xfs_perag_t *pag = &mp->m_perag[ag];
  59. int nr_found;
  60. int first_index = 0;
  61. int error = 0;
  62. int last_error = 0;
  63. int fflag = XFS_B_ASYNC;
  64. int lock_flags = XFS_ILOCK_SHARED;
  65. if (flags & SYNC_DELWRI)
  66. fflag = XFS_B_DELWRI;
  67. if (flags & SYNC_WAIT)
  68. fflag = 0; /* synchronous overrides all */
  69. if (flags & SYNC_DELWRI) {
  70. /*
  71. * We need the I/O lock if we're going to call any of
  72. * the flush/inval routines.
  73. */
  74. lock_flags |= XFS_IOLOCK_SHARED;
  75. }
  76. do {
  77. struct inode *inode;
  78. boolean_t inode_refed;
  79. xfs_inode_t *ip = NULL;
  80. /*
  81. * use a gang lookup to find the next inode in the tree
  82. * as the tree is sparse and a gang lookup walks to find
  83. * the number of objects requested.
  84. */
  85. read_lock(&pag->pag_ici_lock);
  86. nr_found = radix_tree_gang_lookup(&pag->pag_ici_root,
  87. (void**)&ip, first_index, 1);
  88. if (!nr_found) {
  89. read_unlock(&pag->pag_ici_lock);
  90. break;
  91. }
  92. /* update the index for the next lookup */
  93. first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1);
  94. /*
  95. * skip inodes in reclaim. Let xfs_syncsub do that for
  96. * us so we don't need to worry.
  97. */
  98. if (xfs_iflags_test(ip, (XFS_IRECLAIM|XFS_IRECLAIMABLE))) {
  99. read_unlock(&pag->pag_ici_lock);
  100. continue;
  101. }
  102. /* bad inodes are dealt with elsewhere */
  103. inode = VFS_I(ip);
  104. if (is_bad_inode(inode)) {
  105. read_unlock(&pag->pag_ici_lock);
  106. continue;
  107. }
  108. /* nothing to sync during shutdown */
  109. if (XFS_FORCED_SHUTDOWN(mp)) {
  110. read_unlock(&pag->pag_ici_lock);
  111. return 0;
  112. }
  113. /*
  114. * If we can't get a reference on the VFS_I, the inode must be
  115. * in reclaim. If we can get the inode lock without blocking,
  116. * it is safe to flush the inode because we hold the tree lock
  117. * and xfs_iextract will block right now. Hence if we lock the
  118. * inode while holding the tree lock, xfs_ireclaim() is
  119. * guaranteed to block on the inode lock we now hold and hence
  120. * it is safe to reference the inode until we drop the inode
  121. * locks completely.
  122. */
  123. inode_refed = B_FALSE;
  124. if (igrab(inode)) {
  125. read_unlock(&pag->pag_ici_lock);
  126. xfs_ilock(ip, lock_flags);
  127. inode_refed = B_TRUE;
  128. } else {
  129. if (!xfs_ilock_nowait(ip, lock_flags)) {
  130. /* leave it to reclaim */
  131. read_unlock(&pag->pag_ici_lock);
  132. continue;
  133. }
  134. read_unlock(&pag->pag_ici_lock);
  135. }
  136. /*
  137. * If we have to flush data or wait for I/O completion
  138. * we need to drop the ilock that we currently hold.
  139. * If we need to drop the lock, insert a marker if we
  140. * have not already done so.
  141. */
  142. if ((flags & SYNC_DELWRI) && VN_DIRTY(inode)) {
  143. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  144. error = xfs_flush_pages(ip, 0, -1, fflag, FI_NONE);
  145. if (flags & SYNC_IOWAIT)
  146. vn_iowait(ip);
  147. xfs_ilock(ip, XFS_ILOCK_SHARED);
  148. }
  149. if ((flags & SYNC_ATTR) && !xfs_inode_clean(ip)) {
  150. if (flags & SYNC_WAIT) {
  151. xfs_iflock(ip);
  152. if (!xfs_inode_clean(ip))
  153. error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
  154. else
  155. xfs_ifunlock(ip);
  156. } else if (xfs_iflock_nowait(ip)) {
  157. if (!xfs_inode_clean(ip))
  158. error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
  159. else
  160. xfs_ifunlock(ip);
  161. }
  162. }
  163. if (lock_flags)
  164. xfs_iunlock(ip, lock_flags);
  165. if (inode_refed) {
  166. IRELE(ip);
  167. }
  168. if (error)
  169. last_error = error;
  170. /*
  171. * bail out if the filesystem is corrupted.
  172. */
  173. if (error == EFSCORRUPTED)
  174. return XFS_ERROR(error);
  175. } while (nr_found);
  176. return last_error;
  177. }
  178. int
  179. xfs_sync_inodes(
  180. xfs_mount_t *mp,
  181. int flags)
  182. {
  183. int error;
  184. int last_error;
  185. int i;
  186. int lflags = XFS_LOG_FORCE;
  187. if (mp->m_flags & XFS_MOUNT_RDONLY)
  188. return 0;
  189. error = 0;
  190. last_error = 0;
  191. if (flags & SYNC_WAIT)
  192. lflags |= XFS_LOG_SYNC;
  193. for (i = 0; i < mp->m_sb.sb_agcount; i++) {
  194. if (!mp->m_perag[i].pag_ici_init)
  195. continue;
  196. error = xfs_sync_inodes_ag(mp, i, flags);
  197. if (error)
  198. last_error = error;
  199. if (error == EFSCORRUPTED)
  200. break;
  201. }
  202. if (flags & SYNC_DELWRI)
  203. xfs_log_force(mp, 0, lflags);
  204. return XFS_ERROR(last_error);
  205. }
  206. STATIC int
  207. xfs_commit_dummy_trans(
  208. struct xfs_mount *mp,
  209. uint log_flags)
  210. {
  211. struct xfs_inode *ip = mp->m_rootip;
  212. struct xfs_trans *tp;
  213. int error;
  214. /*
  215. * Put a dummy transaction in the log to tell recovery
  216. * that all others are OK.
  217. */
  218. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  219. error = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
  220. if (error) {
  221. xfs_trans_cancel(tp, 0);
  222. return error;
  223. }
  224. xfs_ilock(ip, XFS_ILOCK_EXCL);
  225. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  226. xfs_trans_ihold(tp, ip);
  227. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  228. /* XXX(hch): ignoring the error here.. */
  229. error = xfs_trans_commit(tp, 0);
  230. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  231. xfs_log_force(mp, 0, log_flags);
  232. return 0;
  233. }
  234. int
  235. xfs_sync_fsdata(
  236. struct xfs_mount *mp,
  237. int flags)
  238. {
  239. struct xfs_buf *bp;
  240. struct xfs_buf_log_item *bip;
  241. int error = 0;
  242. /*
  243. * If this is xfssyncd() then only sync the superblock if we can
  244. * lock it without sleeping and it is not pinned.
  245. */
  246. if (flags & SYNC_BDFLUSH) {
  247. ASSERT(!(flags & SYNC_WAIT));
  248. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  249. if (!bp)
  250. goto out;
  251. bip = XFS_BUF_FSPRIVATE(bp, struct xfs_buf_log_item *);
  252. if (!bip || !xfs_buf_item_dirty(bip) || XFS_BUF_ISPINNED(bp))
  253. goto out_brelse;
  254. } else {
  255. bp = xfs_getsb(mp, 0);
  256. /*
  257. * If the buffer is pinned then push on the log so we won't
  258. * get stuck waiting in the write for someone, maybe
  259. * ourselves, to flush the log.
  260. *
  261. * Even though we just pushed the log above, we did not have
  262. * the superblock buffer locked at that point so it can
  263. * become pinned in between there and here.
  264. */
  265. if (XFS_BUF_ISPINNED(bp))
  266. xfs_log_force(mp, 0, XFS_LOG_FORCE);
  267. }
  268. if (flags & SYNC_WAIT)
  269. XFS_BUF_UNASYNC(bp);
  270. else
  271. XFS_BUF_ASYNC(bp);
  272. return xfs_bwrite(mp, bp);
  273. out_brelse:
  274. xfs_buf_relse(bp);
  275. out:
  276. return error;
  277. }
  278. /*
  279. * When remounting a filesystem read-only or freezing the filesystem, we have
  280. * two phases to execute. This first phase is syncing the data before we
  281. * quiesce the filesystem, and the second is flushing all the inodes out after
  282. * we've waited for all the transactions created by the first phase to
  283. * complete. The second phase ensures that the inodes are written to their
  284. * location on disk rather than just existing in transactions in the log. This
  285. * means after a quiesce there is no log replay required to write the inodes to
  286. * disk (this is the main difference between a sync and a quiesce).
  287. */
  288. /*
  289. * First stage of freeze - no writers will make progress now we are here,
  290. * so we flush delwri and delalloc buffers here, then wait for all I/O to
  291. * complete. Data is frozen at that point. Metadata is not frozen,
  292. * transactions can still occur here so don't bother flushing the buftarg
  293. * because it'll just get dirty again.
  294. */
  295. int
  296. xfs_quiesce_data(
  297. struct xfs_mount *mp)
  298. {
  299. int error;
  300. /* push non-blocking */
  301. xfs_sync_inodes(mp, SYNC_DELWRI|SYNC_BDFLUSH);
  302. XFS_QM_DQSYNC(mp, SYNC_BDFLUSH);
  303. xfs_filestream_flush(mp);
  304. /* push and block */
  305. xfs_sync_inodes(mp, SYNC_DELWRI|SYNC_WAIT|SYNC_IOWAIT);
  306. XFS_QM_DQSYNC(mp, SYNC_WAIT);
  307. /* write superblock and hoover up shutdown errors */
  308. error = xfs_sync_fsdata(mp, 0);
  309. /* flush data-only devices */
  310. if (mp->m_rtdev_targp)
  311. XFS_bflush(mp->m_rtdev_targp);
  312. return error;
  313. }
  314. STATIC void
  315. xfs_quiesce_fs(
  316. struct xfs_mount *mp)
  317. {
  318. int count = 0, pincount;
  319. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  320. xfs_finish_reclaim_all(mp, 0, XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  321. /*
  322. * This loop must run at least twice. The first instance of the loop
  323. * will flush most meta data but that will generate more meta data
  324. * (typically directory updates). Which then must be flushed and
  325. * logged before we can write the unmount record.
  326. */
  327. do {
  328. xfs_sync_inodes(mp, SYNC_ATTR|SYNC_WAIT);
  329. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  330. if (!pincount) {
  331. delay(50);
  332. count++;
  333. }
  334. } while (count < 2);
  335. }
  336. /*
  337. * Second stage of a quiesce. The data is already synced, now we have to take
  338. * care of the metadata. New transactions are already blocked, so we need to
  339. * wait for any remaining transactions to drain out before proceding.
  340. */
  341. void
  342. xfs_quiesce_attr(
  343. struct xfs_mount *mp)
  344. {
  345. int error = 0;
  346. /* wait for all modifications to complete */
  347. while (atomic_read(&mp->m_active_trans) > 0)
  348. delay(100);
  349. /* flush inodes and push all remaining buffers out to disk */
  350. xfs_quiesce_fs(mp);
  351. ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
  352. /* Push the superblock and write an unmount record */
  353. error = xfs_log_sbcount(mp, 1);
  354. if (error)
  355. xfs_fs_cmn_err(CE_WARN, mp,
  356. "xfs_attr_quiesce: failed to log sb changes. "
  357. "Frozen image may not be consistent.");
  358. xfs_log_unmount_write(mp);
  359. xfs_unmountfs_writesb(mp);
  360. }
  361. /*
  362. * Enqueue a work item to be picked up by the vfs xfssyncd thread.
  363. * Doing this has two advantages:
  364. * - It saves on stack space, which is tight in certain situations
  365. * - It can be used (with care) as a mechanism to avoid deadlocks.
  366. * Flushing while allocating in a full filesystem requires both.
  367. */
  368. STATIC void
  369. xfs_syncd_queue_work(
  370. struct xfs_mount *mp,
  371. void *data,
  372. void (*syncer)(struct xfs_mount *, void *))
  373. {
  374. struct bhv_vfs_sync_work *work;
  375. work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
  376. INIT_LIST_HEAD(&work->w_list);
  377. work->w_syncer = syncer;
  378. work->w_data = data;
  379. work->w_mount = mp;
  380. spin_lock(&mp->m_sync_lock);
  381. list_add_tail(&work->w_list, &mp->m_sync_list);
  382. spin_unlock(&mp->m_sync_lock);
  383. wake_up_process(mp->m_sync_task);
  384. }
  385. /*
  386. * Flush delayed allocate data, attempting to free up reserved space
  387. * from existing allocations. At this point a new allocation attempt
  388. * has failed with ENOSPC and we are in the process of scratching our
  389. * heads, looking about for more room...
  390. */
  391. STATIC void
  392. xfs_flush_inode_work(
  393. struct xfs_mount *mp,
  394. void *arg)
  395. {
  396. struct inode *inode = arg;
  397. filemap_flush(inode->i_mapping);
  398. iput(inode);
  399. }
  400. void
  401. xfs_flush_inode(
  402. xfs_inode_t *ip)
  403. {
  404. struct inode *inode = VFS_I(ip);
  405. igrab(inode);
  406. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
  407. delay(msecs_to_jiffies(500));
  408. }
  409. /*
  410. * This is the "bigger hammer" version of xfs_flush_inode_work...
  411. * (IOW, "If at first you don't succeed, use a Bigger Hammer").
  412. */
  413. STATIC void
  414. xfs_flush_device_work(
  415. struct xfs_mount *mp,
  416. void *arg)
  417. {
  418. struct inode *inode = arg;
  419. sync_blockdev(mp->m_super->s_bdev);
  420. iput(inode);
  421. }
  422. void
  423. xfs_flush_device(
  424. xfs_inode_t *ip)
  425. {
  426. struct inode *inode = VFS_I(ip);
  427. igrab(inode);
  428. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
  429. delay(msecs_to_jiffies(500));
  430. xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
  431. }
  432. /*
  433. * Every sync period we need to unpin all items, reclaim inodes, sync
  434. * quota and write out the superblock. We might need to cover the log
  435. * to indicate it is idle.
  436. */
  437. STATIC void
  438. xfs_sync_worker(
  439. struct xfs_mount *mp,
  440. void *unused)
  441. {
  442. int error;
  443. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  444. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  445. xfs_finish_reclaim_all(mp, 1, XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  446. /* dgc: errors ignored here */
  447. error = XFS_QM_DQSYNC(mp, SYNC_BDFLUSH);
  448. error = xfs_sync_fsdata(mp, SYNC_BDFLUSH);
  449. if (xfs_log_need_covered(mp))
  450. error = xfs_commit_dummy_trans(mp, XFS_LOG_FORCE);
  451. }
  452. mp->m_sync_seq++;
  453. wake_up(&mp->m_wait_single_sync_task);
  454. }
  455. STATIC int
  456. xfssyncd(
  457. void *arg)
  458. {
  459. struct xfs_mount *mp = arg;
  460. long timeleft;
  461. bhv_vfs_sync_work_t *work, *n;
  462. LIST_HEAD (tmp);
  463. set_freezable();
  464. timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
  465. for (;;) {
  466. timeleft = schedule_timeout_interruptible(timeleft);
  467. /* swsusp */
  468. try_to_freeze();
  469. if (kthread_should_stop() && list_empty(&mp->m_sync_list))
  470. break;
  471. spin_lock(&mp->m_sync_lock);
  472. /*
  473. * We can get woken by laptop mode, to do a sync -
  474. * that's the (only!) case where the list would be
  475. * empty with time remaining.
  476. */
  477. if (!timeleft || list_empty(&mp->m_sync_list)) {
  478. if (!timeleft)
  479. timeleft = xfs_syncd_centisecs *
  480. msecs_to_jiffies(10);
  481. INIT_LIST_HEAD(&mp->m_sync_work.w_list);
  482. list_add_tail(&mp->m_sync_work.w_list,
  483. &mp->m_sync_list);
  484. }
  485. list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
  486. list_move(&work->w_list, &tmp);
  487. spin_unlock(&mp->m_sync_lock);
  488. list_for_each_entry_safe(work, n, &tmp, w_list) {
  489. (*work->w_syncer)(mp, work->w_data);
  490. list_del(&work->w_list);
  491. if (work == &mp->m_sync_work)
  492. continue;
  493. kmem_free(work);
  494. }
  495. }
  496. return 0;
  497. }
  498. int
  499. xfs_syncd_init(
  500. struct xfs_mount *mp)
  501. {
  502. mp->m_sync_work.w_syncer = xfs_sync_worker;
  503. mp->m_sync_work.w_mount = mp;
  504. mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
  505. if (IS_ERR(mp->m_sync_task))
  506. return -PTR_ERR(mp->m_sync_task);
  507. return 0;
  508. }
  509. void
  510. xfs_syncd_stop(
  511. struct xfs_mount *mp)
  512. {
  513. kthread_stop(mp->m_sync_task);
  514. }
  515. int
  516. xfs_finish_reclaim(
  517. xfs_inode_t *ip,
  518. int locked,
  519. int sync_mode)
  520. {
  521. xfs_perag_t *pag = xfs_get_perag(ip->i_mount, ip->i_ino);
  522. /* The hash lock here protects a thread in xfs_iget_core from
  523. * racing with us on linking the inode back with a vnode.
  524. * Once we have the XFS_IRECLAIM flag set it will not touch
  525. * us.
  526. */
  527. write_lock(&pag->pag_ici_lock);
  528. spin_lock(&ip->i_flags_lock);
  529. if (__xfs_iflags_test(ip, XFS_IRECLAIM) ||
  530. !__xfs_iflags_test(ip, XFS_IRECLAIMABLE)) {
  531. spin_unlock(&ip->i_flags_lock);
  532. write_unlock(&pag->pag_ici_lock);
  533. if (locked) {
  534. xfs_ifunlock(ip);
  535. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  536. }
  537. return 1;
  538. }
  539. __xfs_iflags_set(ip, XFS_IRECLAIM);
  540. spin_unlock(&ip->i_flags_lock);
  541. write_unlock(&pag->pag_ici_lock);
  542. xfs_put_perag(ip->i_mount, pag);
  543. /*
  544. * If the inode is still dirty, then flush it out. If the inode
  545. * is not in the AIL, then it will be OK to flush it delwri as
  546. * long as xfs_iflush() does not keep any references to the inode.
  547. * We leave that decision up to xfs_iflush() since it has the
  548. * knowledge of whether it's OK to simply do a delwri flush of
  549. * the inode or whether we need to wait until the inode is
  550. * pulled from the AIL.
  551. * We get the flush lock regardless, though, just to make sure
  552. * we don't free it while it is being flushed.
  553. */
  554. if (!locked) {
  555. xfs_ilock(ip, XFS_ILOCK_EXCL);
  556. xfs_iflock(ip);
  557. }
  558. /*
  559. * In the case of a forced shutdown we rely on xfs_iflush() to
  560. * wait for the inode to be unpinned before returning an error.
  561. */
  562. if (!is_bad_inode(VFS_I(ip)) && xfs_iflush(ip, sync_mode) == 0) {
  563. /* synchronize with xfs_iflush_done */
  564. xfs_iflock(ip);
  565. xfs_ifunlock(ip);
  566. }
  567. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  568. xfs_ireclaim(ip);
  569. return 0;
  570. }
  571. int
  572. xfs_finish_reclaim_all(
  573. xfs_mount_t *mp,
  574. int noblock,
  575. int mode)
  576. {
  577. xfs_inode_t *ip, *n;
  578. restart:
  579. XFS_MOUNT_ILOCK(mp);
  580. list_for_each_entry_safe(ip, n, &mp->m_del_inodes, i_reclaim) {
  581. if (noblock) {
  582. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0)
  583. continue;
  584. if (xfs_ipincount(ip) ||
  585. !xfs_iflock_nowait(ip)) {
  586. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  587. continue;
  588. }
  589. }
  590. XFS_MOUNT_IUNLOCK(mp);
  591. if (xfs_finish_reclaim(ip, noblock, mode))
  592. delay(1);
  593. goto restart;
  594. }
  595. XFS_MOUNT_IUNLOCK(mp);
  596. return 0;
  597. }