xfs_vfsops.c 3.4 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18
 */
#include "xfs.h"
19
#include "xfs_fs.h"
L
Linus Torvalds 已提交
20
#include "xfs_types.h"
21
#include "xfs_bit.h"
L
Linus Torvalds 已提交
22
#include "xfs_log.h"
23
#include "xfs_inum.h"
L
Linus Torvalds 已提交
24 25
#include "xfs_trans.h"
#include "xfs_sb.h"
26
#include "xfs_ag.h"
L
Linus Torvalds 已提交
27 28 29
#include "xfs_dir2.h"
#include "xfs_dmapi.h"
#include "xfs_mount.h"
30
#include "xfs_da_btree.h"
L
Linus Torvalds 已提交
31 32 33 34
#include "xfs_bmap_btree.h"
#include "xfs_ialloc_btree.h"
#include "xfs_alloc_btree.h"
#include "xfs_dir2_sf.h"
35
#include "xfs_attr_sf.h"
L
Linus Torvalds 已提交
36 37
#include "xfs_dinode.h"
#include "xfs_inode.h"
38 39 40 41 42
#include "xfs_inode_item.h"
#include "xfs_btree.h"
#include "xfs_alloc.h"
#include "xfs_ialloc.h"
#include "xfs_quota.h"
L
Linus Torvalds 已提交
43 44 45 46
#include "xfs_error.h"
#include "xfs_bmap.h"
#include "xfs_rw.h"
#include "xfs_buf_item.h"
47
#include "xfs_log_priv.h"
L
Linus Torvalds 已提交
48
#include "xfs_dir2_trace.h"
49
#include "xfs_extfree_item.h"
L
Linus Torvalds 已提交
50 51
#include "xfs_acl.h"
#include "xfs_attr.h"
52 53
#include "xfs_mru_cache.h"
#include "xfs_filestream.h"
54
#include "xfs_fsops.h"
55
#include "xfs_vnodeops.h"
56
#include "xfs_vfsops.h"
57
#include "xfs_utils.h"
58
#include "xfs_sync.h"
59

L
Linus Torvalds 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

/*
 * xfs_unmount_flush implements a set of flush operation on special
 * inodes, which are needed as a separate set of operations so that
 * they can be called as part of relocation process.
 */
int
xfs_unmount_flush(
	xfs_mount_t	*mp,		/* Mount structure we are getting
					   rid of. */
	int             relocation)	/* Called from vfs relocation. */
{
	xfs_inode_t	*rip = mp->m_rootip;
	xfs_inode_t	*rbmip;
	xfs_inode_t	*rsumip = NULL;
	int		error;

77
	xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
L
Linus Torvalds 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91
	xfs_iflock(rip);

	/*
	 * Flush out the real time inodes.
	 */
	if ((rbmip = mp->m_rbmip) != NULL) {
		xfs_ilock(rbmip, XFS_ILOCK_EXCL);
		xfs_iflock(rbmip);
		error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
		xfs_iunlock(rbmip, XFS_ILOCK_EXCL);

		if (error == EFSCORRUPTED)
			goto fscorrupt_out;

92
		ASSERT(vn_count(VFS_I(rbmip)) == 1);
L
Linus Torvalds 已提交
93 94 95 96 97 98 99 100 101 102

		rsumip = mp->m_rsumip;
		xfs_ilock(rsumip, XFS_ILOCK_EXCL);
		xfs_iflock(rsumip);
		error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
		xfs_iunlock(rsumip, XFS_ILOCK_EXCL);

		if (error == EFSCORRUPTED)
			goto fscorrupt_out;

103
		ASSERT(vn_count(VFS_I(rsumip)) == 1);
L
Linus Torvalds 已提交
104 105 106 107 108 109 110 111 112
	}

	/*
	 * Synchronously flush root inode to disk
	 */
	error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
	if (error == EFSCORRUPTED)
		goto fscorrupt_out2;

113
	if (vn_count(VFS_I(rip)) != 1 && !relocation) {
L
Linus Torvalds 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126
		xfs_iunlock(rip, XFS_ILOCK_EXCL);
		return XFS_ERROR(EBUSY);
	}

	/*
	 * Release dquot that rootinode, rbmino and rsumino might be holding,
	 * flush and purge the quota inodes.
	 */
	error = XFS_QM_UNMOUNT(mp);
	if (error == EFSCORRUPTED)
		goto fscorrupt_out2;

	if (rbmip) {
127 128
		IRELE(rbmip);
		IRELE(rsumip);
L
Linus Torvalds 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142
	}

	xfs_iunlock(rip, XFS_ILOCK_EXCL);
	return 0;

fscorrupt_out:
	xfs_ifunlock(rip);

fscorrupt_out2:
	xfs_iunlock(rip, XFS_ILOCK_EXCL);

	return XFS_ERROR(EFSCORRUPTED);
}