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