jfs_umount.c 3.3 KB

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