2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * 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.
14 * 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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_alloc_btree.h"
34 #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"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_quota.h"
43 #include "xfs_error.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_log_priv.h"
48 #include "xfs_dir2_trace.h"
49 #include "xfs_extfree_item.h"
53 #include "xfs_mru_cache.h"
54 #include "xfs_filestream.h"
55 #include "xfs_fsops.h"
56 #include "xfs_vnodeops.h"
57 #include "xfs_vfsops.h"
58 #include "xfs_utils.h"
66 int count = 0, pincount;
68 xfs_flush_buftarg(mp->m_ddev_targp, 0);
69 xfs_finish_reclaim_all(mp, 0, XFS_IFLUSH_DELWRI_ELSE_ASYNC);
71 /* This loop must run at least twice.
72 * The first instance of the loop will flush
73 * most meta data but that will generate more
74 * meta data (typically directory updates).
75 * Which then must be flushed and logged before
76 * we can write the unmount record.
79 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
80 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
89 * Second stage of a quiesce. The data is already synced, now we have to take
90 * care of the metadata. New transactions are already blocked, so we need to
91 * wait for any remaining transactions to drain out before proceding.
99 /* wait for all modifications to complete */
100 while (atomic_read(&mp->m_active_trans) > 0)
103 /* flush inodes and push all remaining buffers out to disk */
106 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
108 /* Push the superblock and write an unmount record */
109 error = xfs_log_sbcount(mp, 1);
111 xfs_fs_cmn_err(CE_WARN, mp,
112 "xfs_attr_quiesce: failed to log sb changes. "
113 "Frozen image may not be consistent.");
114 xfs_log_unmount_write(mp);
115 xfs_unmountfs_writesb(mp);
119 * xfs_unmount_flush implements a set of flush operation on special
120 * inodes, which are needed as a separate set of operations so that
121 * they can be called as part of relocation process.
125 xfs_mount_t *mp, /* Mount structure we are getting
127 int relocation) /* Called from vfs relocation. */
129 xfs_inode_t *rip = mp->m_rootip;
131 xfs_inode_t *rsumip = NULL;
134 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
138 * Flush out the real time inodes.
140 if ((rbmip = mp->m_rbmip) != NULL) {
141 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
143 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
144 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
146 if (error == EFSCORRUPTED)
149 ASSERT(vn_count(VFS_I(rbmip)) == 1);
151 rsumip = mp->m_rsumip;
152 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
154 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
155 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
157 if (error == EFSCORRUPTED)
160 ASSERT(vn_count(VFS_I(rsumip)) == 1);
164 * Synchronously flush root inode to disk
166 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
167 if (error == EFSCORRUPTED)
170 if (vn_count(VFS_I(rip)) != 1 && !relocation) {
171 xfs_iunlock(rip, XFS_ILOCK_EXCL);
172 return XFS_ERROR(EBUSY);
176 * Release dquot that rootinode, rbmino and rsumino might be holding,
177 * flush and purge the quota inodes.
179 error = XFS_QM_UNMOUNT(mp);
180 if (error == EFSCORRUPTED)
188 xfs_iunlock(rip, XFS_ILOCK_EXCL);
195 xfs_iunlock(rip, XFS_ILOCK_EXCL);
197 return XFS_ERROR(EFSCORRUPTED);