jfs_umount.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2004
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the 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 to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /*
  19. * jfs_umount.c
  20. *
  21. * note: file system in transition to aggregate/fileset:
  22. * (ref. jfs_mount.c)
  23. *
  24. * file system unmount is interpreted as mount of the single/only
  25. * fileset in the aggregate and, if unmount of the last fileset,
  26. * as unmount of the aggerate;
  27. */
  28. #include <linux/fs.h>
  29. #include "jfs_incore.h"
  30. #include "jfs_filsys.h"
  31. #include "jfs_superblock.h"
  32. #include "jfs_dmap.h"
  33. #include "jfs_imap.h"
  34. #include "jfs_metapage.h"
  35. #include "jfs_debug.h"
  36. /*
  37. * NAME: jfs_umount(vfsp, flags, crp)
  38. *
  39. * FUNCTION: vfs_umount()
  40. *
  41. * PARAMETERS: vfsp - virtual file system pointer
  42. * flags - unmount for shutdown
  43. * crp - credential
  44. *
  45. * RETURN : EBUSY - device has open files
  46. */
  47. int jfs_umount(struct super_block *sb)
  48. {
  49. struct jfs_sb_info *sbi = JFS_SBI(sb);
  50. struct inode *ipbmap = sbi->ipbmap;
  51. struct inode *ipimap = sbi->ipimap;
  52. struct inode *ipaimap = sbi->ipaimap;
  53. struct inode *ipaimap2 = sbi->ipaimap2;
  54. struct jfs_log *log;
  55. int rc = 0;
  56. jfs_info("UnMount JFS: sb:0x%p", sb);
  57. /*
  58. * update superblock and close log
  59. *
  60. * if mounted read-write and log based recovery was enabled
  61. */
  62. if ((log = sbi->log))
  63. /*
  64. * Wait for outstanding transactions to be written to log:
  65. */
  66. jfs_flush_journal(log, 1);
  67. /*
  68. * close fileset inode allocation map (aka fileset inode)
  69. */
  70. diUnmount(ipimap, 0);
  71. diFreeSpecial(ipimap);
  72. sbi->ipimap = NULL;
  73. /*
  74. * close secondary aggregate inode allocation map
  75. */
  76. ipaimap2 = sbi->ipaimap2;
  77. if (ipaimap2) {
  78. diUnmount(ipaimap2, 0);
  79. diFreeSpecial(ipaimap2);
  80. sbi->ipaimap2 = NULL;
  81. }
  82. /*
  83. * close aggregate inode allocation map
  84. */
  85. ipaimap = sbi->ipaimap;
  86. diUnmount(ipaimap, 0);
  87. diFreeSpecial(ipaimap);
  88. sbi->ipaimap = NULL;
  89. /*
  90. * close aggregate block allocation map
  91. */
  92. dbUnmount(ipbmap, 0);
  93. diFreeSpecial(ipbmap);
  94. sbi->ipimap = NULL;
  95. /*
  96. * Make sure all metadata makes it to disk before we mark
  97. * the superblock as clean
  98. */
  99. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  100. /*
  101. * ensure all file system file pages are propagated to their
  102. * home blocks on disk (and their in-memory buffer pages are
  103. * invalidated) BEFORE updating file system superblock state
  104. * (to signify file system is unmounted cleanly, and thus in
  105. * consistent state) and log superblock active file system
  106. * list (to signify skip logredo()).
  107. */
  108. if (log) { /* log = NULL if read-only mount */
  109. updateSuper(sb, FM_CLEAN);
  110. /*
  111. * close log:
  112. *
  113. * remove file system from log active file system list.
  114. */
  115. rc = lmLogClose(sb);
  116. }
  117. jfs_info("UnMount JFS Complete: rc = %d", rc);
  118. return rc;
  119. }
  120. int jfs_umount_rw(struct super_block *sb)
  121. {
  122. struct jfs_sb_info *sbi = JFS_SBI(sb);
  123. struct jfs_log *log = sbi->log;
  124. if (!log)
  125. return 0;
  126. /*
  127. * close log:
  128. *
  129. * remove file system from log active file system list.
  130. */
  131. jfs_flush_journal(log, 1);
  132. /*
  133. * Make sure all metadata makes it to disk
  134. */
  135. dbSync(sbi->ipbmap);
  136. diSync(sbi->ipimap);
  137. /*
  138. * Note that we have to do this even if sync_blockdev() will
  139. * do exactly the same a few instructions later: We can't
  140. * mark the superblock clean before everything is flushed to
  141. * disk.
  142. */
  143. filemap_write_and_wait(sbi->direct_inode->i_mapping);
  144. updateSuper(sb, FM_CLEAN);
  145. return lmLogClose(sb);
  146. }