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" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Lachlan McIlroy | de2eeea | 2008-02-06 13:37:56 +1100 | [diff] [blame] | 61 | int __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | xfs_init(void) |
| 63 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #ifdef XFS_DABUF_DEBUG |
Eric Sandeen | 703e1f0 | 2007-10-11 17:41:21 +1000 | [diff] [blame] | 65 | extern spinlock_t xfs_dabuf_global_lock; |
Eric Sandeen | 007c61c | 2007-10-11 17:43:56 +1000 | [diff] [blame] | 66 | spin_lock_init(&xfs_dabuf_global_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | /* |
| 70 | * Initialize all of the zone allocators we use. |
| 71 | */ |
David Chinner | eb01c9c | 2008-04-10 12:18:46 +1000 | [diff] [blame] | 72 | xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t), |
| 73 | "xfs_log_ticket"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), |
David Chinner | eb01c9c | 2008-04-10 12:18:46 +1000 | [diff] [blame] | 75 | "xfs_bmap_free_item"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), |
David Chinner | eb01c9c | 2008-04-10 12:18:46 +1000 | [diff] [blame] | 77 | "xfs_btree_cur"); |
| 78 | xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t), |
| 79 | "xfs_da_state"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 81 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); |
David Chinner | eb01c9c | 2008-04-10 12:18:46 +1000 | [diff] [blame] | 82 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 83 | xfs_acl_zone_init(xfs_acl_zone, "xfs_acl"); |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 84 | xfs_mru_cache_init(); |
| 85 | xfs_filestream_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * The size of the zone allocated buf log item is the maximum |
| 89 | * size possible under XFS. This wastes a little bit of memory, |
| 90 | * but it is much faster. |
| 91 | */ |
| 92 | xfs_buf_item_zone = |
| 93 | kmem_zone_init((sizeof(xfs_buf_log_item_t) + |
| 94 | (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) / |
| 95 | NBWORD) * sizeof(int))), |
| 96 | "xfs_buf_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 97 | xfs_efd_zone = |
| 98 | kmem_zone_init((sizeof(xfs_efd_log_item_t) + |
| 99 | ((XFS_EFD_MAX_FAST_EXTENTS - 1) * |
| 100 | sizeof(xfs_extent_t))), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | "xfs_efd_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 102 | xfs_efi_zone = |
| 103 | kmem_zone_init((sizeof(xfs_efi_log_item_t) + |
| 104 | ((XFS_EFI_MAX_FAST_EXTENTS - 1) * |
| 105 | sizeof(xfs_extent_t))), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | "xfs_efi_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * These zones warrant special memory allocator hints |
| 110 | */ |
| 111 | xfs_inode_zone = |
| 112 | kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", |
| 113 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
| 114 | KM_ZONE_SPREAD, NULL); |
| 115 | xfs_ili_zone = |
| 116 | kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili", |
| 117 | KM_ZONE_SPREAD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Allocate global trace buffers. |
| 121 | */ |
| 122 | #ifdef XFS_ALLOC_TRACE |
| 123 | xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP); |
| 124 | #endif |
| 125 | #ifdef XFS_BMAP_TRACE |
| 126 | xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP); |
| 127 | #endif |
| 128 | #ifdef XFS_BMBT_TRACE |
| 129 | xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP); |
| 130 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #ifdef XFS_ATTR_TRACE |
| 132 | xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP); |
| 133 | #endif |
| 134 | #ifdef XFS_DIR2_TRACE |
| 135 | xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP); |
| 136 | #endif |
| 137 | |
| 138 | xfs_dir_startup(); |
| 139 | |
| 140 | #if (defined(DEBUG) || defined(INDUCE_IO_ERROR)) |
| 141 | xfs_error_test_init(); |
| 142 | #endif /* DEBUG || INDUCE_IO_ERROR */ |
| 143 | |
| 144 | xfs_init_procfs(); |
| 145 | xfs_sysctl_register(); |
| 146 | return 0; |
| 147 | } |
| 148 | |
Lachlan McIlroy | de2eeea | 2008-02-06 13:37:56 +1100 | [diff] [blame] | 149 | void __exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | xfs_cleanup(void) |
| 151 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | extern kmem_zone_t *xfs_inode_zone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | extern kmem_zone_t *xfs_efd_zone; |
| 154 | extern kmem_zone_t *xfs_efi_zone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | xfs_cleanup_procfs(); |
| 157 | xfs_sysctl_unregister(); |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 158 | xfs_filestream_uninit(); |
| 159 | xfs_mru_cache_uninit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | xfs_acl_zone_destroy(xfs_acl_zone); |
| 161 | |
| 162 | #ifdef XFS_DIR2_TRACE |
| 163 | ktrace_free(xfs_dir2_trace_buf); |
| 164 | #endif |
| 165 | #ifdef XFS_ATTR_TRACE |
| 166 | ktrace_free(xfs_attr_trace_buf); |
| 167 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #ifdef XFS_BMBT_TRACE |
| 169 | ktrace_free(xfs_bmbt_trace_buf); |
| 170 | #endif |
| 171 | #ifdef XFS_BMAP_TRACE |
| 172 | ktrace_free(xfs_bmap_trace_buf); |
| 173 | #endif |
| 174 | #ifdef XFS_ALLOC_TRACE |
| 175 | ktrace_free(xfs_alloc_trace_buf); |
| 176 | #endif |
| 177 | |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 178 | kmem_zone_destroy(xfs_bmap_free_item_zone); |
| 179 | kmem_zone_destroy(xfs_btree_cur_zone); |
| 180 | kmem_zone_destroy(xfs_inode_zone); |
| 181 | kmem_zone_destroy(xfs_trans_zone); |
| 182 | kmem_zone_destroy(xfs_da_state_zone); |
| 183 | kmem_zone_destroy(xfs_dabuf_zone); |
| 184 | kmem_zone_destroy(xfs_buf_item_zone); |
| 185 | kmem_zone_destroy(xfs_efd_zone); |
| 186 | kmem_zone_destroy(xfs_efi_zone); |
| 187 | kmem_zone_destroy(xfs_ifork_zone); |
| 188 | kmem_zone_destroy(xfs_ili_zone); |
Alexey Dobriyan | fe0754f | 2008-04-29 12:53:08 +1000 | [diff] [blame] | 189 | kmem_zone_destroy(xfs_log_ticket_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * xfs_start_flags |
| 194 | * |
| 195 | * This function fills in xfs_mount_t fields based on mount args. |
| 196 | * Note: the superblock has _not_ yet been read in. |
| 197 | */ |
| 198 | STATIC int |
| 199 | xfs_start_flags( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct xfs_mount_args *ap, |
| 201 | struct xfs_mount *mp) |
| 202 | { |
| 203 | /* Values are in BBs */ |
| 204 | if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 205 | /* |
| 206 | * At this point the superblock has not been read |
| 207 | * in, therefore we do not know the block size. |
| 208 | * Before the mount call ends we will convert |
| 209 | * these to FSBs. |
| 210 | */ |
| 211 | mp->m_dalign = ap->sunit; |
| 212 | mp->m_swidth = ap->swidth; |
| 213 | } |
| 214 | |
| 215 | if (ap->logbufs != -1 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | ap->logbufs != 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | (ap->logbufs < XLOG_MIN_ICLOGS || |
| 218 | ap->logbufs > XLOG_MAX_ICLOGS)) { |
| 219 | cmn_err(CE_WARN, |
| 220 | "XFS: invalid logbufs value: %d [not %d-%d]", |
| 221 | ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); |
| 222 | return XFS_ERROR(EINVAL); |
| 223 | } |
| 224 | mp->m_logbufs = ap->logbufs; |
| 225 | if (ap->logbufsize != -1 && |
Nathan Scott | cfcbbbd | 2005-11-02 15:12:04 +1100 | [diff] [blame] | 226 | ap->logbufsize != 0 && |
Eric Sandeen | dcb3b83 | 2007-08-16 16:25:33 +1000 | [diff] [blame] | 227 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || |
| 228 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || |
| 229 | !is_power_of_2(ap->logbufsize))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | cmn_err(CE_WARN, |
| 231 | "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", |
| 232 | ap->logbufsize); |
| 233 | return XFS_ERROR(EINVAL); |
| 234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | mp->m_logbsize = ap->logbufsize; |
| 236 | mp->m_fsname_len = strlen(ap->fsname) + 1; |
| 237 | mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP); |
| 238 | strcpy(mp->m_fsname, ap->fsname); |
Nathan Scott | fc1f8c1 | 2005-11-02 11:44:33 +1100 | [diff] [blame] | 239 | if (ap->rtname[0]) { |
| 240 | mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP); |
| 241 | strcpy(mp->m_rtname, ap->rtname); |
| 242 | } |
| 243 | if (ap->logname[0]) { |
| 244 | mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP); |
| 245 | strcpy(mp->m_logname, ap->logname); |
| 246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | if (ap->flags & XFSMNT_WSYNC) |
| 249 | mp->m_flags |= XFS_MOUNT_WSYNC; |
| 250 | #if XFS_BIG_INUMS |
| 251 | if (ap->flags & XFSMNT_INO64) { |
| 252 | mp->m_flags |= XFS_MOUNT_INO64; |
| 253 | mp->m_inoadd = XFS_INO64_OFFSET; |
| 254 | } |
| 255 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (ap->flags & XFSMNT_RETERR) |
| 257 | mp->m_flags |= XFS_MOUNT_RETERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (ap->flags & XFSMNT_NOALIGN) |
| 259 | mp->m_flags |= XFS_MOUNT_NOALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (ap->flags & XFSMNT_SWALLOC) |
| 261 | mp->m_flags |= XFS_MOUNT_SWALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (ap->flags & XFSMNT_OSYNCISOSYNC) |
| 263 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if (ap->flags & XFSMNT_32BITINODES) |
Nathan Scott | c11e2c3 | 2005-11-02 15:11:45 +1100 | [diff] [blame] | 265 | mp->m_flags |= XFS_MOUNT_32BITINODES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | if (ap->flags & XFSMNT_IOSIZE) { |
| 268 | if (ap->iosizelog > XFS_MAX_IO_LOG || |
| 269 | ap->iosizelog < XFS_MIN_IO_LOG) { |
| 270 | cmn_err(CE_WARN, |
| 271 | "XFS: invalid log iosize: %d [not %d-%d]", |
| 272 | ap->iosizelog, XFS_MIN_IO_LOG, |
| 273 | XFS_MAX_IO_LOG); |
| 274 | return XFS_ERROR(EINVAL); |
| 275 | } |
| 276 | |
| 277 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; |
| 278 | mp->m_readio_log = mp->m_writeio_log = ap->iosizelog; |
| 279 | } |
| 280 | |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 281 | if (ap->flags & XFSMNT_IKEEP) |
| 282 | mp->m_flags |= XFS_MOUNT_IKEEP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (ap->flags & XFSMNT_DIRSYNC) |
| 284 | mp->m_flags |= XFS_MOUNT_DIRSYNC; |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 285 | if (ap->flags & XFSMNT_ATTR2) |
| 286 | mp->m_flags |= XFS_MOUNT_ATTR2; |
David Chinner | e8c8b3a | 2005-11-02 10:33:05 +1100 | [diff] [blame] | 287 | |
Nathan Scott | e718eeb4 | 2005-11-02 15:09:22 +1100 | [diff] [blame] | 288 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) |
| 289 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* |
| 292 | * no recovery flag requires a read-only mount |
| 293 | */ |
| 294 | if (ap->flags & XFSMNT_NORECOVERY) { |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 295 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | cmn_err(CE_WARN, |
| 297 | "XFS: tried to mount a FS read-write without recovery!"); |
| 298 | return XFS_ERROR(EINVAL); |
| 299 | } |
| 300 | mp->m_flags |= XFS_MOUNT_NORECOVERY; |
| 301 | } |
| 302 | |
| 303 | if (ap->flags & XFSMNT_NOUUID) |
| 304 | mp->m_flags |= XFS_MOUNT_NOUUID; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 305 | if (ap->flags & XFSMNT_BARRIER) |
| 306 | mp->m_flags |= XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 307 | else |
| 308 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 310 | if (ap->flags2 & XFSMNT2_FILESTREAMS) |
| 311 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
| 312 | |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 313 | if (ap->flags & XFSMNT_DMAPI) |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 314 | mp->m_flags |= XFS_MOUNT_DMAPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * This function fills in xfs_mount_t fields based on mount args. |
| 320 | * Note: the superblock _has_ now been read in. |
| 321 | */ |
| 322 | STATIC int |
| 323 | xfs_finish_flags( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | struct xfs_mount_args *ap, |
| 325 | struct xfs_mount *mp) |
| 326 | { |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 327 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | /* Fail a mount where the logbuf is smaller then the log stripe */ |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 330 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { |
Nathan Scott | c2cd255 | 2006-01-11 15:35:32 +1100 | [diff] [blame] | 331 | if ((ap->logbufsize <= 0) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { |
| 333 | mp->m_logbsize = mp->m_sb.sb_logsunit; |
Nathan Scott | c2cd255 | 2006-01-11 15:35:32 +1100 | [diff] [blame] | 334 | } else if (ap->logbufsize > 0 && |
| 335 | ap->logbufsize < mp->m_sb.sb_logsunit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | cmn_err(CE_WARN, |
| 337 | "XFS: logbuf size must be greater than or equal to log stripe size"); |
| 338 | return XFS_ERROR(EINVAL); |
| 339 | } |
| 340 | } else { |
| 341 | /* Fail a mount if the logbuf is larger than 32K */ |
| 342 | if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) { |
| 343 | cmn_err(CE_WARN, |
| 344 | "XFS: logbuf size for version 1 logs must be 16K or 32K"); |
| 345 | return XFS_ERROR(EINVAL); |
| 346 | } |
| 347 | } |
| 348 | |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 349 | if (xfs_sb_version_hasattr2(&mp->m_sb)) |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 350 | mp->m_flags |= XFS_MOUNT_ATTR2; |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* |
| 353 | * prohibit r/w mounts of read-only filesystems |
| 354 | */ |
| 355 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { |
| 356 | cmn_err(CE_WARN, |
| 357 | "XFS: cannot mount a read-only filesystem as read-write"); |
| 358 | return XFS_ERROR(EROFS); |
| 359 | } |
| 360 | |
| 361 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | * check for shared mount. |
| 363 | */ |
| 364 | if (ap->flags & XFSMNT_SHARED) { |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 365 | if (!xfs_sb_version_hasshared(&mp->m_sb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return XFS_ERROR(EINVAL); |
| 367 | |
| 368 | /* |
| 369 | * For IRIX 6.5, shared mounts must have the shared |
| 370 | * version bit set, have the persistent readonly |
| 371 | * field set, must be version 0 and can only be mounted |
| 372 | * read-only. |
| 373 | */ |
| 374 | if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) || |
| 375 | (mp->m_sb.sb_shared_vn != 0)) |
| 376 | return XFS_ERROR(EINVAL); |
| 377 | |
| 378 | mp->m_flags |= XFS_MOUNT_SHARED; |
| 379 | |
| 380 | /* |
| 381 | * Shared XFS V0 can't deal with DMI. Return EINVAL. |
| 382 | */ |
| 383 | if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI)) |
| 384 | return XFS_ERROR(EINVAL); |
| 385 | } |
| 386 | |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 387 | if (ap->flags & XFSMNT_UQUOTA) { |
| 388 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); |
| 389 | if (ap->flags & XFSMNT_UQUOTAENF) |
| 390 | mp->m_qflags |= XFS_UQUOTA_ENFD; |
| 391 | } |
| 392 | |
| 393 | if (ap->flags & XFSMNT_GQUOTA) { |
| 394 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); |
| 395 | if (ap->flags & XFSMNT_GQUOTAENF) |
| 396 | mp->m_qflags |= XFS_OQUOTA_ENFD; |
| 397 | } else if (ap->flags & XFSMNT_PQUOTA) { |
| 398 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); |
| 399 | if (ap->flags & XFSMNT_PQUOTAENF) |
| 400 | mp->m_qflags |= XFS_OQUOTA_ENFD; |
| 401 | } |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * xfs_mount |
| 408 | * |
| 409 | * The file system configurations are: |
| 410 | * (1) device (partition) with data and internal log |
| 411 | * (2) logical volume with data and log subvolumes. |
| 412 | * (3) logical volume with data, log, and realtime subvolumes. |
| 413 | * |
| 414 | * We only have to handle opening the log and realtime volumes here if |
| 415 | * they are present. The data subvolume has already been opened by |
| 416 | * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev. |
| 417 | */ |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 418 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | xfs_mount( |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 420 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | struct xfs_mount_args *args, |
| 422 | cred_t *credp) |
| 423 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | struct block_device *ddev, *logdev, *rtdev; |
| 425 | int flags = 0, error; |
| 426 | |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 427 | ddev = mp->m_super->s_bdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | logdev = rtdev = NULL; |
| 429 | |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 430 | error = xfs_dmops_get(mp, args); |
| 431 | if (error) |
| 432 | return error; |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 433 | error = xfs_qmops_get(mp, args); |
| 434 | if (error) |
| 435 | return error; |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 436 | |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 437 | if (args->flags & XFSMNT_QUIET) |
| 438 | flags |= XFS_MFSI_QUIET; |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | /* |
| 441 | * Open real time and log devices - order is important. |
| 442 | */ |
| 443 | if (args->logname[0]) { |
| 444 | error = xfs_blkdev_get(mp, args->logname, &logdev); |
| 445 | if (error) |
| 446 | return error; |
| 447 | } |
| 448 | if (args->rtname[0]) { |
| 449 | error = xfs_blkdev_get(mp, args->rtname, &rtdev); |
| 450 | if (error) { |
| 451 | xfs_blkdev_put(logdev); |
| 452 | return error; |
| 453 | } |
| 454 | |
| 455 | if (rtdev == ddev || rtdev == logdev) { |
| 456 | cmn_err(CE_WARN, |
| 457 | "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev."); |
| 458 | xfs_blkdev_put(logdev); |
| 459 | xfs_blkdev_put(rtdev); |
| 460 | return EINVAL; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Setup xfs_mount buffer target pointers |
| 466 | */ |
| 467 | error = ENOMEM; |
| 468 | mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0); |
| 469 | if (!mp->m_ddev_targp) { |
| 470 | xfs_blkdev_put(logdev); |
| 471 | xfs_blkdev_put(rtdev); |
| 472 | return error; |
| 473 | } |
| 474 | if (rtdev) { |
| 475 | mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1); |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame] | 476 | if (!mp->m_rtdev_targp) { |
| 477 | xfs_blkdev_put(logdev); |
| 478 | xfs_blkdev_put(rtdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | goto error0; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame] | 480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | mp->m_logdev_targp = (logdev && logdev != ddev) ? |
| 483 | xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame] | 484 | if (!mp->m_logdev_targp) { |
| 485 | xfs_blkdev_put(logdev); |
| 486 | xfs_blkdev_put(rtdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | goto error0; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame] | 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | /* |
| 491 | * Setup flags based on mount(2) options and then the superblock |
| 492 | */ |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 493 | error = xfs_start_flags(args, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (error) |
| 495 | goto error1; |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 496 | error = xfs_readsb(mp, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (error) |
| 498 | goto error1; |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 499 | error = xfs_finish_flags(args, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (error) |
| 501 | goto error2; |
| 502 | |
| 503 | /* |
| 504 | * Setup xfs_mount buffer target pointers based on superblock |
| 505 | */ |
| 506 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize, |
| 507 | mp->m_sb.sb_sectsize); |
| 508 | if (!error && logdev && logdev != ddev) { |
| 509 | unsigned int log_sector_size = BBSIZE; |
| 510 | |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 511 | if (xfs_sb_version_hassector(&mp->m_sb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | log_sector_size = mp->m_sb.sb_logsectsize; |
| 513 | error = xfs_setsize_buftarg(mp->m_logdev_targp, |
| 514 | mp->m_sb.sb_blocksize, |
| 515 | log_sector_size); |
| 516 | } |
| 517 | if (!error && rtdev) |
| 518 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, |
| 519 | mp->m_sb.sb_blocksize, |
| 520 | mp->m_sb.sb_sectsize); |
| 521 | if (error) |
| 522 | goto error2; |
| 523 | |
Nathan Scott | b2ea401 | 2006-07-28 17:05:13 +1000 | [diff] [blame] | 524 | if (mp->m_flags & XFS_MOUNT_BARRIER) |
Christoph Hellwig | c7d437d | 2006-01-11 15:28:56 +1100 | [diff] [blame] | 525 | xfs_mountfs_check_barriers(mp); |
| 526 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 527 | if ((error = xfs_filestream_mount(mp))) |
| 528 | goto error2; |
| 529 | |
Lachlan McIlroy | 541d7d3 | 2007-10-11 17:34:33 +1000 | [diff] [blame] | 530 | error = xfs_mountfs(mp, flags); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 531 | if (error) |
| 532 | goto error2; |
| 533 | |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 534 | XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname); |
| 535 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 536 | return 0; |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | error2: |
| 539 | if (mp->m_sb_bp) |
| 540 | xfs_freesb(mp); |
| 541 | error1: |
| 542 | xfs_binval(mp->m_ddev_targp); |
| 543 | if (logdev && logdev != ddev) |
| 544 | xfs_binval(mp->m_logdev_targp); |
| 545 | if (rtdev) |
| 546 | xfs_binval(mp->m_rtdev_targp); |
| 547 | error0: |
| 548 | xfs_unmountfs_close(mp, credp); |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 549 | xfs_qmops_put(mp); |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 550 | xfs_dmops_put(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return error; |
| 552 | } |
| 553 | |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 554 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | xfs_unmount( |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 556 | xfs_mount_t *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | int flags, |
| 558 | cred_t *credp) |
| 559 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | xfs_inode_t *rip; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 561 | bhv_vnode_t *rvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | int unmount_event_wanted = 0; |
| 563 | int unmount_event_flags = 0; |
| 564 | int xfs_unmountfs_needed = 0; |
| 565 | int error; |
| 566 | |
| 567 | rip = mp->m_rootip; |
| 568 | rvp = XFS_ITOV(rip); |
| 569 | |
Eric Sandeen | 948c6d4f | 2007-08-23 16:19:57 +1000 | [diff] [blame] | 570 | #ifdef HAVE_DMAPI |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 571 | if (mp->m_flags & XFS_MOUNT_DMAPI) { |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 572 | error = XFS_SEND_PREUNMOUNT(mp, |
Christoph Hellwig | bc4ac74 | 2008-03-06 13:45:58 +1100 | [diff] [blame] | 573 | rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | NULL, NULL, 0, 0, |
| 575 | (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))? |
| 576 | 0:DM_FLAGS_UNWANTED); |
| 577 | if (error) |
| 578 | return XFS_ERROR(error); |
| 579 | unmount_event_wanted = 1; |
| 580 | unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))? |
| 581 | 0 : DM_FLAGS_UNWANTED; |
| 582 | } |
Eric Sandeen | 948c6d4f | 2007-08-23 16:19:57 +1000 | [diff] [blame] | 583 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 585 | /* |
| 586 | * Blow away any referenced inode in the filestreams cache. |
| 587 | * This can and will cause log traffic as inodes go inactive |
| 588 | * here. |
| 589 | */ |
| 590 | xfs_filestream_unmount(mp); |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | XFS_bflush(mp->m_ddev_targp); |
| 593 | error = xfs_unmount_flush(mp, 0); |
| 594 | if (error) |
| 595 | goto out; |
| 596 | |
| 597 | ASSERT(vn_count(rvp) == 1); |
| 598 | |
| 599 | /* |
| 600 | * Drop the reference count |
| 601 | */ |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 602 | IRELE(rip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * If we're forcing a shutdown, typically because of a media error, |
| 606 | * we want to make sure we invalidate dirty pages that belong to |
| 607 | * referenced vnodes as well. |
| 608 | */ |
| 609 | if (XFS_FORCED_SHUTDOWN(mp)) { |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 610 | error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | ASSERT(error != EFSCORRUPTED); |
| 612 | } |
| 613 | xfs_unmountfs_needed = 1; |
| 614 | |
| 615 | out: |
| 616 | /* Send DMAPI event, if required. |
| 617 | * Then do xfs_unmountfs() if needed. |
| 618 | * Then return error (or zero). |
| 619 | */ |
| 620 | if (unmount_event_wanted) { |
| 621 | /* Note: mp structure must still exist for |
| 622 | * XFS_SEND_UNMOUNT() call. |
| 623 | */ |
Christoph Hellwig | bc4ac74 | 2008-03-06 13:45:58 +1100 | [diff] [blame] | 624 | XFS_SEND_UNMOUNT(mp, error == 0 ? rip : NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | DM_RIGHT_NULL, 0, error, unmount_event_flags); |
| 626 | } |
| 627 | if (xfs_unmountfs_needed) { |
| 628 | /* |
| 629 | * Call common unmount function to flush to disk |
| 630 | * and free the super block buffer & mount structures. |
| 631 | */ |
| 632 | xfs_unmountfs(mp, credp); |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 633 | xfs_qmops_put(mp); |
Christoph Hellwig | 293688e | 2007-08-29 11:59:36 +1000 | [diff] [blame] | 634 | xfs_dmops_put(mp); |
Christoph Hellwig | f541d27 | 2007-08-29 11:53:22 +1000 | [diff] [blame] | 635 | kmem_free(mp, sizeof(xfs_mount_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return XFS_ERROR(error); |
| 639 | } |
| 640 | |
David Chinner | 3c85c36 | 2008-04-10 12:19:40 +1000 | [diff] [blame] | 641 | STATIC void |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 642 | xfs_quiesce_fs( |
| 643 | xfs_mount_t *mp) |
| 644 | { |
| 645 | int count = 0, pincount; |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 646 | |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 647 | xfs_flush_buftarg(mp->m_ddev_targp, 0); |
| 648 | xfs_finish_reclaim_all(mp, 0); |
| 649 | |
| 650 | /* This loop must run at least twice. |
| 651 | * The first instance of the loop will flush |
| 652 | * most meta data but that will generate more |
| 653 | * meta data (typically directory updates). |
| 654 | * Which then must be flushed and logged before |
| 655 | * we can write the unmount record. |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 656 | */ |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 657 | do { |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 658 | xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL); |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 659 | pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1); |
| 660 | if (!pincount) { |
| 661 | delay(50); |
| 662 | count++; |
| 663 | } |
| 664 | } while (count < 2); |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 667 | /* |
| 668 | * Second stage of a quiesce. The data is already synced, now we have to take |
| 669 | * care of the metadata. New transactions are already blocked, so we need to |
| 670 | * wait for any remaining transactions to drain out before proceding. |
| 671 | */ |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 672 | void |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 673 | xfs_attr_quiesce( |
| 674 | xfs_mount_t *mp) |
| 675 | { |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 676 | int error = 0; |
| 677 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 678 | /* wait for all modifications to complete */ |
| 679 | while (atomic_read(&mp->m_active_trans) > 0) |
| 680 | delay(100); |
| 681 | |
| 682 | /* flush inodes and push all remaining buffers out to disk */ |
| 683 | xfs_quiesce_fs(mp); |
| 684 | |
| 685 | ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0); |
| 686 | |
| 687 | /* Push the superblock and write an unmount record */ |
David Chinner | e5720ee | 2008-04-10 12:21:18 +1000 | [diff] [blame] | 688 | error = xfs_log_sbcount(mp, 1); |
| 689 | if (error) |
| 690 | xfs_fs_cmn_err(CE_WARN, mp, |
| 691 | "xfs_attr_quiesce: failed to log sb changes. " |
| 692 | "Frozen image may not be consistent."); |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 693 | xfs_log_unmount_write(mp); |
| 694 | xfs_unmountfs_writesb(mp); |
| 695 | } |
| 696 | |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 697 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | xfs_mntupdate( |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 699 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | int *flags, |
| 701 | struct xfs_mount_args *args) |
| 702 | { |
Nathan Scott | d08d389 | 2006-05-08 19:51:28 +1000 | [diff] [blame] | 703 | if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */ |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 704 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
| 705 | mp->m_flags &= ~XFS_MOUNT_RDONLY; |
Nathan Scott | d08d389 | 2006-05-08 19:51:28 +1000 | [diff] [blame] | 706 | if (args->flags & XFSMNT_BARRIER) { |
| 707 | mp->m_flags |= XFS_MOUNT_BARRIER; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 708 | xfs_mountfs_check_barriers(mp); |
Nathan Scott | d08d389 | 2006-05-08 19:51:28 +1000 | [diff] [blame] | 709 | } else { |
| 710 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
| 711 | } |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 712 | } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */ |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 713 | xfs_filestream_flush(mp); |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 714 | xfs_sync(mp, SYNC_DATA_QUIESCE); |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 715 | xfs_attr_quiesce(mp); |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 716 | mp->m_flags |= XFS_MOUNT_RDONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * xfs_unmount_flush implements a set of flush operation on special |
| 723 | * inodes, which are needed as a separate set of operations so that |
| 724 | * they can be called as part of relocation process. |
| 725 | */ |
| 726 | int |
| 727 | xfs_unmount_flush( |
| 728 | xfs_mount_t *mp, /* Mount structure we are getting |
| 729 | rid of. */ |
| 730 | int relocation) /* Called from vfs relocation. */ |
| 731 | { |
| 732 | xfs_inode_t *rip = mp->m_rootip; |
| 733 | xfs_inode_t *rbmip; |
| 734 | xfs_inode_t *rsumip = NULL; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 735 | bhv_vnode_t *rvp = XFS_ITOV(rip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | int error; |
| 737 | |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 738 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | xfs_iflock(rip); |
| 740 | |
| 741 | /* |
| 742 | * Flush out the real time inodes. |
| 743 | */ |
| 744 | if ((rbmip = mp->m_rbmip) != NULL) { |
| 745 | xfs_ilock(rbmip, XFS_ILOCK_EXCL); |
| 746 | xfs_iflock(rbmip); |
| 747 | error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC); |
| 748 | xfs_iunlock(rbmip, XFS_ILOCK_EXCL); |
| 749 | |
| 750 | if (error == EFSCORRUPTED) |
| 751 | goto fscorrupt_out; |
| 752 | |
| 753 | ASSERT(vn_count(XFS_ITOV(rbmip)) == 1); |
| 754 | |
| 755 | rsumip = mp->m_rsumip; |
| 756 | xfs_ilock(rsumip, XFS_ILOCK_EXCL); |
| 757 | xfs_iflock(rsumip); |
| 758 | error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC); |
| 759 | xfs_iunlock(rsumip, XFS_ILOCK_EXCL); |
| 760 | |
| 761 | if (error == EFSCORRUPTED) |
| 762 | goto fscorrupt_out; |
| 763 | |
| 764 | ASSERT(vn_count(XFS_ITOV(rsumip)) == 1); |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Synchronously flush root inode to disk |
| 769 | */ |
| 770 | error = xfs_iflush(rip, XFS_IFLUSH_SYNC); |
| 771 | if (error == EFSCORRUPTED) |
| 772 | goto fscorrupt_out2; |
| 773 | |
| 774 | if (vn_count(rvp) != 1 && !relocation) { |
| 775 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 776 | return XFS_ERROR(EBUSY); |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * Release dquot that rootinode, rbmino and rsumino might be holding, |
| 781 | * flush and purge the quota inodes. |
| 782 | */ |
| 783 | error = XFS_QM_UNMOUNT(mp); |
| 784 | if (error == EFSCORRUPTED) |
| 785 | goto fscorrupt_out2; |
| 786 | |
| 787 | if (rbmip) { |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 788 | IRELE(rbmip); |
| 789 | IRELE(rsumip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 793 | return 0; |
| 794 | |
| 795 | fscorrupt_out: |
| 796 | xfs_ifunlock(rip); |
| 797 | |
| 798 | fscorrupt_out2: |
| 799 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 800 | |
| 801 | return XFS_ERROR(EFSCORRUPTED); |
| 802 | } |
| 803 | |
| 804 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | * xfs_sync flushes any pending I/O to file system vfsp. |
| 806 | * |
| 807 | * This routine is called by vfs_sync() to make sure that things make it |
| 808 | * out to disk eventually, on sync() system calls to flush out everything, |
| 809 | * and when the file system is unmounted. For the vfs_sync() case, all |
| 810 | * we really need to do is sync out the log to make all of our meta-data |
| 811 | * updates permanent (except for timestamps). For calls from pflushd(), |
| 812 | * dirty pages are kept moving by calling pdflush() on the inodes |
| 813 | * containing them. We also flush the inodes that we can lock without |
| 814 | * sleeping and the superblock if we can lock it without sleeping from |
| 815 | * vfs_sync() so that items at the tail of the log are always moving out. |
| 816 | * |
| 817 | * Flags: |
| 818 | * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want |
| 819 | * to sleep if we can help it. All we really need |
| 820 | * to do is ensure that the log is synced at least |
| 821 | * periodically. We also push the inodes and |
| 822 | * superblock if we can lock them without sleeping |
| 823 | * and they are not pinned. |
| 824 | * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not |
| 825 | * set, then we really want to lock each inode and flush |
| 826 | * it. |
| 827 | * SYNC_WAIT - All the flushes that take place in this call should |
| 828 | * be synchronous. |
| 829 | * SYNC_DELWRI - This tells us to push dirty pages associated with |
| 830 | * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to |
| 831 | * determine if they should be flushed sync, async, or |
| 832 | * delwri. |
| 833 | * SYNC_CLOSE - This flag is passed when the system is being |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 834 | * unmounted. We should sync and invalidate everything. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | * SYNC_FSDATA - This indicates that the caller would like to make |
| 836 | * sure the superblock is safe on disk. We can ensure |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 837 | * this by simply making sure the log gets flushed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | * if SYNC_BDFLUSH is set, and by actually writing it |
| 839 | * out otherwise. |
David Chinner | 3c0dc77 | 2007-02-10 18:37:22 +1100 | [diff] [blame] | 840 | * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete |
| 841 | * before we return (including direct I/O). Forms the drain |
| 842 | * side of the write barrier needed to safely quiesce the |
| 843 | * filesystem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | * |
| 845 | */ |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 846 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | xfs_sync( |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 848 | xfs_mount_t *mp, |
| 849 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 851 | int error; |
| 852 | |
| 853 | /* |
| 854 | * Get the Quota Manager to flush the dquots. |
| 855 | * |
| 856 | * If XFS quota support is not enabled or this filesystem |
| 857 | * instance does not use quotas XFS_QM_DQSYNC will always |
| 858 | * return zero. |
| 859 | */ |
| 860 | error = XFS_QM_DQSYNC(mp, flags); |
| 861 | if (error) { |
| 862 | /* |
| 863 | * If we got an IO error, we will be shutting down. |
| 864 | * So, there's nothing more for us to do here. |
| 865 | */ |
| 866 | ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp)); |
| 867 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 868 | return XFS_ERROR(error); |
| 869 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 871 | if (flags & SYNC_IOWAIT) |
| 872 | xfs_filestream_flush(mp); |
| 873 | |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 874 | return xfs_syncsub(mp, flags, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /* |
| 878 | * xfs sync routine for internal use |
| 879 | * |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 880 | * This routine supports all of the flags defined for the generic vfs_sync |
Lachlan McIlroy | 1f9b3b6 | 2007-02-10 18:35:33 +1100 | [diff] [blame] | 881 | * interface as explained above under xfs_sync. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | * |
| 883 | */ |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 884 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | xfs_sync_inodes( |
| 886 | xfs_mount_t *mp, |
| 887 | int flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | int *bypassed) |
| 889 | { |
| 890 | xfs_inode_t *ip = NULL; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 891 | bhv_vnode_t *vp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | int error; |
| 893 | int last_error; |
| 894 | uint64_t fflag; |
| 895 | uint lock_flags; |
| 896 | uint base_lock_flags; |
| 897 | boolean_t mount_locked; |
| 898 | boolean_t vnode_refed; |
| 899 | int preempt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | xfs_iptr_t *ipointer; |
| 901 | #ifdef DEBUG |
| 902 | boolean_t ipointer_in = B_FALSE; |
| 903 | |
| 904 | #define IPOINTER_SET ipointer_in = B_TRUE |
| 905 | #define IPOINTER_CLR ipointer_in = B_FALSE |
| 906 | #else |
| 907 | #define IPOINTER_SET |
| 908 | #define IPOINTER_CLR |
| 909 | #endif |
| 910 | |
| 911 | |
| 912 | /* Insert a marker record into the inode list after inode ip. The list |
| 913 | * must be locked when this is called. After the call the list will no |
| 914 | * longer be locked. |
| 915 | */ |
| 916 | #define IPOINTER_INSERT(ip, mp) { \ |
| 917 | ASSERT(ipointer_in == B_FALSE); \ |
| 918 | ipointer->ip_mnext = ip->i_mnext; \ |
| 919 | ipointer->ip_mprev = ip; \ |
| 920 | ip->i_mnext = (xfs_inode_t *)ipointer; \ |
| 921 | ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \ |
| 922 | preempt = 0; \ |
| 923 | XFS_MOUNT_IUNLOCK(mp); \ |
| 924 | mount_locked = B_FALSE; \ |
| 925 | IPOINTER_SET; \ |
| 926 | } |
| 927 | |
| 928 | /* Remove the marker from the inode list. If the marker was the only item |
| 929 | * in the list then there are no remaining inodes and we should zero out |
| 930 | * the whole list. If we are the current head of the list then move the head |
| 931 | * past us. |
| 932 | */ |
| 933 | #define IPOINTER_REMOVE(ip, mp) { \ |
| 934 | ASSERT(ipointer_in == B_TRUE); \ |
| 935 | if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \ |
| 936 | ip = ipointer->ip_mnext; \ |
| 937 | ip->i_mprev = ipointer->ip_mprev; \ |
| 938 | ipointer->ip_mprev->i_mnext = ip; \ |
| 939 | if (mp->m_inodes == (xfs_inode_t *)ipointer) { \ |
| 940 | mp->m_inodes = ip; \ |
| 941 | } \ |
| 942 | } else { \ |
| 943 | ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \ |
| 944 | mp->m_inodes = NULL; \ |
| 945 | ip = NULL; \ |
| 946 | } \ |
| 947 | IPOINTER_CLR; \ |
| 948 | } |
| 949 | |
| 950 | #define XFS_PREEMPT_MASK 0x7f |
| 951 | |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 952 | ASSERT(!(flags & SYNC_BDFLUSH)); |
| 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | if (bypassed) |
| 955 | *bypassed = 0; |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 956 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | return 0; |
| 958 | error = 0; |
| 959 | last_error = 0; |
| 960 | preempt = 0; |
| 961 | |
| 962 | /* Allocate a reference marker */ |
| 963 | ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP); |
| 964 | |
| 965 | fflag = XFS_B_ASYNC; /* default is don't wait */ |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 966 | if (flags & SYNC_DELWRI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | fflag = XFS_B_DELWRI; |
| 968 | if (flags & SYNC_WAIT) |
| 969 | fflag = 0; /* synchronous overrides all */ |
| 970 | |
| 971 | base_lock_flags = XFS_ILOCK_SHARED; |
| 972 | if (flags & (SYNC_DELWRI | SYNC_CLOSE)) { |
| 973 | /* |
| 974 | * We need the I/O lock if we're going to call any of |
| 975 | * the flush/inval routines. |
| 976 | */ |
| 977 | base_lock_flags |= XFS_IOLOCK_SHARED; |
| 978 | } |
| 979 | |
| 980 | XFS_MOUNT_ILOCK(mp); |
| 981 | |
| 982 | ip = mp->m_inodes; |
| 983 | |
| 984 | mount_locked = B_TRUE; |
| 985 | vnode_refed = B_FALSE; |
| 986 | |
| 987 | IPOINTER_CLR; |
| 988 | |
| 989 | do { |
| 990 | ASSERT(ipointer_in == B_FALSE); |
| 991 | ASSERT(vnode_refed == B_FALSE); |
| 992 | |
| 993 | lock_flags = base_lock_flags; |
| 994 | |
| 995 | /* |
| 996 | * There were no inodes in the list, just break out |
| 997 | * of the loop. |
| 998 | */ |
| 999 | if (ip == NULL) { |
| 1000 | break; |
| 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | * We found another sync thread marker - skip it |
| 1005 | */ |
| 1006 | if (ip->i_mount == NULL) { |
| 1007 | ip = ip->i_mnext; |
| 1008 | continue; |
| 1009 | } |
| 1010 | |
| 1011 | vp = XFS_ITOV_NULL(ip); |
| 1012 | |
| 1013 | /* |
| 1014 | * If the vnode is gone then this is being torn down, |
| 1015 | * call reclaim if it is flushed, else let regular flush |
| 1016 | * code deal with it later in the loop. |
| 1017 | */ |
| 1018 | |
| 1019 | if (vp == NULL) { |
| 1020 | /* Skip ones already in reclaim */ |
| 1021 | if (ip->i_flags & XFS_IRECLAIM) { |
| 1022 | ip = ip->i_mnext; |
| 1023 | continue; |
| 1024 | } |
| 1025 | if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) { |
| 1026 | ip = ip->i_mnext; |
| 1027 | } else if ((xfs_ipincount(ip) == 0) && |
| 1028 | xfs_iflock_nowait(ip)) { |
| 1029 | IPOINTER_INSERT(ip, mp); |
| 1030 | |
| 1031 | xfs_finish_reclaim(ip, 1, |
| 1032 | XFS_IFLUSH_DELWRI_ELSE_ASYNC); |
| 1033 | |
| 1034 | XFS_MOUNT_ILOCK(mp); |
| 1035 | mount_locked = B_TRUE; |
| 1036 | IPOINTER_REMOVE(ip, mp); |
| 1037 | } else { |
| 1038 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1039 | ip = ip->i_mnext; |
| 1040 | } |
| 1041 | continue; |
| 1042 | } |
| 1043 | |
| 1044 | if (VN_BAD(vp)) { |
| 1045 | ip = ip->i_mnext; |
| 1046 | continue; |
| 1047 | } |
| 1048 | |
| 1049 | if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) { |
| 1050 | XFS_MOUNT_IUNLOCK(mp); |
| 1051 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | * Try to lock without sleeping. We're out of order with |
| 1057 | * the inode list lock here, so if we fail we need to drop |
| 1058 | * the mount lock and try again. If we're called from |
| 1059 | * bdflush() here, then don't bother. |
| 1060 | * |
| 1061 | * The inode lock here actually coordinates with the |
| 1062 | * almost spurious inode lock in xfs_ireclaim() to prevent |
| 1063 | * the vnode we handle here without a reference from |
| 1064 | * being freed while we reference it. If we lock the inode |
| 1065 | * while it's on the mount list here, then the spurious inode |
| 1066 | * lock in xfs_ireclaim() after the inode is pulled from |
| 1067 | * the mount list will sleep until we release it here. |
| 1068 | * This keeps the vnode from being freed while we reference |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1069 | * it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | */ |
| 1071 | if (xfs_ilock_nowait(ip, lock_flags) == 0) { |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 1072 | if (vp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | ip = ip->i_mnext; |
| 1074 | continue; |
| 1075 | } |
| 1076 | |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1077 | vp = vn_grab(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | if (vp == NULL) { |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1079 | ip = ip->i_mnext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | continue; |
| 1081 | } |
| 1082 | |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1083 | IPOINTER_INSERT(ip, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | xfs_ilock(ip, lock_flags); |
| 1085 | |
| 1086 | ASSERT(vp == XFS_ITOV(ip)); |
| 1087 | ASSERT(ip->i_mount == mp); |
| 1088 | |
| 1089 | vnode_refed = B_TRUE; |
| 1090 | } |
| 1091 | |
| 1092 | /* From here on in the loop we may have a marker record |
| 1093 | * in the inode list. |
| 1094 | */ |
| 1095 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1096 | /* |
| 1097 | * If we have to flush data or wait for I/O completion |
| 1098 | * we need to drop the ilock that we currently hold. |
| 1099 | * If we need to drop the lock, insert a marker if we |
| 1100 | * have not already done so. |
| 1101 | */ |
| 1102 | if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) || |
| 1103 | ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) { |
| 1104 | if (mount_locked) { |
| 1105 | IPOINTER_INSERT(ip, mp); |
| 1106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 1108 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1109 | if (flags & SYNC_CLOSE) { |
| 1110 | /* Shutdown case. Flush and invalidate. */ |
| 1111 | if (XFS_FORCED_SHUTDOWN(mp)) |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 1112 | xfs_tosspages(ip, 0, -1, |
| 1113 | FI_REMAPF); |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1114 | else |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 1115 | error = xfs_flushinval_pages(ip, |
| 1116 | 0, -1, FI_REMAPF); |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1117 | } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) { |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 1118 | error = xfs_flush_pages(ip, 0, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 1119 | -1, fflag, FI_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1122 | /* |
| 1123 | * When freezing, we need to wait ensure all I/O (including direct |
| 1124 | * I/O) is complete to ensure no further data modification can take |
| 1125 | * place after this point |
| 1126 | */ |
| 1127 | if (flags & SYNC_IOWAIT) |
Christoph Hellwig | b677c21 | 2007-08-29 11:46:28 +1000 | [diff] [blame] | 1128 | vn_iowait(ip); |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1129 | |
| 1130 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 1133 | if ((flags & SYNC_ATTR) && |
| 1134 | (ip->i_update_core || |
| 1135 | (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) { |
| 1136 | if (mount_locked) |
| 1137 | IPOINTER_INSERT(ip, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 1139 | if (flags & SYNC_WAIT) { |
| 1140 | xfs_iflock(ip); |
| 1141 | error = xfs_iflush(ip, XFS_IFLUSH_SYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | |
Lachlan McIlroy | 44866d3 | 2007-09-14 15:21:08 +1000 | [diff] [blame] | 1143 | /* |
| 1144 | * If we can't acquire the flush lock, then the inode |
| 1145 | * is already being flushed so don't bother waiting. |
| 1146 | * |
| 1147 | * If we can lock it then do a delwri flush so we can |
| 1148 | * combine multiple inode flushes in each disk write. |
| 1149 | */ |
| 1150 | } else if (xfs_iflock_nowait(ip)) { |
| 1151 | error = xfs_iflush(ip, XFS_IFLUSH_DELWRI); |
| 1152 | } else if (bypassed) { |
| 1153 | (*bypassed)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | if (lock_flags != 0) { |
| 1158 | xfs_iunlock(ip, lock_flags); |
| 1159 | } |
| 1160 | |
| 1161 | if (vnode_refed) { |
| 1162 | /* |
| 1163 | * If we had to take a reference on the vnode |
| 1164 | * above, then wait until after we've unlocked |
| 1165 | * the inode to release the reference. This is |
| 1166 | * because we can be already holding the inode |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 1167 | * lock when IRELE() calls xfs_inactive(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | * |
| 1169 | * Make sure to drop the mount lock before calling |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 1170 | * IRELE() so that we don't trip over ourselves if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | * we have to go for the mount lock again in the |
| 1172 | * inactive code. |
| 1173 | */ |
| 1174 | if (mount_locked) { |
| 1175 | IPOINTER_INSERT(ip, mp); |
| 1176 | } |
| 1177 | |
Christoph Hellwig | 4335509 | 2008-03-27 18:01:08 +1100 | [diff] [blame] | 1178 | IRELE(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
| 1180 | vnode_refed = B_FALSE; |
| 1181 | } |
| 1182 | |
| 1183 | if (error) { |
| 1184 | last_error = error; |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | * bail out if the filesystem is corrupted. |
| 1189 | */ |
| 1190 | if (error == EFSCORRUPTED) { |
| 1191 | if (!mount_locked) { |
| 1192 | XFS_MOUNT_ILOCK(mp); |
| 1193 | IPOINTER_REMOVE(ip, mp); |
| 1194 | } |
| 1195 | XFS_MOUNT_IUNLOCK(mp); |
| 1196 | ASSERT(ipointer_in == B_FALSE); |
| 1197 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1198 | return XFS_ERROR(error); |
| 1199 | } |
| 1200 | |
| 1201 | /* Let other threads have a chance at the mount lock |
| 1202 | * if we have looped many times without dropping the |
| 1203 | * lock. |
| 1204 | */ |
| 1205 | if ((++preempt & XFS_PREEMPT_MASK) == 0) { |
| 1206 | if (mount_locked) { |
| 1207 | IPOINTER_INSERT(ip, mp); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | if (mount_locked == B_FALSE) { |
| 1212 | XFS_MOUNT_ILOCK(mp); |
| 1213 | mount_locked = B_TRUE; |
| 1214 | IPOINTER_REMOVE(ip, mp); |
| 1215 | continue; |
| 1216 | } |
| 1217 | |
| 1218 | ASSERT(ipointer_in == B_FALSE); |
| 1219 | ip = ip->i_mnext; |
| 1220 | |
| 1221 | } while (ip != mp->m_inodes); |
| 1222 | |
| 1223 | XFS_MOUNT_IUNLOCK(mp); |
| 1224 | |
| 1225 | ASSERT(ipointer_in == B_FALSE); |
| 1226 | |
| 1227 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1228 | return XFS_ERROR(last_error); |
| 1229 | } |
| 1230 | |
| 1231 | /* |
| 1232 | * xfs sync routine for internal use |
| 1233 | * |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1234 | * This routine supports all of the flags defined for the generic vfs_sync |
Lachlan McIlroy | 1f9b3b6 | 2007-02-10 18:35:33 +1100 | [diff] [blame] | 1235 | * interface as explained above under xfs_sync. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | * |
| 1237 | */ |
| 1238 | int |
| 1239 | xfs_syncsub( |
| 1240 | xfs_mount_t *mp, |
| 1241 | int flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | int *bypassed) |
| 1243 | { |
| 1244 | int error = 0; |
| 1245 | int last_error = 0; |
| 1246 | uint log_flags = XFS_LOG_FORCE; |
| 1247 | xfs_buf_t *bp; |
| 1248 | xfs_buf_log_item_t *bip; |
| 1249 | |
| 1250 | /* |
| 1251 | * Sync out the log. This ensures that the log is periodically |
| 1252 | * flushed even if there is not enough activity to fill it up. |
| 1253 | */ |
| 1254 | if (flags & SYNC_WAIT) |
| 1255 | log_flags |= XFS_LOG_SYNC; |
| 1256 | |
| 1257 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1258 | |
| 1259 | if (flags & (SYNC_ATTR|SYNC_DELWRI)) { |
| 1260 | if (flags & SYNC_BDFLUSH) |
| 1261 | xfs_finish_reclaim_all(mp, 1); |
| 1262 | else |
Lachlan McIlroy | 1f9b3b6 | 2007-02-10 18:35:33 +1100 | [diff] [blame] | 1263 | error = xfs_sync_inodes(mp, flags, bypassed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * Flushing out dirty data above probably generated more |
| 1268 | * log activity, so if this isn't vfs_sync() then flush |
| 1269 | * the log again. |
| 1270 | */ |
| 1271 | if (flags & SYNC_DELWRI) { |
| 1272 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1273 | } |
| 1274 | |
| 1275 | if (flags & SYNC_FSDATA) { |
| 1276 | /* |
| 1277 | * If this is vfs_sync() then only sync the superblock |
| 1278 | * if we can lock it without sleeping and it is not pinned. |
| 1279 | */ |
| 1280 | if (flags & SYNC_BDFLUSH) { |
| 1281 | bp = xfs_getsb(mp, XFS_BUF_TRYLOCK); |
| 1282 | if (bp != NULL) { |
| 1283 | bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*); |
| 1284 | if ((bip != NULL) && |
| 1285 | xfs_buf_item_dirty(bip)) { |
| 1286 | if (!(XFS_BUF_ISPINNED(bp))) { |
| 1287 | XFS_BUF_ASYNC(bp); |
| 1288 | error = xfs_bwrite(mp, bp); |
| 1289 | } else { |
| 1290 | xfs_buf_relse(bp); |
| 1291 | } |
| 1292 | } else { |
| 1293 | xfs_buf_relse(bp); |
| 1294 | } |
| 1295 | } |
| 1296 | } else { |
| 1297 | bp = xfs_getsb(mp, 0); |
| 1298 | /* |
| 1299 | * If the buffer is pinned then push on the log so |
| 1300 | * we won't get stuck waiting in the write for |
| 1301 | * someone, maybe ourselves, to flush the log. |
| 1302 | * Even though we just pushed the log above, we |
| 1303 | * did not have the superblock buffer locked at |
| 1304 | * that point so it can become pinned in between |
| 1305 | * there and here. |
| 1306 | */ |
| 1307 | if (XFS_BUF_ISPINNED(bp)) |
| 1308 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE); |
| 1309 | if (flags & SYNC_WAIT) |
| 1310 | XFS_BUF_UNASYNC(bp); |
| 1311 | else |
| 1312 | XFS_BUF_ASYNC(bp); |
| 1313 | error = xfs_bwrite(mp, bp); |
| 1314 | } |
| 1315 | if (error) { |
| 1316 | last_error = error; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | * Now check to see if the log needs a "dummy" transaction. |
| 1322 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) { |
| 1324 | xfs_trans_t *tp; |
| 1325 | xfs_inode_t *ip; |
| 1326 | |
| 1327 | /* |
| 1328 | * Put a dummy transaction in the log to tell |
| 1329 | * recovery that all others are OK. |
| 1330 | */ |
| 1331 | tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1); |
| 1332 | if ((error = xfs_trans_reserve(tp, 0, |
| 1333 | XFS_ICHANGE_LOG_RES(mp), |
| 1334 | 0, 0, 0))) { |
| 1335 | xfs_trans_cancel(tp, 0); |
| 1336 | return error; |
| 1337 | } |
| 1338 | |
| 1339 | ip = mp->m_rootip; |
| 1340 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 1341 | |
| 1342 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 1343 | xfs_trans_ihold(tp, ip); |
| 1344 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 1345 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1347 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1348 | } |
| 1349 | |
| 1350 | /* |
| 1351 | * When shutting down, we need to insure that the AIL is pushed |
| 1352 | * to disk or the filesystem can appear corrupt from the PROM. |
| 1353 | */ |
| 1354 | if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) { |
| 1355 | XFS_bflush(mp->m_ddev_targp); |
| 1356 | if (mp->m_rtdev_targp) { |
| 1357 | XFS_bflush(mp->m_rtdev_targp); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | return XFS_ERROR(last_error); |
| 1362 | } |