xfs_sync.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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 | SYNC_CLOSE)) {
  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) && !(flags & SYNC_CLOSE)) {
  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_CLOSE) {
  143. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  144. if (XFS_FORCED_SHUTDOWN(mp))
  145. xfs_tosspages(ip, 0, -1, FI_REMAPF);
  146. else
  147. error = xfs_flushinval_pages(ip, 0, -1,
  148. FI_REMAPF);
  149. /* wait for I/O on freeze */
  150. if (flags & SYNC_IOWAIT)
  151. vn_iowait(ip);
  152. xfs_ilock(ip, XFS_ILOCK_SHARED);
  153. }
  154. if ((flags & SYNC_DELWRI) && VN_DIRTY(inode)) {
  155. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  156. error = xfs_flush_pages(ip, 0, -1, fflag, FI_NONE);
  157. if (flags & SYNC_IOWAIT)
  158. vn_iowait(ip);
  159. xfs_ilock(ip, XFS_ILOCK_SHARED);
  160. }
  161. if ((flags & SYNC_ATTR) && !xfs_inode_clean(ip)) {
  162. if (flags & SYNC_WAIT) {
  163. xfs_iflock(ip);
  164. if (!xfs_inode_clean(ip))
  165. error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
  166. else
  167. xfs_ifunlock(ip);
  168. } else if (xfs_iflock_nowait(ip)) {
  169. if (!xfs_inode_clean(ip))
  170. error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
  171. else
  172. xfs_ifunlock(ip);
  173. }
  174. }
  175. if (lock_flags)
  176. xfs_iunlock(ip, lock_flags);
  177. if (inode_refed) {
  178. IRELE(ip);
  179. }
  180. if (error)
  181. last_error = error;
  182. /*
  183. * bail out if the filesystem is corrupted.
  184. */
  185. if (error == EFSCORRUPTED)
  186. return XFS_ERROR(error);
  187. } while (nr_found);
  188. return last_error;
  189. }
  190. int
  191. xfs_sync_inodes(
  192. xfs_mount_t *mp,
  193. int flags)
  194. {
  195. int error;
  196. int last_error;
  197. int i;
  198. int lflags = XFS_LOG_FORCE;
  199. if (mp->m_flags & XFS_MOUNT_RDONLY)
  200. return 0;
  201. error = 0;
  202. last_error = 0;
  203. if (flags & SYNC_WAIT)
  204. lflags |= XFS_LOG_SYNC;
  205. for (i = 0; i < mp->m_sb.sb_agcount; i++) {
  206. if (!mp->m_perag[i].pag_ici_init)
  207. continue;
  208. error = xfs_sync_inodes_ag(mp, i, flags);
  209. if (error)
  210. last_error = error;
  211. if (error == EFSCORRUPTED)
  212. break;
  213. }
  214. if (flags & SYNC_DELWRI)
  215. xfs_log_force(mp, 0, lflags);
  216. return XFS_ERROR(last_error);
  217. }
  218. STATIC int
  219. xfs_commit_dummy_trans(
  220. struct xfs_mount *mp,
  221. uint log_flags)
  222. {
  223. struct xfs_inode *ip = mp->m_rootip;
  224. struct xfs_trans *tp;
  225. int error;
  226. /*
  227. * Put a dummy transaction in the log to tell recovery
  228. * that all others are OK.
  229. */
  230. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  231. error = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
  232. if (error) {
  233. xfs_trans_cancel(tp, 0);
  234. return error;
  235. }
  236. xfs_ilock(ip, XFS_ILOCK_EXCL);
  237. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  238. xfs_trans_ihold(tp, ip);
  239. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  240. /* XXX(hch): ignoring the error here.. */
  241. error = xfs_trans_commit(tp, 0);
  242. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  243. xfs_log_force(mp, 0, log_flags);
  244. return 0;
  245. }
  246. int
  247. xfs_sync_fsdata(
  248. struct xfs_mount *mp,
  249. int flags)
  250. {
  251. struct xfs_buf *bp;
  252. struct xfs_buf_log_item *bip;
  253. int error = 0;
  254. /*
  255. * If this is xfssyncd() then only sync the superblock if we can
  256. * lock it without sleeping and it is not pinned.
  257. */
  258. if (flags & SYNC_BDFLUSH) {
  259. ASSERT(!(flags & SYNC_WAIT));
  260. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  261. if (!bp)
  262. goto out;
  263. bip = XFS_BUF_FSPRIVATE(bp, struct xfs_buf_log_item *);
  264. if (!bip || !xfs_buf_item_dirty(bip) || XFS_BUF_ISPINNED(bp))
  265. goto out_brelse;
  266. } else {
  267. bp = xfs_getsb(mp, 0);
  268. /*
  269. * If the buffer is pinned then push on the log so we won't
  270. * get stuck waiting in the write for someone, maybe
  271. * ourselves, to flush the log.
  272. *
  273. * Even though we just pushed the log above, we did not have
  274. * the superblock buffer locked at that point so it can
  275. * become pinned in between there and here.
  276. */
  277. if (XFS_BUF_ISPINNED(bp))
  278. xfs_log_force(mp, 0, XFS_LOG_FORCE);
  279. }
  280. if (flags & SYNC_WAIT)
  281. XFS_BUF_UNASYNC(bp);
  282. else
  283. XFS_BUF_ASYNC(bp);
  284. return xfs_bwrite(mp, bp);
  285. out_brelse:
  286. xfs_buf_relse(bp);
  287. out:
  288. return error;
  289. }
  290. /*
  291. * First stage of freeze - no more writers will make progress now we are here,
  292. * so we flush delwri and delalloc buffers here, then wait for all I/O to
  293. * complete. Data is frozen at that point. Metadata is not frozen,
  294. * transactions can still occur here so don't bother flushing the buftarg (i.e
  295. * SYNC_QUIESCE) because it'll just get dirty again.
  296. */
  297. int
  298. xfs_quiesce_data(
  299. struct xfs_mount *mp)
  300. {
  301. int error;
  302. /* push non-blocking */
  303. xfs_sync_inodes(mp, SYNC_DELWRI|SYNC_BDFLUSH);
  304. XFS_QM_DQSYNC(mp, SYNC_BDFLUSH);
  305. xfs_filestream_flush(mp);
  306. /* push and block */
  307. xfs_sync_inodes(mp, SYNC_DELWRI|SYNC_WAIT|SYNC_IOWAIT);
  308. XFS_QM_DQSYNC(mp, SYNC_WAIT);
  309. /* write superblock and hoover shutdown errors */
  310. error = xfs_sync_fsdata(mp, 0);
  311. /* flush devices */
  312. XFS_bflush(mp->m_ddev_targp);
  313. if (mp->m_rtdev_targp)
  314. XFS_bflush(mp->m_rtdev_targp);
  315. return error;
  316. }
  317. /*
  318. * xfs_sync flushes any pending I/O to file system vfsp.
  319. *
  320. * This routine is called by vfs_sync() to make sure that things make it
  321. * out to disk eventually, on sync() system calls to flush out everything,
  322. * and when the file system is unmounted. For the vfs_sync() case, all
  323. * we really need to do is sync out the log to make all of our meta-data
  324. * updates permanent (except for timestamps). For calls from pflushd(),
  325. * dirty pages are kept moving by calling pdflush() on the inodes
  326. * containing them. We also flush the inodes that we can lock without
  327. * sleeping and the superblock if we can lock it without sleeping from
  328. * vfs_sync() so that items at the tail of the log are always moving out.
  329. *
  330. * Flags:
  331. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  332. * to sleep if we can help it. All we really need
  333. * to do is ensure that the log is synced at least
  334. * periodically. We also push the inodes and
  335. * superblock if we can lock them without sleeping
  336. * and they are not pinned.
  337. * SYNC_ATTR - We need to flush the inodes. Now handled by direct calls
  338. * to xfs_sync_inodes().
  339. * SYNC_WAIT - All the flushes that take place in this call should
  340. * be synchronous.
  341. * SYNC_DELWRI - This tells us to push dirty pages associated with
  342. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  343. * determine if they should be flushed sync, async, or
  344. * delwri.
  345. * SYNC_CLOSE - This flag is passed when the system is being
  346. * unmounted. We should sync and invalidate everything.
  347. * SYNC_FSDATA - This indicates that the caller would like to make
  348. * sure the superblock is safe on disk. We can ensure
  349. * this by simply making sure the log gets flushed
  350. * if SYNC_BDFLUSH is set, and by actually writing it
  351. * out otherwise.
  352. * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
  353. * before we return (including direct I/O). Forms the drain
  354. * side of the write barrier needed to safely quiesce the
  355. * filesystem.
  356. *
  357. */
  358. int
  359. xfs_sync(
  360. xfs_mount_t *mp,
  361. int flags)
  362. {
  363. int error;
  364. int last_error = 0;
  365. uint log_flags = XFS_LOG_FORCE;
  366. ASSERT(!(flags & SYNC_ATTR));
  367. /*
  368. * Get the Quota Manager to flush the dquots.
  369. *
  370. * If XFS quota support is not enabled or this filesystem
  371. * instance does not use quotas XFS_QM_DQSYNC will always
  372. * return zero.
  373. */
  374. error = XFS_QM_DQSYNC(mp, flags);
  375. if (error) {
  376. /*
  377. * If we got an IO error, we will be shutting down.
  378. * So, there's nothing more for us to do here.
  379. */
  380. ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
  381. if (XFS_FORCED_SHUTDOWN(mp))
  382. return XFS_ERROR(error);
  383. }
  384. if (flags & SYNC_IOWAIT)
  385. xfs_filestream_flush(mp);
  386. /*
  387. * Sync out the log. This ensures that the log is periodically
  388. * flushed even if there is not enough activity to fill it up.
  389. */
  390. if (flags & SYNC_WAIT)
  391. log_flags |= XFS_LOG_SYNC;
  392. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  393. if (flags & SYNC_DELWRI) {
  394. if (flags & SYNC_BDFLUSH)
  395. xfs_finish_reclaim_all(mp, 1, XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  396. else
  397. error = xfs_sync_inodes(mp, flags);
  398. /*
  399. * Flushing out dirty data above probably generated more
  400. * log activity, so if this isn't vfs_sync() then flush
  401. * the log again.
  402. */
  403. xfs_log_force(mp, 0, log_flags);
  404. }
  405. if (flags & SYNC_FSDATA) {
  406. error = xfs_sync_fsdata(mp, flags);
  407. if (error)
  408. last_error = error;
  409. }
  410. /*
  411. * Now check to see if the log needs a "dummy" transaction.
  412. */
  413. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  414. error = xfs_commit_dummy_trans(mp, log_flags);
  415. if (error)
  416. return error;
  417. }
  418. /*
  419. * When shutting down, we need to insure that the AIL is pushed
  420. * to disk or the filesystem can appear corrupt from the PROM.
  421. */
  422. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  423. XFS_bflush(mp->m_ddev_targp);
  424. if (mp->m_rtdev_targp) {
  425. XFS_bflush(mp->m_rtdev_targp);
  426. }
  427. }
  428. return XFS_ERROR(last_error);
  429. }
  430. /*
  431. * Enqueue a work item to be picked up by the vfs xfssyncd thread.
  432. * Doing this has two advantages:
  433. * - It saves on stack space, which is tight in certain situations
  434. * - It can be used (with care) as a mechanism to avoid deadlocks.
  435. * Flushing while allocating in a full filesystem requires both.
  436. */
  437. STATIC void
  438. xfs_syncd_queue_work(
  439. struct xfs_mount *mp,
  440. void *data,
  441. void (*syncer)(struct xfs_mount *, void *))
  442. {
  443. struct bhv_vfs_sync_work *work;
  444. work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
  445. INIT_LIST_HEAD(&work->w_list);
  446. work->w_syncer = syncer;
  447. work->w_data = data;
  448. work->w_mount = mp;
  449. spin_lock(&mp->m_sync_lock);
  450. list_add_tail(&work->w_list, &mp->m_sync_list);
  451. spin_unlock(&mp->m_sync_lock);
  452. wake_up_process(mp->m_sync_task);
  453. }
  454. /*
  455. * Flush delayed allocate data, attempting to free up reserved space
  456. * from existing allocations. At this point a new allocation attempt
  457. * has failed with ENOSPC and we are in the process of scratching our
  458. * heads, looking about for more room...
  459. */
  460. STATIC void
  461. xfs_flush_inode_work(
  462. struct xfs_mount *mp,
  463. void *arg)
  464. {
  465. struct inode *inode = arg;
  466. filemap_flush(inode->i_mapping);
  467. iput(inode);
  468. }
  469. void
  470. xfs_flush_inode(
  471. xfs_inode_t *ip)
  472. {
  473. struct inode *inode = VFS_I(ip);
  474. igrab(inode);
  475. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
  476. delay(msecs_to_jiffies(500));
  477. }
  478. /*
  479. * This is the "bigger hammer" version of xfs_flush_inode_work...
  480. * (IOW, "If at first you don't succeed, use a Bigger Hammer").
  481. */
  482. STATIC void
  483. xfs_flush_device_work(
  484. struct xfs_mount *mp,
  485. void *arg)
  486. {
  487. struct inode *inode = arg;
  488. sync_blockdev(mp->m_super->s_bdev);
  489. iput(inode);
  490. }
  491. void
  492. xfs_flush_device(
  493. xfs_inode_t *ip)
  494. {
  495. struct inode *inode = VFS_I(ip);
  496. igrab(inode);
  497. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
  498. delay(msecs_to_jiffies(500));
  499. xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
  500. }
  501. /*
  502. * Every sync period we need to unpin all items, reclaim inodes, sync
  503. * quota and write out the superblock. We might need to cover the log
  504. * to indicate it is idle.
  505. */
  506. STATIC void
  507. xfs_sync_worker(
  508. struct xfs_mount *mp,
  509. void *unused)
  510. {
  511. int error;
  512. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  513. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  514. xfs_finish_reclaim_all(mp, 1, XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  515. /* dgc: errors ignored here */
  516. error = XFS_QM_DQSYNC(mp, SYNC_BDFLUSH);
  517. error = xfs_sync_fsdata(mp, SYNC_BDFLUSH);
  518. if (xfs_log_need_covered(mp))
  519. error = xfs_commit_dummy_trans(mp, XFS_LOG_FORCE);
  520. }
  521. mp->m_sync_seq++;
  522. wake_up(&mp->m_wait_single_sync_task);
  523. }
  524. STATIC int
  525. xfssyncd(
  526. void *arg)
  527. {
  528. struct xfs_mount *mp = arg;
  529. long timeleft;
  530. bhv_vfs_sync_work_t *work, *n;
  531. LIST_HEAD (tmp);
  532. set_freezable();
  533. timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
  534. for (;;) {
  535. timeleft = schedule_timeout_interruptible(timeleft);
  536. /* swsusp */
  537. try_to_freeze();
  538. if (kthread_should_stop() && list_empty(&mp->m_sync_list))
  539. break;
  540. spin_lock(&mp->m_sync_lock);
  541. /*
  542. * We can get woken by laptop mode, to do a sync -
  543. * that's the (only!) case where the list would be
  544. * empty with time remaining.
  545. */
  546. if (!timeleft || list_empty(&mp->m_sync_list)) {
  547. if (!timeleft)
  548. timeleft = xfs_syncd_centisecs *
  549. msecs_to_jiffies(10);
  550. INIT_LIST_HEAD(&mp->m_sync_work.w_list);
  551. list_add_tail(&mp->m_sync_work.w_list,
  552. &mp->m_sync_list);
  553. }
  554. list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
  555. list_move(&work->w_list, &tmp);
  556. spin_unlock(&mp->m_sync_lock);
  557. list_for_each_entry_safe(work, n, &tmp, w_list) {
  558. (*work->w_syncer)(mp, work->w_data);
  559. list_del(&work->w_list);
  560. if (work == &mp->m_sync_work)
  561. continue;
  562. kmem_free(work);
  563. }
  564. }
  565. return 0;
  566. }
  567. int
  568. xfs_syncd_init(
  569. struct xfs_mount *mp)
  570. {
  571. mp->m_sync_work.w_syncer = xfs_sync_worker;
  572. mp->m_sync_work.w_mount = mp;
  573. mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
  574. if (IS_ERR(mp->m_sync_task))
  575. return -PTR_ERR(mp->m_sync_task);
  576. return 0;
  577. }
  578. void
  579. xfs_syncd_stop(
  580. struct xfs_mount *mp)
  581. {
  582. kthread_stop(mp->m_sync_task);
  583. }