blob: 305d9f3948e03e773e7a53a88556b28b7fe1f8ed [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_trans.h"
25#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110026#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_dir2.h"
28#include "xfs_dmapi.h"
29#include "xfs_mount.h"
Nathan Scotta844f452005-11-02 14:38:42 +110030#include "xfs_da_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
32#include "xfs_ialloc_btree.h"
33#include "xfs_alloc_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110034#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "xfs_btree.h"
40#include "xfs_alloc.h"
41#include "xfs_ialloc.h"
Nathan Scotta844f452005-11-02 14:38:42 +110042#include "xfs_quota.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include "xfs_error.h"
44#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include "xfs_rw.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_buf_item.h"
Nathan Scotta844f452005-11-02 14:38:42 +110047#include "xfs_log_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include "xfs_dir2_trace.h"
Nathan Scotta844f452005-11-02 14:38:42 +110049#include "xfs_extfree_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include "xfs_acl.h"
51#include "xfs_attr.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100052#include "xfs_mru_cache.h"
53#include "xfs_filestream.h"
Christoph Hellwige13a73f2006-01-11 15:30:08 +110054#include "xfs_fsops.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100055#include "xfs_vnodeops.h"
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +100056#include "xfs_vfsops.h"
Christoph Hellwig43355092008-03-27 18:01:08 +110057#include "xfs_utils.h"
David Chinnerfe4fa4b2008-10-30 17:06:08 +110058#include "xfs_sync.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*
62 * xfs_unmount_flush implements a set of flush operation on special
63 * inodes, which are needed as a separate set of operations so that
64 * they can be called as part of relocation process.
65 */
66int
67xfs_unmount_flush(
68 xfs_mount_t *mp, /* Mount structure we are getting
69 rid of. */
70 int relocation) /* Called from vfs relocation. */
71{
72 xfs_inode_t *rip = mp->m_rootip;
73 xfs_inode_t *rbmip;
74 xfs_inode_t *rsumip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 int error;
76
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +100077 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 xfs_iflock(rip);
79
80 /*
81 * Flush out the real time inodes.
82 */
83 if ((rbmip = mp->m_rbmip) != NULL) {
84 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
85 xfs_iflock(rbmip);
86 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
87 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
88
89 if (error == EFSCORRUPTED)
90 goto fscorrupt_out;
91
David Chinnere4f75292008-08-13 16:00:45 +100092 ASSERT(vn_count(VFS_I(rbmip)) == 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 rsumip = mp->m_rsumip;
95 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
96 xfs_iflock(rsumip);
97 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
98 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
99
100 if (error == EFSCORRUPTED)
101 goto fscorrupt_out;
102
David Chinnere4f75292008-08-13 16:00:45 +1000103 ASSERT(vn_count(VFS_I(rsumip)) == 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
106 /*
107 * Synchronously flush root inode to disk
108 */
109 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
110 if (error == EFSCORRUPTED)
111 goto fscorrupt_out2;
112
Christoph Hellwigdf80c932008-08-13 16:22:09 +1000113 if (vn_count(VFS_I(rip)) != 1 && !relocation) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 xfs_iunlock(rip, XFS_ILOCK_EXCL);
115 return XFS_ERROR(EBUSY);
116 }
117
118 /*
119 * Release dquot that rootinode, rbmino and rsumino might be holding,
120 * flush and purge the quota inodes.
121 */
122 error = XFS_QM_UNMOUNT(mp);
123 if (error == EFSCORRUPTED)
124 goto fscorrupt_out2;
125
126 if (rbmip) {
Christoph Hellwig43355092008-03-27 18:01:08 +1100127 IRELE(rbmip);
128 IRELE(rsumip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130
131 xfs_iunlock(rip, XFS_ILOCK_EXCL);
132 return 0;
133
134fscorrupt_out:
135 xfs_ifunlock(rip);
136
137fscorrupt_out2:
138 xfs_iunlock(rip, XFS_ILOCK_EXCL);
139
140 return XFS_ERROR(EFSCORRUPTED);
141}
142