xfs_vfsops.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_da_btree.h"
  31. #include "xfs_bmap_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_alloc_btree.h"
  34. #include "xfs_dir2_sf.h"
  35. #include "xfs_attr_sf.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_inode_item.h"
  39. #include "xfs_btree.h"
  40. #include "xfs_alloc.h"
  41. #include "xfs_ialloc.h"
  42. #include "xfs_quota.h"
  43. #include "xfs_error.h"
  44. #include "xfs_bmap.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_buf_item.h"
  47. #include "xfs_log_priv.h"
  48. #include "xfs_dir2_trace.h"
  49. #include "xfs_extfree_item.h"
  50. #include "xfs_acl.h"
  51. #include "xfs_attr.h"
  52. #include "xfs_clnt.h"
  53. #include "xfs_mru_cache.h"
  54. #include "xfs_filestream.h"
  55. #include "xfs_fsops.h"
  56. #include "xfs_vnodeops.h"
  57. #include "xfs_vfsops.h"
  58. #include "xfs_utils.h"
  59. #include "xfs_sync.h"
  60. STATIC void
  61. xfs_quiesce_fs(
  62. xfs_mount_t *mp)
  63. {
  64. int count = 0, pincount;
  65. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  66. xfs_finish_reclaim_all(mp, 0);
  67. /* This loop must run at least twice.
  68. * The first instance of the loop will flush
  69. * most meta data but that will generate more
  70. * meta data (typically directory updates).
  71. * Which then must be flushed and logged before
  72. * we can write the unmount record.
  73. */
  74. do {
  75. xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
  76. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  77. if (!pincount) {
  78. delay(50);
  79. count++;
  80. }
  81. } while (count < 2);
  82. }
  83. /*
  84. * Second stage of a quiesce. The data is already synced, now we have to take
  85. * care of the metadata. New transactions are already blocked, so we need to
  86. * wait for any remaining transactions to drain out before proceding.
  87. */
  88. void
  89. xfs_attr_quiesce(
  90. xfs_mount_t *mp)
  91. {
  92. int error = 0;
  93. /* wait for all modifications to complete */
  94. while (atomic_read(&mp->m_active_trans) > 0)
  95. delay(100);
  96. /* flush inodes and push all remaining buffers out to disk */
  97. xfs_quiesce_fs(mp);
  98. ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
  99. /* Push the superblock and write an unmount record */
  100. error = xfs_log_sbcount(mp, 1);
  101. if (error)
  102. xfs_fs_cmn_err(CE_WARN, mp,
  103. "xfs_attr_quiesce: failed to log sb changes. "
  104. "Frozen image may not be consistent.");
  105. xfs_log_unmount_write(mp);
  106. xfs_unmountfs_writesb(mp);
  107. }
  108. /*
  109. * xfs_unmount_flush implements a set of flush operation on special
  110. * inodes, which are needed as a separate set of operations so that
  111. * they can be called as part of relocation process.
  112. */
  113. int
  114. xfs_unmount_flush(
  115. xfs_mount_t *mp, /* Mount structure we are getting
  116. rid of. */
  117. int relocation) /* Called from vfs relocation. */
  118. {
  119. xfs_inode_t *rip = mp->m_rootip;
  120. xfs_inode_t *rbmip;
  121. xfs_inode_t *rsumip = NULL;
  122. int error;
  123. xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
  124. xfs_iflock(rip);
  125. /*
  126. * Flush out the real time inodes.
  127. */
  128. if ((rbmip = mp->m_rbmip) != NULL) {
  129. xfs_ilock(rbmip, XFS_ILOCK_EXCL);
  130. xfs_iflock(rbmip);
  131. error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
  132. xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
  133. if (error == EFSCORRUPTED)
  134. goto fscorrupt_out;
  135. ASSERT(vn_count(VFS_I(rbmip)) == 1);
  136. rsumip = mp->m_rsumip;
  137. xfs_ilock(rsumip, XFS_ILOCK_EXCL);
  138. xfs_iflock(rsumip);
  139. error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
  140. xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
  141. if (error == EFSCORRUPTED)
  142. goto fscorrupt_out;
  143. ASSERT(vn_count(VFS_I(rsumip)) == 1);
  144. }
  145. /*
  146. * Synchronously flush root inode to disk
  147. */
  148. error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
  149. if (error == EFSCORRUPTED)
  150. goto fscorrupt_out2;
  151. if (vn_count(VFS_I(rip)) != 1 && !relocation) {
  152. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  153. return XFS_ERROR(EBUSY);
  154. }
  155. /*
  156. * Release dquot that rootinode, rbmino and rsumino might be holding,
  157. * flush and purge the quota inodes.
  158. */
  159. error = XFS_QM_UNMOUNT(mp);
  160. if (error == EFSCORRUPTED)
  161. goto fscorrupt_out2;
  162. if (rbmip) {
  163. IRELE(rbmip);
  164. IRELE(rsumip);
  165. }
  166. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  167. return 0;
  168. fscorrupt_out:
  169. xfs_ifunlock(rip);
  170. fscorrupt_out2:
  171. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  172. return XFS_ERROR(EFSCORRUPTED);
  173. }