Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_types.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_trans.h" |
| 25 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 26 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_dir2.h" |
| 28 | #include "xfs_dmapi.h" |
| 29 | #include "xfs_mount.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 30 | #include "xfs_da_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_bmap_btree.h" |
| 32 | #include "xfs_ialloc_btree.h" |
| 33 | #include "xfs_alloc_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_btree.h" |
| 40 | #include "xfs_alloc.h" |
| 41 | #include "xfs_ialloc.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 42 | #include "xfs_quota.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include "xfs_error.h" |
| 44 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "xfs_rw.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "xfs_buf_item.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 47 | #include "xfs_log_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include "xfs_dir2_trace.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 49 | #include "xfs_extfree_item.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include "xfs_acl.h" |
| 51 | #include "xfs_attr.h" |
| 52 | #include "xfs_clnt.h" |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 53 | #include "xfs_mru_cache.h" |
| 54 | #include "xfs_filestream.h" |
Christoph Hellwig | e13a73f | 2006-01-11 15:30:08 +1100 | [diff] [blame] | 55 | #include "xfs_fsops.h" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 56 | #include "xfs_vnodeops.h" |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 57 | #include "xfs_vfsops.h" |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 58 | #include "xfs_utils.h" |
David Chinner | fe4fa4b | 2008-10-30 17:06:08 +1100 | [diff] [blame^] | 59 | #include "xfs_sync.h" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
David Chinner | 3c85c36 | 2008-04-10 12:19:40 +1000 | [diff] [blame] | 62 | STATIC void |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 63 | xfs_quiesce_fs( |
| 64 | xfs_mount_t *mp) |
| 65 | { |
| 66 | int count = 0, pincount; |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 67 | |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 68 | xfs_flush_buftarg(mp->m_ddev_targp, 0); |
| 69 | xfs_finish_reclaim_all(mp, 0); |
| 70 | |
| 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. |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 77 | */ |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 78 | do { |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 79 | xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL); |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 80 | pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1); |
| 81 | if (!pincount) { |
| 82 | delay(50); |
| 83 | count++; |
| 84 | } |
| 85 | } while (count < 2); |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 88 | /* |
| 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. |
| 92 | */ |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 93 | void |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 94 | xfs_attr_quiesce( |
| 95 | xfs_mount_t *mp) |
| 96 | { |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 97 | int error = 0; |
| 98 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 99 | /* wait for all modifications to complete */ |
| 100 | while (atomic_read(&mp->m_active_trans) > 0) |
| 101 | delay(100); |
| 102 | |
| 103 | /* flush inodes and push all remaining buffers out to disk */ |
| 104 | xfs_quiesce_fs(mp); |
| 105 | |
| 106 | ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0); |
| 107 | |
| 108 | /* Push the superblock and write an unmount record */ |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 109 | error = xfs_log_sbcount(mp, 1); |
| 110 | if (error) |
| 111 | xfs_fs_cmn_err(CE_WARN, mp, |
| 112 | "xfs_attr_quiesce: failed to log sb changes. " |
| 113 | "Frozen image may not be consistent."); |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 114 | xfs_log_unmount_write(mp); |
| 115 | xfs_unmountfs_writesb(mp); |
| 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* |
| 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. |
| 122 | */ |
| 123 | int |
| 124 | xfs_unmount_flush( |
| 125 | xfs_mount_t *mp, /* Mount structure we are getting |
| 126 | rid of. */ |
| 127 | int relocation) /* Called from vfs relocation. */ |
| 128 | { |
| 129 | xfs_inode_t *rip = mp->m_rootip; |
| 130 | xfs_inode_t *rbmip; |
| 131 | xfs_inode_t *rsumip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | int error; |
| 133 | |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 134 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | xfs_iflock(rip); |
| 136 | |
| 137 | /* |
| 138 | * Flush out the real time inodes. |
| 139 | */ |
| 140 | if ((rbmip = mp->m_rbmip) != NULL) { |
| 141 | xfs_ilock(rbmip, XFS_ILOCK_EXCL); |
| 142 | xfs_iflock(rbmip); |
| 143 | error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC); |
| 144 | xfs_iunlock(rbmip, XFS_ILOCK_EXCL); |
| 145 | |
| 146 | if (error == EFSCORRUPTED) |
| 147 | goto fscorrupt_out; |
| 148 | |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 149 | ASSERT(vn_count(VFS_I(rbmip)) == 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | rsumip = mp->m_rsumip; |
| 152 | xfs_ilock(rsumip, XFS_ILOCK_EXCL); |
| 153 | xfs_iflock(rsumip); |
| 154 | error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC); |
| 155 | xfs_iunlock(rsumip, XFS_ILOCK_EXCL); |
| 156 | |
| 157 | if (error == EFSCORRUPTED) |
| 158 | goto fscorrupt_out; |
| 159 | |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 160 | ASSERT(vn_count(VFS_I(rsumip)) == 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Synchronously flush root inode to disk |
| 165 | */ |
| 166 | error = xfs_iflush(rip, XFS_IFLUSH_SYNC); |
| 167 | if (error == EFSCORRUPTED) |
| 168 | goto fscorrupt_out2; |
| 169 | |
Christoph Hellwig | df80c93 | 2008-08-13 16:22:09 +1000 | [diff] [blame] | 170 | if (vn_count(VFS_I(rip)) != 1 && !relocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 172 | return XFS_ERROR(EBUSY); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Release dquot that rootinode, rbmino and rsumino might be holding, |
| 177 | * flush and purge the quota inodes. |
| 178 | */ |
| 179 | error = XFS_QM_UNMOUNT(mp); |
| 180 | if (error == EFSCORRUPTED) |
| 181 | goto fscorrupt_out2; |
| 182 | |
| 183 | if (rbmip) { |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 184 | IRELE(rbmip); |
| 185 | IRELE(rsumip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 189 | return 0; |
| 190 | |
| 191 | fscorrupt_out: |
| 192 | xfs_ifunlock(rip); |
| 193 | |
| 194 | fscorrupt_out2: |
| 195 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 196 | |
| 197 | return XFS_ERROR(EFSCORRUPTED); |
| 198 | } |
| 199 | |