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" |
| 46 | #include "xfs_refcache.h" |
| 47 | #include "xfs_buf_item.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 48 | #include "xfs_log_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include "xfs_dir2_trace.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 50 | #include "xfs_extfree_item.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "xfs_acl.h" |
| 52 | #include "xfs_attr.h" |
| 53 | #include "xfs_clnt.h" |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 54 | #include "xfs_mru_cache.h" |
| 55 | #include "xfs_filestream.h" |
Christoph Hellwig | e13a73f | 2006-01-11 15:30:08 +1100 | [diff] [blame] | 56 | #include "xfs_fsops.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
David Chinner | 8d280b9 | 2006-03-14 13:13:09 +1100 | [diff] [blame] | 58 | STATIC int xfs_sync(bhv_desc_t *, int, cred_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | int |
| 61 | xfs_init(void) |
| 62 | { |
| 63 | extern kmem_zone_t *xfs_bmap_free_item_zone; |
| 64 | extern kmem_zone_t *xfs_btree_cur_zone; |
| 65 | extern kmem_zone_t *xfs_trans_zone; |
| 66 | extern kmem_zone_t *xfs_buf_item_zone; |
| 67 | extern kmem_zone_t *xfs_dabuf_zone; |
| 68 | #ifdef XFS_DABUF_DEBUG |
| 69 | extern lock_t xfs_dabuf_global_lock; |
| 70 | spinlock_init(&xfs_dabuf_global_lock, "xfsda"); |
| 71 | #endif |
| 72 | |
| 73 | /* |
| 74 | * Initialize all of the zone allocators we use. |
| 75 | */ |
| 76 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), |
| 77 | "xfs_bmap_free_item"); |
| 78 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), |
| 79 | "xfs_btree_cur"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); |
| 81 | xfs_da_state_zone = |
| 82 | kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state"); |
| 83 | xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 84 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); |
| 85 | xfs_acl_zone_init(xfs_acl_zone, "xfs_acl"); |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 86 | xfs_mru_cache_init(); |
| 87 | xfs_filestream_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * The size of the zone allocated buf log item is the maximum |
| 91 | * size possible under XFS. This wastes a little bit of memory, |
| 92 | * but it is much faster. |
| 93 | */ |
| 94 | xfs_buf_item_zone = |
| 95 | kmem_zone_init((sizeof(xfs_buf_log_item_t) + |
| 96 | (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) / |
| 97 | NBWORD) * sizeof(int))), |
| 98 | "xfs_buf_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 99 | xfs_efd_zone = |
| 100 | kmem_zone_init((sizeof(xfs_efd_log_item_t) + |
| 101 | ((XFS_EFD_MAX_FAST_EXTENTS - 1) * |
| 102 | sizeof(xfs_extent_t))), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | "xfs_efd_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 104 | xfs_efi_zone = |
| 105 | kmem_zone_init((sizeof(xfs_efi_log_item_t) + |
| 106 | ((XFS_EFI_MAX_FAST_EXTENTS - 1) * |
| 107 | sizeof(xfs_extent_t))), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | "xfs_efi_item"); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * These zones warrant special memory allocator hints |
| 112 | */ |
| 113 | xfs_inode_zone = |
| 114 | kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", |
| 115 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
| 116 | KM_ZONE_SPREAD, NULL); |
| 117 | xfs_ili_zone = |
| 118 | kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili", |
| 119 | KM_ZONE_SPREAD, NULL); |
| 120 | xfs_chashlist_zone = |
| 121 | kmem_zone_init_flags(sizeof(xfs_chashlist_t), "xfs_chashlist", |
| 122 | KM_ZONE_SPREAD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * Allocate global trace buffers. |
| 126 | */ |
| 127 | #ifdef XFS_ALLOC_TRACE |
| 128 | xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP); |
| 129 | #endif |
| 130 | #ifdef XFS_BMAP_TRACE |
| 131 | xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP); |
| 132 | #endif |
| 133 | #ifdef XFS_BMBT_TRACE |
| 134 | xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP); |
| 135 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #ifdef XFS_ATTR_TRACE |
| 137 | xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP); |
| 138 | #endif |
| 139 | #ifdef XFS_DIR2_TRACE |
| 140 | xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP); |
| 141 | #endif |
| 142 | |
| 143 | xfs_dir_startup(); |
| 144 | |
| 145 | #if (defined(DEBUG) || defined(INDUCE_IO_ERROR)) |
| 146 | xfs_error_test_init(); |
| 147 | #endif /* DEBUG || INDUCE_IO_ERROR */ |
| 148 | |
| 149 | xfs_init_procfs(); |
| 150 | xfs_sysctl_register(); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | xfs_cleanup(void) |
| 156 | { |
| 157 | extern kmem_zone_t *xfs_bmap_free_item_zone; |
| 158 | extern kmem_zone_t *xfs_btree_cur_zone; |
| 159 | extern kmem_zone_t *xfs_inode_zone; |
| 160 | extern kmem_zone_t *xfs_trans_zone; |
| 161 | extern kmem_zone_t *xfs_da_state_zone; |
| 162 | extern kmem_zone_t *xfs_dabuf_zone; |
| 163 | extern kmem_zone_t *xfs_efd_zone; |
| 164 | extern kmem_zone_t *xfs_efi_zone; |
| 165 | extern kmem_zone_t *xfs_buf_item_zone; |
| 166 | extern kmem_zone_t *xfs_chashlist_zone; |
| 167 | |
| 168 | xfs_cleanup_procfs(); |
| 169 | xfs_sysctl_unregister(); |
| 170 | xfs_refcache_destroy(); |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 171 | xfs_filestream_uninit(); |
| 172 | xfs_mru_cache_uninit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | xfs_acl_zone_destroy(xfs_acl_zone); |
| 174 | |
| 175 | #ifdef XFS_DIR2_TRACE |
| 176 | ktrace_free(xfs_dir2_trace_buf); |
| 177 | #endif |
| 178 | #ifdef XFS_ATTR_TRACE |
| 179 | ktrace_free(xfs_attr_trace_buf); |
| 180 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #ifdef XFS_BMBT_TRACE |
| 182 | ktrace_free(xfs_bmbt_trace_buf); |
| 183 | #endif |
| 184 | #ifdef XFS_BMAP_TRACE |
| 185 | ktrace_free(xfs_bmap_trace_buf); |
| 186 | #endif |
| 187 | #ifdef XFS_ALLOC_TRACE |
| 188 | ktrace_free(xfs_alloc_trace_buf); |
| 189 | #endif |
| 190 | |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 191 | kmem_zone_destroy(xfs_bmap_free_item_zone); |
| 192 | kmem_zone_destroy(xfs_btree_cur_zone); |
| 193 | kmem_zone_destroy(xfs_inode_zone); |
| 194 | kmem_zone_destroy(xfs_trans_zone); |
| 195 | kmem_zone_destroy(xfs_da_state_zone); |
| 196 | kmem_zone_destroy(xfs_dabuf_zone); |
| 197 | kmem_zone_destroy(xfs_buf_item_zone); |
| 198 | kmem_zone_destroy(xfs_efd_zone); |
| 199 | kmem_zone_destroy(xfs_efi_zone); |
| 200 | kmem_zone_destroy(xfs_ifork_zone); |
| 201 | kmem_zone_destroy(xfs_ili_zone); |
| 202 | kmem_zone_destroy(xfs_chashlist_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* |
| 206 | * xfs_start_flags |
| 207 | * |
| 208 | * This function fills in xfs_mount_t fields based on mount args. |
| 209 | * Note: the superblock has _not_ yet been read in. |
| 210 | */ |
| 211 | STATIC int |
| 212 | xfs_start_flags( |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 213 | struct bhv_vfs *vfs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | struct xfs_mount_args *ap, |
| 215 | struct xfs_mount *mp) |
| 216 | { |
| 217 | /* Values are in BBs */ |
| 218 | if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 219 | /* |
| 220 | * At this point the superblock has not been read |
| 221 | * in, therefore we do not know the block size. |
| 222 | * Before the mount call ends we will convert |
| 223 | * these to FSBs. |
| 224 | */ |
| 225 | mp->m_dalign = ap->sunit; |
| 226 | mp->m_swidth = ap->swidth; |
| 227 | } |
| 228 | |
| 229 | if (ap->logbufs != -1 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | ap->logbufs != 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | (ap->logbufs < XLOG_MIN_ICLOGS || |
| 232 | ap->logbufs > XLOG_MAX_ICLOGS)) { |
| 233 | cmn_err(CE_WARN, |
| 234 | "XFS: invalid logbufs value: %d [not %d-%d]", |
| 235 | ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); |
| 236 | return XFS_ERROR(EINVAL); |
| 237 | } |
| 238 | mp->m_logbufs = ap->logbufs; |
| 239 | if (ap->logbufsize != -1 && |
Nathan Scott | cfcbbbd | 2005-11-02 15:12:04 +1100 | [diff] [blame] | 240 | ap->logbufsize != 0 && |
Eric Sandeen | dcb3b83 | 2007-08-16 16:25:33 +1000 | [diff] [blame] | 241 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || |
| 242 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || |
| 243 | !is_power_of_2(ap->logbufsize))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | cmn_err(CE_WARN, |
| 245 | "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", |
| 246 | ap->logbufsize); |
| 247 | return XFS_ERROR(EINVAL); |
| 248 | } |
| 249 | mp->m_ihsize = ap->ihashsize; |
| 250 | mp->m_logbsize = ap->logbufsize; |
| 251 | mp->m_fsname_len = strlen(ap->fsname) + 1; |
| 252 | mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP); |
| 253 | strcpy(mp->m_fsname, ap->fsname); |
Nathan Scott | fc1f8c1 | 2005-11-02 11:44:33 +1100 | [diff] [blame] | 254 | if (ap->rtname[0]) { |
| 255 | mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP); |
| 256 | strcpy(mp->m_rtname, ap->rtname); |
| 257 | } |
| 258 | if (ap->logname[0]) { |
| 259 | mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP); |
| 260 | strcpy(mp->m_logname, ap->logname); |
| 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | if (ap->flags & XFSMNT_WSYNC) |
| 264 | mp->m_flags |= XFS_MOUNT_WSYNC; |
| 265 | #if XFS_BIG_INUMS |
| 266 | if (ap->flags & XFSMNT_INO64) { |
| 267 | mp->m_flags |= XFS_MOUNT_INO64; |
| 268 | mp->m_inoadd = XFS_INO64_OFFSET; |
| 269 | } |
| 270 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | if (ap->flags & XFSMNT_RETERR) |
| 272 | mp->m_flags |= XFS_MOUNT_RETERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (ap->flags & XFSMNT_NOALIGN) |
| 274 | mp->m_flags |= XFS_MOUNT_NOALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (ap->flags & XFSMNT_SWALLOC) |
| 276 | mp->m_flags |= XFS_MOUNT_SWALLOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | if (ap->flags & XFSMNT_OSYNCISOSYNC) |
| 278 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (ap->flags & XFSMNT_32BITINODES) |
Nathan Scott | c11e2c3 | 2005-11-02 15:11:45 +1100 | [diff] [blame] | 280 | mp->m_flags |= XFS_MOUNT_32BITINODES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | if (ap->flags & XFSMNT_IOSIZE) { |
| 283 | if (ap->iosizelog > XFS_MAX_IO_LOG || |
| 284 | ap->iosizelog < XFS_MIN_IO_LOG) { |
| 285 | cmn_err(CE_WARN, |
| 286 | "XFS: invalid log iosize: %d [not %d-%d]", |
| 287 | ap->iosizelog, XFS_MIN_IO_LOG, |
| 288 | XFS_MAX_IO_LOG); |
| 289 | return XFS_ERROR(EINVAL); |
| 290 | } |
| 291 | |
| 292 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; |
| 293 | mp->m_readio_log = mp->m_writeio_log = ap->iosizelog; |
| 294 | } |
| 295 | |
| 296 | if (ap->flags & XFSMNT_IHASHSIZE) |
| 297 | mp->m_flags |= XFS_MOUNT_IHASHSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (ap->flags & XFSMNT_IDELETE) |
| 299 | mp->m_flags |= XFS_MOUNT_IDELETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | if (ap->flags & XFSMNT_DIRSYNC) |
| 301 | mp->m_flags |= XFS_MOUNT_DIRSYNC; |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 302 | if (ap->flags & XFSMNT_ATTR2) |
| 303 | mp->m_flags |= XFS_MOUNT_ATTR2; |
David Chinner | e8c8b3a | 2005-11-02 10:33:05 +1100 | [diff] [blame] | 304 | |
Nathan Scott | e718eeb4 | 2005-11-02 15:09:22 +1100 | [diff] [blame] | 305 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) |
| 306 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* |
| 309 | * no recovery flag requires a read-only mount |
| 310 | */ |
| 311 | if (ap->flags & XFSMNT_NORECOVERY) { |
| 312 | if (!(vfs->vfs_flag & VFS_RDONLY)) { |
| 313 | cmn_err(CE_WARN, |
| 314 | "XFS: tried to mount a FS read-write without recovery!"); |
| 315 | return XFS_ERROR(EINVAL); |
| 316 | } |
| 317 | mp->m_flags |= XFS_MOUNT_NORECOVERY; |
| 318 | } |
| 319 | |
| 320 | if (ap->flags & XFSMNT_NOUUID) |
| 321 | mp->m_flags |= XFS_MOUNT_NOUUID; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 322 | if (ap->flags & XFSMNT_BARRIER) |
| 323 | mp->m_flags |= XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 324 | else |
| 325 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 327 | if (ap->flags2 & XFSMNT2_FILESTREAMS) |
| 328 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * This function fills in xfs_mount_t fields based on mount args. |
| 335 | * Note: the superblock _has_ now been read in. |
| 336 | */ |
| 337 | STATIC int |
| 338 | xfs_finish_flags( |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 339 | struct bhv_vfs *vfs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | struct xfs_mount_args *ap, |
| 341 | struct xfs_mount *mp) |
| 342 | { |
| 343 | int ronly = (vfs->vfs_flag & VFS_RDONLY); |
| 344 | |
| 345 | /* Fail a mount where the logbuf is smaller then the log stripe */ |
| 346 | if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) { |
Nathan Scott | c2cd255 | 2006-01-11 15:35:32 +1100 | [diff] [blame] | 347 | if ((ap->logbufsize <= 0) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { |
| 349 | mp->m_logbsize = mp->m_sb.sb_logsunit; |
Nathan Scott | c2cd255 | 2006-01-11 15:35:32 +1100 | [diff] [blame] | 350 | } else if (ap->logbufsize > 0 && |
| 351 | ap->logbufsize < mp->m_sb.sb_logsunit) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | cmn_err(CE_WARN, |
| 353 | "XFS: logbuf size must be greater than or equal to log stripe size"); |
| 354 | return XFS_ERROR(EINVAL); |
| 355 | } |
| 356 | } else { |
| 357 | /* Fail a mount if the logbuf is larger than 32K */ |
| 358 | if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) { |
| 359 | cmn_err(CE_WARN, |
| 360 | "XFS: logbuf size for version 1 logs must be 16K or 32K"); |
| 361 | return XFS_ERROR(EINVAL); |
| 362 | } |
| 363 | } |
| 364 | |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 365 | if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) { |
| 366 | mp->m_flags |= XFS_MOUNT_ATTR2; |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* |
| 370 | * prohibit r/w mounts of read-only filesystems |
| 371 | */ |
| 372 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { |
| 373 | cmn_err(CE_WARN, |
| 374 | "XFS: cannot mount a read-only filesystem as read-write"); |
| 375 | return XFS_ERROR(EROFS); |
| 376 | } |
| 377 | |
| 378 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | * check for shared mount. |
| 380 | */ |
| 381 | if (ap->flags & XFSMNT_SHARED) { |
| 382 | if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb)) |
| 383 | return XFS_ERROR(EINVAL); |
| 384 | |
| 385 | /* |
| 386 | * For IRIX 6.5, shared mounts must have the shared |
| 387 | * version bit set, have the persistent readonly |
| 388 | * field set, must be version 0 and can only be mounted |
| 389 | * read-only. |
| 390 | */ |
| 391 | if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) || |
| 392 | (mp->m_sb.sb_shared_vn != 0)) |
| 393 | return XFS_ERROR(EINVAL); |
| 394 | |
| 395 | mp->m_flags |= XFS_MOUNT_SHARED; |
| 396 | |
| 397 | /* |
| 398 | * Shared XFS V0 can't deal with DMI. Return EINVAL. |
| 399 | */ |
| 400 | if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI)) |
| 401 | return XFS_ERROR(EINVAL); |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * xfs_mount |
| 409 | * |
| 410 | * The file system configurations are: |
| 411 | * (1) device (partition) with data and internal log |
| 412 | * (2) logical volume with data and log subvolumes. |
| 413 | * (3) logical volume with data, log, and realtime subvolumes. |
| 414 | * |
| 415 | * We only have to handle opening the log and realtime volumes here if |
| 416 | * they are present. The data subvolume has already been opened by |
| 417 | * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev. |
| 418 | */ |
| 419 | STATIC int |
| 420 | xfs_mount( |
| 421 | struct bhv_desc *bhvp, |
| 422 | struct xfs_mount_args *args, |
| 423 | cred_t *credp) |
| 424 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 425 | struct bhv_vfs *vfsp = bhvtovfs(bhvp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | struct bhv_desc *p; |
| 427 | struct xfs_mount *mp = XFS_BHVTOM(bhvp); |
| 428 | struct block_device *ddev, *logdev, *rtdev; |
| 429 | int flags = 0, error; |
| 430 | |
| 431 | ddev = vfsp->vfs_super->s_bdev; |
| 432 | logdev = rtdev = NULL; |
| 433 | |
| 434 | /* |
| 435 | * Setup xfs_mount function vectors from available behaviors |
| 436 | */ |
| 437 | p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM); |
| 438 | mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub; |
| 439 | p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM); |
| 440 | mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub; |
| 441 | p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO); |
| 442 | mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs; |
| 443 | |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 444 | if (args->flags & XFSMNT_QUIET) |
| 445 | flags |= XFS_MFSI_QUIET; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | /* |
| 448 | * Open real time and log devices - order is important. |
| 449 | */ |
| 450 | if (args->logname[0]) { |
| 451 | error = xfs_blkdev_get(mp, args->logname, &logdev); |
| 452 | if (error) |
| 453 | return error; |
| 454 | } |
| 455 | if (args->rtname[0]) { |
| 456 | error = xfs_blkdev_get(mp, args->rtname, &rtdev); |
| 457 | if (error) { |
| 458 | xfs_blkdev_put(logdev); |
| 459 | return error; |
| 460 | } |
| 461 | |
| 462 | if (rtdev == ddev || rtdev == logdev) { |
| 463 | cmn_err(CE_WARN, |
| 464 | "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev."); |
| 465 | xfs_blkdev_put(logdev); |
| 466 | xfs_blkdev_put(rtdev); |
| 467 | return EINVAL; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Setup xfs_mount buffer target pointers |
| 473 | */ |
| 474 | error = ENOMEM; |
| 475 | mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0); |
| 476 | if (!mp->m_ddev_targp) { |
| 477 | xfs_blkdev_put(logdev); |
| 478 | xfs_blkdev_put(rtdev); |
| 479 | return error; |
| 480 | } |
| 481 | if (rtdev) { |
| 482 | mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1); |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame^] | 483 | if (!mp->m_rtdev_targp) { |
| 484 | xfs_blkdev_put(logdev); |
| 485 | xfs_blkdev_put(rtdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | goto error0; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame^] | 487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | mp->m_logdev_targp = (logdev && logdev != ddev) ? |
| 490 | xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame^] | 491 | if (!mp->m_logdev_targp) { |
| 492 | xfs_blkdev_put(logdev); |
| 493 | xfs_blkdev_put(rtdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | goto error0; |
Jesper Juhl | 49ee6c9 | 2007-08-16 16:25:42 +1000 | [diff] [blame^] | 495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | /* |
| 498 | * Setup flags based on mount(2) options and then the superblock |
| 499 | */ |
| 500 | error = xfs_start_flags(vfsp, args, mp); |
| 501 | if (error) |
| 502 | goto error1; |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 503 | error = xfs_readsb(mp, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | if (error) |
| 505 | goto error1; |
| 506 | error = xfs_finish_flags(vfsp, args, mp); |
| 507 | if (error) |
| 508 | goto error2; |
| 509 | |
| 510 | /* |
| 511 | * Setup xfs_mount buffer target pointers based on superblock |
| 512 | */ |
| 513 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize, |
| 514 | mp->m_sb.sb_sectsize); |
| 515 | if (!error && logdev && logdev != ddev) { |
| 516 | unsigned int log_sector_size = BBSIZE; |
| 517 | |
| 518 | if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb)) |
| 519 | log_sector_size = mp->m_sb.sb_logsectsize; |
| 520 | error = xfs_setsize_buftarg(mp->m_logdev_targp, |
| 521 | mp->m_sb.sb_blocksize, |
| 522 | log_sector_size); |
| 523 | } |
| 524 | if (!error && rtdev) |
| 525 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, |
| 526 | mp->m_sb.sb_blocksize, |
| 527 | mp->m_sb.sb_sectsize); |
| 528 | if (error) |
| 529 | goto error2; |
| 530 | |
Nathan Scott | b2ea401 | 2006-07-28 17:05:13 +1000 | [diff] [blame] | 531 | if (mp->m_flags & XFS_MOUNT_BARRIER) |
Christoph Hellwig | c7d437d | 2006-01-11 15:28:56 +1100 | [diff] [blame] | 532 | xfs_mountfs_check_barriers(mp); |
| 533 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 534 | if ((error = xfs_filestream_mount(mp))) |
| 535 | goto error2; |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | error = XFS_IOINIT(vfsp, args, flags); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 538 | if (error) |
| 539 | goto error2; |
| 540 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 541 | return 0; |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | error2: |
| 544 | if (mp->m_sb_bp) |
| 545 | xfs_freesb(mp); |
| 546 | error1: |
| 547 | xfs_binval(mp->m_ddev_targp); |
| 548 | if (logdev && logdev != ddev) |
| 549 | xfs_binval(mp->m_logdev_targp); |
| 550 | if (rtdev) |
| 551 | xfs_binval(mp->m_rtdev_targp); |
| 552 | error0: |
| 553 | xfs_unmountfs_close(mp, credp); |
| 554 | return error; |
| 555 | } |
| 556 | |
| 557 | STATIC int |
| 558 | xfs_unmount( |
| 559 | bhv_desc_t *bdp, |
| 560 | int flags, |
| 561 | cred_t *credp) |
| 562 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 563 | bhv_vfs_t *vfsp = bhvtovfs(bdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | xfs_mount_t *mp = XFS_BHVTOM(bdp); |
| 565 | xfs_inode_t *rip; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 566 | bhv_vnode_t *rvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | int unmount_event_wanted = 0; |
| 568 | int unmount_event_flags = 0; |
| 569 | int xfs_unmountfs_needed = 0; |
| 570 | int error; |
| 571 | |
| 572 | rip = mp->m_rootip; |
| 573 | rvp = XFS_ITOV(rip); |
| 574 | |
| 575 | if (vfsp->vfs_flag & VFS_DMI) { |
| 576 | error = XFS_SEND_PREUNMOUNT(mp, vfsp, |
| 577 | rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL, |
| 578 | NULL, NULL, 0, 0, |
| 579 | (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))? |
| 580 | 0:DM_FLAGS_UNWANTED); |
| 581 | if (error) |
| 582 | return XFS_ERROR(error); |
| 583 | unmount_event_wanted = 1; |
| 584 | unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))? |
| 585 | 0 : DM_FLAGS_UNWANTED; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * First blow any referenced inode from this file system |
| 590 | * out of the reference cache, and delete the timer. |
| 591 | */ |
| 592 | xfs_refcache_purge_mp(mp); |
| 593 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 594 | /* |
| 595 | * Blow away any referenced inode in the filestreams cache. |
| 596 | * This can and will cause log traffic as inodes go inactive |
| 597 | * here. |
| 598 | */ |
| 599 | xfs_filestream_unmount(mp); |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | XFS_bflush(mp->m_ddev_targp); |
| 602 | error = xfs_unmount_flush(mp, 0); |
| 603 | if (error) |
| 604 | goto out; |
| 605 | |
| 606 | ASSERT(vn_count(rvp) == 1); |
| 607 | |
| 608 | /* |
| 609 | * Drop the reference count |
| 610 | */ |
| 611 | VN_RELE(rvp); |
| 612 | |
| 613 | /* |
| 614 | * If we're forcing a shutdown, typically because of a media error, |
| 615 | * we want to make sure we invalidate dirty pages that belong to |
| 616 | * referenced vnodes as well. |
| 617 | */ |
| 618 | if (XFS_FORCED_SHUTDOWN(mp)) { |
| 619 | error = xfs_sync(&mp->m_bhv, |
| 620 | (SYNC_WAIT | SYNC_CLOSE), credp); |
| 621 | ASSERT(error != EFSCORRUPTED); |
| 622 | } |
| 623 | xfs_unmountfs_needed = 1; |
| 624 | |
| 625 | out: |
| 626 | /* Send DMAPI event, if required. |
| 627 | * Then do xfs_unmountfs() if needed. |
| 628 | * Then return error (or zero). |
| 629 | */ |
| 630 | if (unmount_event_wanted) { |
| 631 | /* Note: mp structure must still exist for |
| 632 | * XFS_SEND_UNMOUNT() call. |
| 633 | */ |
| 634 | XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL, |
| 635 | DM_RIGHT_NULL, 0, error, unmount_event_flags); |
| 636 | } |
| 637 | if (xfs_unmountfs_needed) { |
| 638 | /* |
| 639 | * Call common unmount function to flush to disk |
| 640 | * and free the super block buffer & mount structures. |
| 641 | */ |
| 642 | xfs_unmountfs(mp, credp); |
| 643 | } |
| 644 | |
| 645 | return XFS_ERROR(error); |
| 646 | } |
| 647 | |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 648 | STATIC int |
| 649 | xfs_quiesce_fs( |
| 650 | xfs_mount_t *mp) |
| 651 | { |
| 652 | int count = 0, pincount; |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 653 | |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 654 | xfs_refcache_purge_mp(mp); |
| 655 | xfs_flush_buftarg(mp->m_ddev_targp, 0); |
| 656 | xfs_finish_reclaim_all(mp, 0); |
| 657 | |
| 658 | /* This loop must run at least twice. |
| 659 | * The first instance of the loop will flush |
| 660 | * most meta data but that will generate more |
| 661 | * meta data (typically directory updates). |
| 662 | * Which then must be flushed and logged before |
| 663 | * we can write the unmount record. |
Nathan Scott | 3758dee | 2006-03-22 12:47:28 +1100 | [diff] [blame] | 664 | */ |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 665 | do { |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 666 | xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL); |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 667 | pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1); |
| 668 | if (!pincount) { |
| 669 | delay(50); |
| 670 | count++; |
| 671 | } |
| 672 | } while (count < 2); |
| 673 | |
| 674 | return 0; |
| 675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 677 | /* |
| 678 | * Second stage of a quiesce. The data is already synced, now we have to take |
| 679 | * care of the metadata. New transactions are already blocked, so we need to |
| 680 | * wait for any remaining transactions to drain out before proceding. |
| 681 | */ |
| 682 | STATIC void |
| 683 | xfs_attr_quiesce( |
| 684 | xfs_mount_t *mp) |
| 685 | { |
| 686 | /* wait for all modifications to complete */ |
| 687 | while (atomic_read(&mp->m_active_trans) > 0) |
| 688 | delay(100); |
| 689 | |
| 690 | /* flush inodes and push all remaining buffers out to disk */ |
| 691 | xfs_quiesce_fs(mp); |
| 692 | |
| 693 | ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0); |
| 694 | |
| 695 | /* Push the superblock and write an unmount record */ |
| 696 | xfs_log_sbcount(mp, 1); |
| 697 | xfs_log_unmount_write(mp); |
| 698 | xfs_unmountfs_writesb(mp); |
| 699 | } |
| 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | STATIC int |
| 702 | xfs_mntupdate( |
| 703 | bhv_desc_t *bdp, |
| 704 | int *flags, |
| 705 | struct xfs_mount_args *args) |
| 706 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 707 | bhv_vfs_t *vfsp = bhvtovfs(bdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | xfs_mount_t *mp = XFS_BHVTOM(bdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Nathan Scott | d08d389 | 2006-05-08 19:51:28 +1000 | [diff] [blame] | 710 | if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */ |
| 711 | if (vfsp->vfs_flag & VFS_RDONLY) |
| 712 | vfsp->vfs_flag &= ~VFS_RDONLY; |
| 713 | if (args->flags & XFSMNT_BARRIER) { |
| 714 | mp->m_flags |= XFS_MOUNT_BARRIER; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 715 | xfs_mountfs_check_barriers(mp); |
Nathan Scott | d08d389 | 2006-05-08 19:51:28 +1000 | [diff] [blame] | 716 | } else { |
| 717 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
| 718 | } |
| 719 | } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */ |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 720 | xfs_filestream_flush(mp); |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 721 | bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL); |
| 722 | xfs_attr_quiesce(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | vfsp->vfs_flag |= VFS_RDONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | /* |
| 729 | * xfs_unmount_flush implements a set of flush operation on special |
| 730 | * inodes, which are needed as a separate set of operations so that |
| 731 | * they can be called as part of relocation process. |
| 732 | */ |
| 733 | int |
| 734 | xfs_unmount_flush( |
| 735 | xfs_mount_t *mp, /* Mount structure we are getting |
| 736 | rid of. */ |
| 737 | int relocation) /* Called from vfs relocation. */ |
| 738 | { |
| 739 | xfs_inode_t *rip = mp->m_rootip; |
| 740 | xfs_inode_t *rbmip; |
| 741 | xfs_inode_t *rsumip = NULL; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 742 | bhv_vnode_t *rvp = XFS_ITOV(rip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | int error; |
| 744 | |
Lachlan McIlroy | f7c66ce | 2007-05-08 13:50:19 +1000 | [diff] [blame] | 745 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | xfs_iflock(rip); |
| 747 | |
| 748 | /* |
| 749 | * Flush out the real time inodes. |
| 750 | */ |
| 751 | if ((rbmip = mp->m_rbmip) != NULL) { |
| 752 | xfs_ilock(rbmip, XFS_ILOCK_EXCL); |
| 753 | xfs_iflock(rbmip); |
| 754 | error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC); |
| 755 | xfs_iunlock(rbmip, XFS_ILOCK_EXCL); |
| 756 | |
| 757 | if (error == EFSCORRUPTED) |
| 758 | goto fscorrupt_out; |
| 759 | |
| 760 | ASSERT(vn_count(XFS_ITOV(rbmip)) == 1); |
| 761 | |
| 762 | rsumip = mp->m_rsumip; |
| 763 | xfs_ilock(rsumip, XFS_ILOCK_EXCL); |
| 764 | xfs_iflock(rsumip); |
| 765 | error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC); |
| 766 | xfs_iunlock(rsumip, XFS_ILOCK_EXCL); |
| 767 | |
| 768 | if (error == EFSCORRUPTED) |
| 769 | goto fscorrupt_out; |
| 770 | |
| 771 | ASSERT(vn_count(XFS_ITOV(rsumip)) == 1); |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Synchronously flush root inode to disk |
| 776 | */ |
| 777 | error = xfs_iflush(rip, XFS_IFLUSH_SYNC); |
| 778 | if (error == EFSCORRUPTED) |
| 779 | goto fscorrupt_out2; |
| 780 | |
| 781 | if (vn_count(rvp) != 1 && !relocation) { |
| 782 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 783 | return XFS_ERROR(EBUSY); |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | * Release dquot that rootinode, rbmino and rsumino might be holding, |
| 788 | * flush and purge the quota inodes. |
| 789 | */ |
| 790 | error = XFS_QM_UNMOUNT(mp); |
| 791 | if (error == EFSCORRUPTED) |
| 792 | goto fscorrupt_out2; |
| 793 | |
| 794 | if (rbmip) { |
| 795 | VN_RELE(XFS_ITOV(rbmip)); |
| 796 | VN_RELE(XFS_ITOV(rsumip)); |
| 797 | } |
| 798 | |
| 799 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 800 | return 0; |
| 801 | |
| 802 | fscorrupt_out: |
| 803 | xfs_ifunlock(rip); |
| 804 | |
| 805 | fscorrupt_out2: |
| 806 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
| 807 | |
| 808 | return XFS_ERROR(EFSCORRUPTED); |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * xfs_root extracts the root vnode from a vfs. |
| 813 | * |
| 814 | * vfsp -- the vfs struct for the desired file system |
| 815 | * vpp -- address of the caller's vnode pointer which should be |
| 816 | * set to the desired fs root vnode |
| 817 | */ |
| 818 | STATIC int |
| 819 | xfs_root( |
| 820 | bhv_desc_t *bdp, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 821 | bhv_vnode_t **vpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 823 | bhv_vnode_t *vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip); |
| 826 | VN_HOLD(vp); |
| 827 | *vpp = vp; |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | /* |
| 832 | * xfs_statvfs |
| 833 | * |
| 834 | * Fill in the statvfs structure for the given file system. We use |
| 835 | * the superblock lock in the mount structure to ensure a consistent |
| 836 | * snapshot of the counters returned. |
| 837 | */ |
| 838 | STATIC int |
| 839 | xfs_statvfs( |
| 840 | bhv_desc_t *bdp, |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 841 | bhv_statvfs_t *statp, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 842 | bhv_vnode_t *vp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | { |
| 844 | __uint64_t fakeinos; |
| 845 | xfs_extlen_t lsize; |
| 846 | xfs_mount_t *mp; |
| 847 | xfs_sb_t *sbp; |
| 848 | unsigned long s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | mp = XFS_BHVTOM(bdp); |
| 851 | sbp = &(mp->m_sb); |
| 852 | |
| 853 | statp->f_type = XFS_SB_MAGIC; |
| 854 | |
David Chinner | dbcabad | 2007-02-10 18:36:17 +1100 | [diff] [blame] | 855 | xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | s = XFS_SB_LOCK(mp); |
| 857 | statp->f_bsize = sbp->sb_blocksize; |
| 858 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; |
| 859 | statp->f_blocks = sbp->sb_dblocks - lsize; |
David Chinner | 4be536d | 2006-09-07 14:26:50 +1000 | [diff] [blame] | 860 | statp->f_bfree = statp->f_bavail = |
| 861 | sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | fakeinos = statp->f_bfree << sbp->sb_inopblog; |
| 863 | #if XFS_BIG_INUMS |
| 864 | fakeinos += mp->m_inoadd; |
| 865 | #endif |
| 866 | statp->f_files = |
| 867 | MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); |
| 868 | if (mp->m_maxicount) |
| 869 | #if XFS_BIG_INUMS |
| 870 | if (!mp->m_inoadd) |
| 871 | #endif |
| 872 | statp->f_files = min_t(typeof(statp->f_files), |
| 873 | statp->f_files, |
| 874 | mp->m_maxicount); |
| 875 | statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); |
| 876 | XFS_SB_UNLOCK(mp, s); |
| 877 | |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 878 | xfs_statvfs_fsid(statp, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | statp->f_namelen = MAXNAMELEN - 1; |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | |
| 885 | /* |
| 886 | * xfs_sync flushes any pending I/O to file system vfsp. |
| 887 | * |
| 888 | * This routine is called by vfs_sync() to make sure that things make it |
| 889 | * out to disk eventually, on sync() system calls to flush out everything, |
| 890 | * and when the file system is unmounted. For the vfs_sync() case, all |
| 891 | * we really need to do is sync out the log to make all of our meta-data |
| 892 | * updates permanent (except for timestamps). For calls from pflushd(), |
| 893 | * dirty pages are kept moving by calling pdflush() on the inodes |
| 894 | * containing them. We also flush the inodes that we can lock without |
| 895 | * sleeping and the superblock if we can lock it without sleeping from |
| 896 | * vfs_sync() so that items at the tail of the log are always moving out. |
| 897 | * |
| 898 | * Flags: |
| 899 | * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want |
| 900 | * to sleep if we can help it. All we really need |
| 901 | * to do is ensure that the log is synced at least |
| 902 | * periodically. We also push the inodes and |
| 903 | * superblock if we can lock them without sleeping |
| 904 | * and they are not pinned. |
| 905 | * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not |
| 906 | * set, then we really want to lock each inode and flush |
| 907 | * it. |
| 908 | * SYNC_WAIT - All the flushes that take place in this call should |
| 909 | * be synchronous. |
| 910 | * SYNC_DELWRI - This tells us to push dirty pages associated with |
| 911 | * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to |
| 912 | * determine if they should be flushed sync, async, or |
| 913 | * delwri. |
| 914 | * SYNC_CLOSE - This flag is passed when the system is being |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 915 | * unmounted. We should sync and invalidate everything. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | * SYNC_FSDATA - This indicates that the caller would like to make |
| 917 | * sure the superblock is safe on disk. We can ensure |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 918 | * this by simply making sure the log gets flushed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | * if SYNC_BDFLUSH is set, and by actually writing it |
| 920 | * out otherwise. |
David Chinner | 3c0dc77 | 2007-02-10 18:37:22 +1100 | [diff] [blame] | 921 | * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete |
| 922 | * before we return (including direct I/O). Forms the drain |
| 923 | * side of the write barrier needed to safely quiesce the |
| 924 | * filesystem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | * |
| 926 | */ |
| 927 | /*ARGSUSED*/ |
| 928 | STATIC int |
| 929 | xfs_sync( |
| 930 | bhv_desc_t *bdp, |
| 931 | int flags, |
| 932 | cred_t *credp) |
| 933 | { |
Christoph Hellwig | f898d6c | 2005-06-21 15:40:48 +1000 | [diff] [blame] | 934 | xfs_mount_t *mp = XFS_BHVTOM(bdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 936 | if (flags & SYNC_IOWAIT) |
| 937 | xfs_filestream_flush(mp); |
| 938 | |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 939 | return xfs_syncsub(mp, flags, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /* |
| 943 | * xfs sync routine for internal use |
| 944 | * |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 945 | * 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] | 946 | * interface as explained above under xfs_sync. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | * |
| 948 | */ |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 949 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | xfs_sync_inodes( |
| 951 | xfs_mount_t *mp, |
| 952 | int flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | int *bypassed) |
| 954 | { |
| 955 | xfs_inode_t *ip = NULL; |
| 956 | xfs_inode_t *ip_next; |
| 957 | xfs_buf_t *bp; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 958 | bhv_vnode_t *vp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | int error; |
| 960 | int last_error; |
| 961 | uint64_t fflag; |
| 962 | uint lock_flags; |
| 963 | uint base_lock_flags; |
| 964 | boolean_t mount_locked; |
| 965 | boolean_t vnode_refed; |
| 966 | int preempt; |
| 967 | xfs_dinode_t *dip; |
| 968 | xfs_iptr_t *ipointer; |
| 969 | #ifdef DEBUG |
| 970 | boolean_t ipointer_in = B_FALSE; |
| 971 | |
| 972 | #define IPOINTER_SET ipointer_in = B_TRUE |
| 973 | #define IPOINTER_CLR ipointer_in = B_FALSE |
| 974 | #else |
| 975 | #define IPOINTER_SET |
| 976 | #define IPOINTER_CLR |
| 977 | #endif |
| 978 | |
| 979 | |
| 980 | /* Insert a marker record into the inode list after inode ip. The list |
| 981 | * must be locked when this is called. After the call the list will no |
| 982 | * longer be locked. |
| 983 | */ |
| 984 | #define IPOINTER_INSERT(ip, mp) { \ |
| 985 | ASSERT(ipointer_in == B_FALSE); \ |
| 986 | ipointer->ip_mnext = ip->i_mnext; \ |
| 987 | ipointer->ip_mprev = ip; \ |
| 988 | ip->i_mnext = (xfs_inode_t *)ipointer; \ |
| 989 | ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \ |
| 990 | preempt = 0; \ |
| 991 | XFS_MOUNT_IUNLOCK(mp); \ |
| 992 | mount_locked = B_FALSE; \ |
| 993 | IPOINTER_SET; \ |
| 994 | } |
| 995 | |
| 996 | /* Remove the marker from the inode list. If the marker was the only item |
| 997 | * in the list then there are no remaining inodes and we should zero out |
| 998 | * the whole list. If we are the current head of the list then move the head |
| 999 | * past us. |
| 1000 | */ |
| 1001 | #define IPOINTER_REMOVE(ip, mp) { \ |
| 1002 | ASSERT(ipointer_in == B_TRUE); \ |
| 1003 | if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \ |
| 1004 | ip = ipointer->ip_mnext; \ |
| 1005 | ip->i_mprev = ipointer->ip_mprev; \ |
| 1006 | ipointer->ip_mprev->i_mnext = ip; \ |
| 1007 | if (mp->m_inodes == (xfs_inode_t *)ipointer) { \ |
| 1008 | mp->m_inodes = ip; \ |
| 1009 | } \ |
| 1010 | } else { \ |
| 1011 | ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \ |
| 1012 | mp->m_inodes = NULL; \ |
| 1013 | ip = NULL; \ |
| 1014 | } \ |
| 1015 | IPOINTER_CLR; \ |
| 1016 | } |
| 1017 | |
| 1018 | #define XFS_PREEMPT_MASK 0x7f |
| 1019 | |
| 1020 | if (bypassed) |
| 1021 | *bypassed = 0; |
| 1022 | if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY) |
| 1023 | return 0; |
| 1024 | error = 0; |
| 1025 | last_error = 0; |
| 1026 | preempt = 0; |
| 1027 | |
| 1028 | /* Allocate a reference marker */ |
| 1029 | ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP); |
| 1030 | |
| 1031 | fflag = XFS_B_ASYNC; /* default is don't wait */ |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 1032 | if (flags & (SYNC_BDFLUSH | SYNC_DELWRI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | fflag = XFS_B_DELWRI; |
| 1034 | if (flags & SYNC_WAIT) |
| 1035 | fflag = 0; /* synchronous overrides all */ |
| 1036 | |
| 1037 | base_lock_flags = XFS_ILOCK_SHARED; |
| 1038 | if (flags & (SYNC_DELWRI | SYNC_CLOSE)) { |
| 1039 | /* |
| 1040 | * We need the I/O lock if we're going to call any of |
| 1041 | * the flush/inval routines. |
| 1042 | */ |
| 1043 | base_lock_flags |= XFS_IOLOCK_SHARED; |
| 1044 | } |
| 1045 | |
| 1046 | XFS_MOUNT_ILOCK(mp); |
| 1047 | |
| 1048 | ip = mp->m_inodes; |
| 1049 | |
| 1050 | mount_locked = B_TRUE; |
| 1051 | vnode_refed = B_FALSE; |
| 1052 | |
| 1053 | IPOINTER_CLR; |
| 1054 | |
| 1055 | do { |
| 1056 | ASSERT(ipointer_in == B_FALSE); |
| 1057 | ASSERT(vnode_refed == B_FALSE); |
| 1058 | |
| 1059 | lock_flags = base_lock_flags; |
| 1060 | |
| 1061 | /* |
| 1062 | * There were no inodes in the list, just break out |
| 1063 | * of the loop. |
| 1064 | */ |
| 1065 | if (ip == NULL) { |
| 1066 | break; |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * We found another sync thread marker - skip it |
| 1071 | */ |
| 1072 | if (ip->i_mount == NULL) { |
| 1073 | ip = ip->i_mnext; |
| 1074 | continue; |
| 1075 | } |
| 1076 | |
| 1077 | vp = XFS_ITOV_NULL(ip); |
| 1078 | |
| 1079 | /* |
| 1080 | * If the vnode is gone then this is being torn down, |
| 1081 | * call reclaim if it is flushed, else let regular flush |
| 1082 | * code deal with it later in the loop. |
| 1083 | */ |
| 1084 | |
| 1085 | if (vp == NULL) { |
| 1086 | /* Skip ones already in reclaim */ |
| 1087 | if (ip->i_flags & XFS_IRECLAIM) { |
| 1088 | ip = ip->i_mnext; |
| 1089 | continue; |
| 1090 | } |
| 1091 | if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) { |
| 1092 | ip = ip->i_mnext; |
| 1093 | } else if ((xfs_ipincount(ip) == 0) && |
| 1094 | xfs_iflock_nowait(ip)) { |
| 1095 | IPOINTER_INSERT(ip, mp); |
| 1096 | |
| 1097 | xfs_finish_reclaim(ip, 1, |
| 1098 | XFS_IFLUSH_DELWRI_ELSE_ASYNC); |
| 1099 | |
| 1100 | XFS_MOUNT_ILOCK(mp); |
| 1101 | mount_locked = B_TRUE; |
| 1102 | IPOINTER_REMOVE(ip, mp); |
| 1103 | } else { |
| 1104 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1105 | ip = ip->i_mnext; |
| 1106 | } |
| 1107 | continue; |
| 1108 | } |
| 1109 | |
| 1110 | if (VN_BAD(vp)) { |
| 1111 | ip = ip->i_mnext; |
| 1112 | continue; |
| 1113 | } |
| 1114 | |
| 1115 | if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) { |
| 1116 | XFS_MOUNT_IUNLOCK(mp); |
| 1117 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | /* |
| 1122 | * If this is just vfs_sync() or pflushd() calling |
| 1123 | * then we can skip inodes for which it looks like |
| 1124 | * there is nothing to do. Since we don't have the |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1125 | * inode locked this is racy, but these are periodic |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | * calls so it doesn't matter. For the others we want |
| 1127 | * to know for sure, so we at least try to lock them. |
| 1128 | */ |
| 1129 | if (flags & SYNC_BDFLUSH) { |
| 1130 | if (((ip->i_itemp == NULL) || |
| 1131 | !(ip->i_itemp->ili_format.ilf_fields & |
| 1132 | XFS_ILOG_ALL)) && |
| 1133 | (ip->i_update_core == 0)) { |
| 1134 | ip = ip->i_mnext; |
| 1135 | continue; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | * Try to lock without sleeping. We're out of order with |
| 1141 | * the inode list lock here, so if we fail we need to drop |
| 1142 | * the mount lock and try again. If we're called from |
| 1143 | * bdflush() here, then don't bother. |
| 1144 | * |
| 1145 | * The inode lock here actually coordinates with the |
| 1146 | * almost spurious inode lock in xfs_ireclaim() to prevent |
| 1147 | * the vnode we handle here without a reference from |
| 1148 | * being freed while we reference it. If we lock the inode |
| 1149 | * while it's on the mount list here, then the spurious inode |
| 1150 | * lock in xfs_ireclaim() after the inode is pulled from |
| 1151 | * the mount list will sleep until we release it here. |
| 1152 | * This keeps the vnode from being freed while we reference |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1153 | * it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | */ |
| 1155 | if (xfs_ilock_nowait(ip, lock_flags) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | if ((flags & SYNC_BDFLUSH) || (vp == NULL)) { |
| 1157 | ip = ip->i_mnext; |
| 1158 | continue; |
| 1159 | } |
| 1160 | |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1161 | vp = vn_grab(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | if (vp == NULL) { |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1163 | ip = ip->i_mnext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | continue; |
| 1165 | } |
| 1166 | |
Christoph Hellwig | cdb6268 | 2005-09-02 16:24:19 +1000 | [diff] [blame] | 1167 | IPOINTER_INSERT(ip, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | xfs_ilock(ip, lock_flags); |
| 1169 | |
| 1170 | ASSERT(vp == XFS_ITOV(ip)); |
| 1171 | ASSERT(ip->i_mount == mp); |
| 1172 | |
| 1173 | vnode_refed = B_TRUE; |
| 1174 | } |
| 1175 | |
| 1176 | /* From here on in the loop we may have a marker record |
| 1177 | * in the inode list. |
| 1178 | */ |
| 1179 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1180 | /* |
| 1181 | * If we have to flush data or wait for I/O completion |
| 1182 | * we need to drop the ilock that we currently hold. |
| 1183 | * If we need to drop the lock, insert a marker if we |
| 1184 | * have not already done so. |
| 1185 | */ |
| 1186 | if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) || |
| 1187 | ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) { |
| 1188 | if (mount_locked) { |
| 1189 | IPOINTER_INSERT(ip, mp); |
| 1190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 1192 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1193 | if (flags & SYNC_CLOSE) { |
| 1194 | /* Shutdown case. Flush and invalidate. */ |
| 1195 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 1196 | bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF); |
| 1197 | else |
| 1198 | error = bhv_vop_flushinval_pages(vp, 0, |
| 1199 | -1, FI_REMAPF); |
| 1200 | } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 1201 | error = bhv_vop_flush_pages(vp, (xfs_off_t)0, |
| 1202 | -1, fflag, FI_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
David Chinner | 40095b6 | 2007-05-14 18:24:09 +1000 | [diff] [blame] | 1205 | /* |
| 1206 | * When freezing, we need to wait ensure all I/O (including direct |
| 1207 | * I/O) is complete to ensure no further data modification can take |
| 1208 | * place after this point |
| 1209 | */ |
| 1210 | if (flags & SYNC_IOWAIT) |
| 1211 | vn_iowait(vp); |
| 1212 | |
| 1213 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (flags & SYNC_BDFLUSH) { |
| 1217 | if ((flags & SYNC_ATTR) && |
| 1218 | ((ip->i_update_core) || |
| 1219 | ((ip->i_itemp != NULL) && |
| 1220 | (ip->i_itemp->ili_format.ilf_fields != 0)))) { |
| 1221 | |
| 1222 | /* Insert marker and drop lock if not already |
| 1223 | * done. |
| 1224 | */ |
| 1225 | if (mount_locked) { |
| 1226 | IPOINTER_INSERT(ip, mp); |
| 1227 | } |
| 1228 | |
| 1229 | /* |
| 1230 | * We don't want the periodic flushing of the |
| 1231 | * inodes by vfs_sync() to interfere with |
| 1232 | * I/O to the file, especially read I/O |
| 1233 | * where it is only the access time stamp |
| 1234 | * that is being flushed out. To prevent |
| 1235 | * long periods where we have both inode |
| 1236 | * locks held shared here while reading the |
| 1237 | * inode's buffer in from disk, we drop the |
| 1238 | * inode lock while reading in the inode |
| 1239 | * buffer. We have to release the buffer |
| 1240 | * and reacquire the inode lock so that they |
| 1241 | * are acquired in the proper order (inode |
| 1242 | * locks first). The buffer will go at the |
| 1243 | * end of the lru chain, though, so we can |
| 1244 | * expect it to still be there when we go |
| 1245 | * for it again in xfs_iflush(). |
| 1246 | */ |
| 1247 | if ((xfs_ipincount(ip) == 0) && |
| 1248 | xfs_iflock_nowait(ip)) { |
| 1249 | |
| 1250 | xfs_ifunlock(ip); |
| 1251 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 1252 | |
| 1253 | error = xfs_itobp(mp, NULL, ip, |
Nathan Scott | b12dd34 | 2006-03-17 17:26:04 +1100 | [diff] [blame] | 1254 | &dip, &bp, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | if (!error) { |
| 1256 | xfs_buf_relse(bp); |
| 1257 | } else { |
| 1258 | /* Bailing out, remove the |
| 1259 | * marker and free it. |
| 1260 | */ |
| 1261 | XFS_MOUNT_ILOCK(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | IPOINTER_REMOVE(ip, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | XFS_MOUNT_IUNLOCK(mp); |
| 1264 | |
| 1265 | ASSERT(!(lock_flags & |
| 1266 | XFS_IOLOCK_SHARED)); |
| 1267 | |
| 1268 | kmem_free(ipointer, |
| 1269 | sizeof(xfs_iptr_t)); |
| 1270 | return (0); |
| 1271 | } |
| 1272 | |
| 1273 | /* |
| 1274 | * Since we dropped the inode lock, |
| 1275 | * the inode may have been reclaimed. |
| 1276 | * Therefore, we reacquire the mount |
| 1277 | * lock and check to see if we were the |
| 1278 | * inode reclaimed. If this happened |
| 1279 | * then the ipointer marker will no |
| 1280 | * longer point back at us. In this |
| 1281 | * case, move ip along to the inode |
| 1282 | * after the marker, remove the marker |
| 1283 | * and continue. |
| 1284 | */ |
| 1285 | XFS_MOUNT_ILOCK(mp); |
| 1286 | mount_locked = B_TRUE; |
| 1287 | |
| 1288 | if (ip != ipointer->ip_mprev) { |
| 1289 | IPOINTER_REMOVE(ip, mp); |
| 1290 | |
| 1291 | ASSERT(!vnode_refed); |
| 1292 | ASSERT(!(lock_flags & |
| 1293 | XFS_IOLOCK_SHARED)); |
| 1294 | continue; |
| 1295 | } |
| 1296 | |
| 1297 | ASSERT(ip->i_mount == mp); |
| 1298 | |
| 1299 | if (xfs_ilock_nowait(ip, |
| 1300 | XFS_ILOCK_SHARED) == 0) { |
| 1301 | ASSERT(ip->i_mount == mp); |
| 1302 | /* |
| 1303 | * We failed to reacquire |
| 1304 | * the inode lock without |
| 1305 | * sleeping, so just skip |
| 1306 | * the inode for now. We |
| 1307 | * clear the ILOCK bit from |
| 1308 | * the lock_flags so that we |
| 1309 | * won't try to drop a lock |
| 1310 | * we don't hold below. |
| 1311 | */ |
| 1312 | lock_flags &= ~XFS_ILOCK_SHARED; |
| 1313 | IPOINTER_REMOVE(ip_next, mp); |
| 1314 | } else if ((xfs_ipincount(ip) == 0) && |
| 1315 | xfs_iflock_nowait(ip)) { |
| 1316 | ASSERT(ip->i_mount == mp); |
| 1317 | /* |
| 1318 | * Since this is vfs_sync() |
| 1319 | * calling we only flush the |
| 1320 | * inode out if we can lock |
| 1321 | * it without sleeping and |
| 1322 | * it is not pinned. Drop |
| 1323 | * the mount lock here so |
| 1324 | * that we don't hold it for |
| 1325 | * too long. We already have |
| 1326 | * a marker in the list here. |
| 1327 | */ |
| 1328 | XFS_MOUNT_IUNLOCK(mp); |
| 1329 | mount_locked = B_FALSE; |
| 1330 | error = xfs_iflush(ip, |
| 1331 | XFS_IFLUSH_DELWRI); |
| 1332 | } else { |
| 1333 | ASSERT(ip->i_mount == mp); |
| 1334 | IPOINTER_REMOVE(ip_next, mp); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | } |
| 1339 | |
| 1340 | } else { |
| 1341 | if ((flags & SYNC_ATTR) && |
| 1342 | ((ip->i_update_core) || |
| 1343 | ((ip->i_itemp != NULL) && |
| 1344 | (ip->i_itemp->ili_format.ilf_fields != 0)))) { |
| 1345 | if (mount_locked) { |
| 1346 | IPOINTER_INSERT(ip, mp); |
| 1347 | } |
| 1348 | |
| 1349 | if (flags & SYNC_WAIT) { |
| 1350 | xfs_iflock(ip); |
| 1351 | error = xfs_iflush(ip, |
| 1352 | XFS_IFLUSH_SYNC); |
| 1353 | } else { |
| 1354 | /* |
| 1355 | * If we can't acquire the flush |
| 1356 | * lock, then the inode is already |
| 1357 | * being flushed so don't bother |
| 1358 | * waiting. If we can lock it then |
| 1359 | * do a delwri flush so we can |
| 1360 | * combine multiple inode flushes |
| 1361 | * in each disk write. |
| 1362 | */ |
| 1363 | if (xfs_iflock_nowait(ip)) { |
| 1364 | error = xfs_iflush(ip, |
| 1365 | XFS_IFLUSH_DELWRI); |
| 1366 | } |
| 1367 | else if (bypassed) |
| 1368 | (*bypassed)++; |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | if (lock_flags != 0) { |
| 1374 | xfs_iunlock(ip, lock_flags); |
| 1375 | } |
| 1376 | |
| 1377 | if (vnode_refed) { |
| 1378 | /* |
| 1379 | * If we had to take a reference on the vnode |
| 1380 | * above, then wait until after we've unlocked |
| 1381 | * the inode to release the reference. This is |
| 1382 | * because we can be already holding the inode |
| 1383 | * lock when VN_RELE() calls xfs_inactive(). |
| 1384 | * |
| 1385 | * Make sure to drop the mount lock before calling |
| 1386 | * VN_RELE() so that we don't trip over ourselves if |
| 1387 | * we have to go for the mount lock again in the |
| 1388 | * inactive code. |
| 1389 | */ |
| 1390 | if (mount_locked) { |
| 1391 | IPOINTER_INSERT(ip, mp); |
| 1392 | } |
| 1393 | |
| 1394 | VN_RELE(vp); |
| 1395 | |
| 1396 | vnode_refed = B_FALSE; |
| 1397 | } |
| 1398 | |
| 1399 | if (error) { |
| 1400 | last_error = error; |
| 1401 | } |
| 1402 | |
| 1403 | /* |
| 1404 | * bail out if the filesystem is corrupted. |
| 1405 | */ |
| 1406 | if (error == EFSCORRUPTED) { |
| 1407 | if (!mount_locked) { |
| 1408 | XFS_MOUNT_ILOCK(mp); |
| 1409 | IPOINTER_REMOVE(ip, mp); |
| 1410 | } |
| 1411 | XFS_MOUNT_IUNLOCK(mp); |
| 1412 | ASSERT(ipointer_in == B_FALSE); |
| 1413 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1414 | return XFS_ERROR(error); |
| 1415 | } |
| 1416 | |
| 1417 | /* Let other threads have a chance at the mount lock |
| 1418 | * if we have looped many times without dropping the |
| 1419 | * lock. |
| 1420 | */ |
| 1421 | if ((++preempt & XFS_PREEMPT_MASK) == 0) { |
| 1422 | if (mount_locked) { |
| 1423 | IPOINTER_INSERT(ip, mp); |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | if (mount_locked == B_FALSE) { |
| 1428 | XFS_MOUNT_ILOCK(mp); |
| 1429 | mount_locked = B_TRUE; |
| 1430 | IPOINTER_REMOVE(ip, mp); |
| 1431 | continue; |
| 1432 | } |
| 1433 | |
| 1434 | ASSERT(ipointer_in == B_FALSE); |
| 1435 | ip = ip->i_mnext; |
| 1436 | |
| 1437 | } while (ip != mp->m_inodes); |
| 1438 | |
| 1439 | XFS_MOUNT_IUNLOCK(mp); |
| 1440 | |
| 1441 | ASSERT(ipointer_in == B_FALSE); |
| 1442 | |
| 1443 | kmem_free(ipointer, sizeof(xfs_iptr_t)); |
| 1444 | return XFS_ERROR(last_error); |
| 1445 | } |
| 1446 | |
| 1447 | /* |
| 1448 | * xfs sync routine for internal use |
| 1449 | * |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1450 | * 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] | 1451 | * interface as explained above under xfs_sync. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | * |
| 1453 | */ |
| 1454 | int |
| 1455 | xfs_syncsub( |
| 1456 | xfs_mount_t *mp, |
| 1457 | int flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | int *bypassed) |
| 1459 | { |
| 1460 | int error = 0; |
| 1461 | int last_error = 0; |
| 1462 | uint log_flags = XFS_LOG_FORCE; |
| 1463 | xfs_buf_t *bp; |
| 1464 | xfs_buf_log_item_t *bip; |
| 1465 | |
| 1466 | /* |
| 1467 | * Sync out the log. This ensures that the log is periodically |
| 1468 | * flushed even if there is not enough activity to fill it up. |
| 1469 | */ |
| 1470 | if (flags & SYNC_WAIT) |
| 1471 | log_flags |= XFS_LOG_SYNC; |
| 1472 | |
| 1473 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1474 | |
| 1475 | if (flags & (SYNC_ATTR|SYNC_DELWRI)) { |
| 1476 | if (flags & SYNC_BDFLUSH) |
| 1477 | xfs_finish_reclaim_all(mp, 1); |
| 1478 | else |
Lachlan McIlroy | 1f9b3b6 | 2007-02-10 18:35:33 +1100 | [diff] [blame] | 1479 | error = xfs_sync_inodes(mp, flags, bypassed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /* |
| 1483 | * Flushing out dirty data above probably generated more |
| 1484 | * log activity, so if this isn't vfs_sync() then flush |
| 1485 | * the log again. |
| 1486 | */ |
| 1487 | if (flags & SYNC_DELWRI) { |
| 1488 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1489 | } |
| 1490 | |
| 1491 | if (flags & SYNC_FSDATA) { |
| 1492 | /* |
| 1493 | * If this is vfs_sync() then only sync the superblock |
| 1494 | * if we can lock it without sleeping and it is not pinned. |
| 1495 | */ |
| 1496 | if (flags & SYNC_BDFLUSH) { |
| 1497 | bp = xfs_getsb(mp, XFS_BUF_TRYLOCK); |
| 1498 | if (bp != NULL) { |
| 1499 | bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*); |
| 1500 | if ((bip != NULL) && |
| 1501 | xfs_buf_item_dirty(bip)) { |
| 1502 | if (!(XFS_BUF_ISPINNED(bp))) { |
| 1503 | XFS_BUF_ASYNC(bp); |
| 1504 | error = xfs_bwrite(mp, bp); |
| 1505 | } else { |
| 1506 | xfs_buf_relse(bp); |
| 1507 | } |
| 1508 | } else { |
| 1509 | xfs_buf_relse(bp); |
| 1510 | } |
| 1511 | } |
| 1512 | } else { |
| 1513 | bp = xfs_getsb(mp, 0); |
| 1514 | /* |
| 1515 | * If the buffer is pinned then push on the log so |
| 1516 | * we won't get stuck waiting in the write for |
| 1517 | * someone, maybe ourselves, to flush the log. |
| 1518 | * Even though we just pushed the log above, we |
| 1519 | * did not have the superblock buffer locked at |
| 1520 | * that point so it can become pinned in between |
| 1521 | * there and here. |
| 1522 | */ |
| 1523 | if (XFS_BUF_ISPINNED(bp)) |
| 1524 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE); |
| 1525 | if (flags & SYNC_WAIT) |
| 1526 | XFS_BUF_UNASYNC(bp); |
| 1527 | else |
| 1528 | XFS_BUF_ASYNC(bp); |
| 1529 | error = xfs_bwrite(mp, bp); |
| 1530 | } |
| 1531 | if (error) { |
| 1532 | last_error = error; |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * If this is the periodic sync, then kick some entries out of |
| 1538 | * the reference cache. This ensures that idle entries are |
| 1539 | * eventually kicked out of the cache. |
| 1540 | */ |
| 1541 | if (flags & SYNC_REFCACHE) { |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 1542 | if (flags & SYNC_WAIT) |
| 1543 | xfs_refcache_purge_mp(mp); |
| 1544 | else |
| 1545 | xfs_refcache_purge_some(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /* |
David Chinner | 92821e2 | 2007-05-24 15:26:31 +1000 | [diff] [blame] | 1549 | * If asked, update the disk superblock with incore counter values if we |
| 1550 | * are using non-persistent counters so that they don't get too far out |
| 1551 | * of sync if we crash or get a forced shutdown. We don't want to force |
| 1552 | * this to disk, just get a transaction into the iclogs.... |
| 1553 | */ |
| 1554 | if (flags & SYNC_SUPER) |
| 1555 | xfs_log_sbcount(mp, 0); |
| 1556 | |
| 1557 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | * Now check to see if the log needs a "dummy" transaction. |
| 1559 | */ |
| 1560 | |
| 1561 | if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) { |
| 1562 | xfs_trans_t *tp; |
| 1563 | xfs_inode_t *ip; |
| 1564 | |
| 1565 | /* |
| 1566 | * Put a dummy transaction in the log to tell |
| 1567 | * recovery that all others are OK. |
| 1568 | */ |
| 1569 | tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1); |
| 1570 | if ((error = xfs_trans_reserve(tp, 0, |
| 1571 | XFS_ICHANGE_LOG_RES(mp), |
| 1572 | 0, 0, 0))) { |
| 1573 | xfs_trans_cancel(tp, 0); |
| 1574 | return error; |
| 1575 | } |
| 1576 | |
| 1577 | ip = mp->m_rootip; |
| 1578 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 1579 | |
| 1580 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 1581 | xfs_trans_ihold(tp, ip); |
| 1582 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Eric Sandeen | 1c72bf9 | 2007-05-08 13:48:42 +1000 | [diff] [blame] | 1583 | error = xfs_trans_commit(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1585 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); |
| 1586 | } |
| 1587 | |
| 1588 | /* |
| 1589 | * When shutting down, we need to insure that the AIL is pushed |
| 1590 | * to disk or the filesystem can appear corrupt from the PROM. |
| 1591 | */ |
| 1592 | if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) { |
| 1593 | XFS_bflush(mp->m_ddev_targp); |
| 1594 | if (mp->m_rtdev_targp) { |
| 1595 | XFS_bflush(mp->m_rtdev_targp); |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | return XFS_ERROR(last_error); |
| 1600 | } |
| 1601 | |
| 1602 | /* |
| 1603 | * xfs_vget - called by DMAPI and NFSD to get vnode from file handle |
| 1604 | */ |
| 1605 | STATIC int |
| 1606 | xfs_vget( |
| 1607 | bhv_desc_t *bdp, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 1608 | bhv_vnode_t **vpp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | fid_t *fidp) |
| 1610 | { |
| 1611 | xfs_mount_t *mp = XFS_BHVTOM(bdp); |
| 1612 | xfs_fid_t *xfid = (struct xfs_fid *)fidp; |
| 1613 | xfs_inode_t *ip; |
| 1614 | int error; |
| 1615 | xfs_ino_t ino; |
| 1616 | unsigned int igen; |
| 1617 | |
| 1618 | /* |
| 1619 | * Invalid. Since handles can be created in user space and passed in |
| 1620 | * via gethandle(), this is not cause for a panic. |
| 1621 | */ |
| 1622 | if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) |
| 1623 | return XFS_ERROR(EINVAL); |
| 1624 | |
| 1625 | ino = xfid->xfs_fid_ino; |
| 1626 | igen = xfid->xfs_fid_gen; |
| 1627 | |
| 1628 | /* |
| 1629 | * NFS can sometimes send requests for ino 0. Fail them gracefully. |
| 1630 | */ |
| 1631 | if (ino == 0) |
| 1632 | return XFS_ERROR(ESTALE); |
| 1633 | |
| 1634 | error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0); |
| 1635 | if (error) { |
| 1636 | *vpp = NULL; |
| 1637 | return error; |
| 1638 | } |
| 1639 | |
| 1640 | if (ip == NULL) { |
| 1641 | *vpp = NULL; |
| 1642 | return XFS_ERROR(EIO); |
| 1643 | } |
| 1644 | |
| 1645 | if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) { |
| 1646 | xfs_iput_new(ip, XFS_ILOCK_SHARED); |
| 1647 | *vpp = NULL; |
| 1648 | return XFS_ERROR(ENOENT); |
| 1649 | } |
| 1650 | |
| 1651 | *vpp = XFS_ITOV(ip); |
| 1652 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | |
| 1657 | #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */ |
| 1658 | #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */ |
| 1659 | #define MNTOPT_LOGDEV "logdev" /* log device */ |
| 1660 | #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */ |
| 1661 | #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */ |
| 1662 | #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */ |
| 1663 | #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */ |
| 1664 | #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */ |
| 1665 | #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */ |
| 1666 | #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */ |
| 1667 | #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */ |
| 1668 | #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */ |
| 1669 | #define MNTOPT_MTPT "mtpt" /* filesystem mount point */ |
Nathan Scott | e69a333 | 2005-09-02 16:42:26 +1000 | [diff] [blame] | 1670 | #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */ |
| 1671 | #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */ |
| 1672 | #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */ |
| 1673 | #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */ |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1674 | #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */ |
| 1676 | #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */ |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 1677 | #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and |
Nathan Scott | d8cc890 | 2005-11-02 10:34:53 +1100 | [diff] [blame] | 1678 | * unwritten extent conversion */ |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 1679 | #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */ |
| 1681 | #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */ |
| 1682 | #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */ |
| 1683 | #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */ |
David Chinner | e8c8b3a | 2005-11-02 10:33:05 +1100 | [diff] [blame] | 1684 | #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */ |
| 1685 | #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes |
| 1686 | * in stat(). */ |
Nathan Scott | d8cc890 | 2005-11-02 10:34:53 +1100 | [diff] [blame] | 1687 | #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */ |
| 1688 | #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */ |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 1689 | #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1691 | STATIC unsigned long |
Nathan Scott | b190f11 | 2006-06-09 17:13:15 +1000 | [diff] [blame] | 1692 | suffix_strtoul(char *s, char **endp, unsigned int base) |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1693 | { |
| 1694 | int last, shift_left_factor = 0; |
Nathan Scott | b190f11 | 2006-06-09 17:13:15 +1000 | [diff] [blame] | 1695 | char *value = s; |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1696 | |
| 1697 | last = strlen(value) - 1; |
| 1698 | if (value[last] == 'K' || value[last] == 'k') { |
| 1699 | shift_left_factor = 10; |
| 1700 | value[last] = '\0'; |
| 1701 | } |
| 1702 | if (value[last] == 'M' || value[last] == 'm') { |
| 1703 | shift_left_factor = 20; |
| 1704 | value[last] = '\0'; |
| 1705 | } |
| 1706 | if (value[last] == 'G' || value[last] == 'g') { |
| 1707 | shift_left_factor = 30; |
| 1708 | value[last] = '\0'; |
| 1709 | } |
| 1710 | |
Nathan Scott | b190f11 | 2006-06-09 17:13:15 +1000 | [diff] [blame] | 1711 | return simple_strtoul((const char *)s, endp, base) << shift_left_factor; |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1712 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 1714 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | xfs_parseargs( |
| 1716 | struct bhv_desc *bhv, |
| 1717 | char *options, |
| 1718 | struct xfs_mount_args *args, |
| 1719 | int update) |
| 1720 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1721 | bhv_vfs_t *vfsp = bhvtovfs(bhv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | char *this_char, *value, *eov; |
| 1723 | int dsunit, dswidth, vol_dsunit, vol_dswidth; |
| 1724 | int iosize; |
| 1725 | |
Nathan Scott | e15f195 | 2006-03-22 12:47:52 +1100 | [diff] [blame] | 1726 | args->flags |= XFSMNT_IDELETE; |
Nathan Scott | 3bbcc8e | 2006-03-31 13:04:56 +1000 | [diff] [blame] | 1727 | args->flags |= XFSMNT_BARRIER; |
| 1728 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
| 1730 | if (!options) |
Nathan Scott | 05db218 | 2005-11-04 09:49:07 +1100 | [diff] [blame] | 1731 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
| 1733 | iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0; |
| 1734 | |
| 1735 | while ((this_char = strsep(&options, ",")) != NULL) { |
| 1736 | if (!*this_char) |
| 1737 | continue; |
| 1738 | if ((value = strchr(this_char, '=')) != NULL) |
| 1739 | *value++ = 0; |
| 1740 | |
| 1741 | if (!strcmp(this_char, MNTOPT_LOGBUFS)) { |
| 1742 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1743 | cmn_err(CE_WARN, |
| 1744 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1745 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | return EINVAL; |
| 1747 | } |
| 1748 | args->logbufs = simple_strtoul(value, &eov, 10); |
| 1749 | } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1751 | cmn_err(CE_WARN, |
| 1752 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1753 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | return EINVAL; |
| 1755 | } |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1756 | args->logbufsize = suffix_strtoul(value, &eov, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | } else if (!strcmp(this_char, MNTOPT_LOGDEV)) { |
| 1758 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1759 | cmn_err(CE_WARN, |
| 1760 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1761 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | return EINVAL; |
| 1763 | } |
| 1764 | strncpy(args->logname, value, MAXNAMELEN); |
| 1765 | } else if (!strcmp(this_char, MNTOPT_MTPT)) { |
| 1766 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1767 | cmn_err(CE_WARN, |
| 1768 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1769 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return EINVAL; |
| 1771 | } |
| 1772 | strncpy(args->mtpt, value, MAXNAMELEN); |
| 1773 | } else if (!strcmp(this_char, MNTOPT_RTDEV)) { |
| 1774 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1775 | cmn_err(CE_WARN, |
| 1776 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1777 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | return EINVAL; |
| 1779 | } |
| 1780 | strncpy(args->rtname, value, MAXNAMELEN); |
| 1781 | } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) { |
| 1782 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1783 | cmn_err(CE_WARN, |
| 1784 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1785 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | return EINVAL; |
| 1787 | } |
| 1788 | iosize = simple_strtoul(value, &eov, 10); |
| 1789 | args->flags |= XFSMNT_IOSIZE; |
| 1790 | args->iosizelog = (uint8_t) iosize; |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1791 | } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) { |
| 1792 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1793 | cmn_err(CE_WARN, |
| 1794 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1795 | this_char); |
| 1796 | return EINVAL; |
| 1797 | } |
| 1798 | iosize = suffix_strtoul(value, &eov, 10); |
| 1799 | args->flags |= XFSMNT_IOSIZE; |
| 1800 | args->iosizelog = ffs(iosize) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) { |
| 1802 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1803 | cmn_err(CE_WARN, |
| 1804 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1805 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | return EINVAL; |
| 1807 | } |
| 1808 | args->flags |= XFSMNT_IHASHSIZE; |
| 1809 | args->ihashsize = simple_strtoul(value, &eov, 10); |
Nathan Scott | e69a333 | 2005-09-02 16:42:26 +1000 | [diff] [blame] | 1810 | } else if (!strcmp(this_char, MNTOPT_GRPID) || |
| 1811 | !strcmp(this_char, MNTOPT_BSDGROUPS)) { |
| 1812 | vfsp->vfs_flag |= VFS_GRPID; |
| 1813 | } else if (!strcmp(this_char, MNTOPT_NOGRPID) || |
| 1814 | !strcmp(this_char, MNTOPT_SYSVGROUPS)) { |
| 1815 | vfsp->vfs_flag &= ~VFS_GRPID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } else if (!strcmp(this_char, MNTOPT_WSYNC)) { |
| 1817 | args->flags |= XFSMNT_WSYNC; |
| 1818 | } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) { |
| 1819 | args->flags |= XFSMNT_OSYNCISOSYNC; |
| 1820 | } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) { |
| 1821 | args->flags |= XFSMNT_NORECOVERY; |
| 1822 | } else if (!strcmp(this_char, MNTOPT_INO64)) { |
| 1823 | args->flags |= XFSMNT_INO64; |
| 1824 | #if !XFS_BIG_INUMS |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1825 | cmn_err(CE_WARN, |
| 1826 | "XFS: %s option not allowed on this system", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1827 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | return EINVAL; |
| 1829 | #endif |
| 1830 | } else if (!strcmp(this_char, MNTOPT_NOALIGN)) { |
| 1831 | args->flags |= XFSMNT_NOALIGN; |
| 1832 | } else if (!strcmp(this_char, MNTOPT_SWALLOC)) { |
| 1833 | args->flags |= XFSMNT_SWALLOC; |
| 1834 | } else if (!strcmp(this_char, MNTOPT_SUNIT)) { |
| 1835 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1836 | cmn_err(CE_WARN, |
| 1837 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1838 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | return EINVAL; |
| 1840 | } |
| 1841 | dsunit = simple_strtoul(value, &eov, 10); |
| 1842 | } else if (!strcmp(this_char, MNTOPT_SWIDTH)) { |
| 1843 | if (!value || !*value) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1844 | cmn_err(CE_WARN, |
| 1845 | "XFS: %s option requires an argument", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1846 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return EINVAL; |
| 1848 | } |
| 1849 | dswidth = simple_strtoul(value, &eov, 10); |
| 1850 | } else if (!strcmp(this_char, MNTOPT_64BITINODE)) { |
| 1851 | args->flags &= ~XFSMNT_32BITINODES; |
| 1852 | #if !XFS_BIG_INUMS |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1853 | cmn_err(CE_WARN, |
| 1854 | "XFS: %s option not allowed on this system", |
Nathan Scott | 1f443ad | 2005-05-05 13:28:29 -0700 | [diff] [blame] | 1855 | this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | return EINVAL; |
| 1857 | #endif |
| 1858 | } else if (!strcmp(this_char, MNTOPT_NOUUID)) { |
| 1859 | args->flags |= XFSMNT_NOUUID; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 1860 | } else if (!strcmp(this_char, MNTOPT_BARRIER)) { |
| 1861 | args->flags |= XFSMNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 1862 | } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) { |
| 1863 | args->flags &= ~XFSMNT_BARRIER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } else if (!strcmp(this_char, MNTOPT_IKEEP)) { |
| 1865 | args->flags &= ~XFSMNT_IDELETE; |
| 1866 | } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) { |
| 1867 | args->flags |= XFSMNT_IDELETE; |
David Chinner | e8c8b3a | 2005-11-02 10:33:05 +1100 | [diff] [blame] | 1868 | } else if (!strcmp(this_char, MNTOPT_LARGEIO)) { |
Nathan Scott | e718eeb4 | 2005-11-02 15:09:22 +1100 | [diff] [blame] | 1869 | args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE; |
David Chinner | e8c8b3a | 2005-11-02 10:33:05 +1100 | [diff] [blame] | 1870 | } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) { |
Nathan Scott | e718eeb4 | 2005-11-02 15:09:22 +1100 | [diff] [blame] | 1871 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
Nathan Scott | d8cc890 | 2005-11-02 10:34:53 +1100 | [diff] [blame] | 1872 | } else if (!strcmp(this_char, MNTOPT_ATTR2)) { |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 1873 | args->flags |= XFSMNT_ATTR2; |
Nathan Scott | d8cc890 | 2005-11-02 10:34:53 +1100 | [diff] [blame] | 1874 | } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { |
Nathan Scott | 13059ff | 2006-01-11 15:32:01 +1100 | [diff] [blame] | 1875 | args->flags &= ~XFSMNT_ATTR2; |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 1876 | } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { |
| 1877 | args->flags2 |= XFSMNT2_FILESTREAMS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | } else if (!strcmp(this_char, "osyncisdsync")) { |
| 1879 | /* no-op, this is now the default */ |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1880 | cmn_err(CE_WARN, |
| 1881 | "XFS: osyncisdsync is now the default, option is deprecated."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | } else if (!strcmp(this_char, "irixsgid")) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1883 | cmn_err(CE_WARN, |
| 1884 | "XFS: irixsgid is now a sysctl(2) variable, option is deprecated."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } else { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1886 | cmn_err(CE_WARN, |
| 1887 | "XFS: unknown mount option [%s].", this_char); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | return EINVAL; |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | if (args->flags & XFSMNT_NORECOVERY) { |
| 1893 | if ((vfsp->vfs_flag & VFS_RDONLY) == 0) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1894 | cmn_err(CE_WARN, |
| 1895 | "XFS: no-recovery mounts must be read-only."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | return EINVAL; |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1901 | cmn_err(CE_WARN, |
| 1902 | "XFS: sunit and swidth options incompatible with the noalign option"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | return EINVAL; |
| 1904 | } |
| 1905 | |
| 1906 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1907 | cmn_err(CE_WARN, |
| 1908 | "XFS: sunit and swidth must be specified together"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | return EINVAL; |
| 1910 | } |
| 1911 | |
| 1912 | if (dsunit && (dswidth % dsunit != 0)) { |
Nathan Scott | b657452 | 2006-06-09 15:29:40 +1000 | [diff] [blame] | 1913 | cmn_err(CE_WARN, |
| 1914 | "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | dswidth, dsunit); |
| 1916 | return EINVAL; |
| 1917 | } |
| 1918 | |
| 1919 | if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 1920 | if (dsunit) { |
| 1921 | args->sunit = dsunit; |
| 1922 | args->flags |= XFSMNT_RETERR; |
| 1923 | } else { |
| 1924 | args->sunit = vol_dsunit; |
| 1925 | } |
| 1926 | dswidth ? (args->swidth = dswidth) : |
| 1927 | (args->swidth = vol_dswidth); |
| 1928 | } else { |
| 1929 | args->sunit = args->swidth = 0; |
| 1930 | } |
| 1931 | |
Nathan Scott | 05db218 | 2005-11-04 09:49:07 +1100 | [diff] [blame] | 1932 | done: |
Nathan Scott | c11e2c3 | 2005-11-02 15:11:45 +1100 | [diff] [blame] | 1933 | if (args->flags & XFSMNT_32BITINODES) |
| 1934 | vfsp->vfs_flag |= VFS_32BITINODES; |
Nathan Scott | e718eeb4 | 2005-11-02 15:09:22 +1100 | [diff] [blame] | 1935 | if (args->flags2) |
| 1936 | args->flags |= XFSMNT_FLAGS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | return 0; |
| 1938 | } |
| 1939 | |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 1940 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | xfs_showargs( |
| 1942 | struct bhv_desc *bhv, |
| 1943 | struct seq_file *m) |
| 1944 | { |
| 1945 | static struct proc_xfs_info { |
| 1946 | int flag; |
| 1947 | char *str; |
| 1948 | } xfs_info[] = { |
| 1949 | /* the few simple ones we can get from the mount struct */ |
| 1950 | { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC }, |
| 1951 | { XFS_MOUNT_INO64, "," MNTOPT_INO64 }, |
| 1952 | { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN }, |
| 1953 | { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC }, |
| 1954 | { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID }, |
| 1955 | { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY }, |
| 1956 | { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { 0, NULL } |
| 1958 | }; |
| 1959 | struct proc_xfs_info *xfs_infop; |
| 1960 | struct xfs_mount *mp = XFS_BHVTOM(bhv); |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1961 | struct bhv_vfs *vfsp = XFS_MTOVFS(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
| 1963 | for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) { |
| 1964 | if (mp->m_flags & xfs_infop->flag) |
| 1965 | seq_puts(m, xfs_infop->str); |
| 1966 | } |
| 1967 | |
| 1968 | if (mp->m_flags & XFS_MOUNT_IHASHSIZE) |
Nathan Scott | 215101c | 2006-09-28 11:04:43 +1000 | [diff] [blame] | 1969 | seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", (int)mp->m_ihsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
| 1971 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) |
Nathan Scott | cfcbbbd | 2005-11-02 15:12:04 +1100 | [diff] [blame] | 1972 | seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk", |
| 1973 | (int)(1 << mp->m_writeio_log) >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | |
| 1975 | if (mp->m_logbufs > 0) |
| 1976 | seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | if (mp->m_logbsize > 0) |
Nathan Scott | cfcbbbd | 2005-11-02 15:12:04 +1100 | [diff] [blame] | 1978 | seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
Nathan Scott | fc1f8c1 | 2005-11-02 11:44:33 +1100 | [diff] [blame] | 1980 | if (mp->m_logname) |
| 1981 | seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname); |
Nathan Scott | fc1f8c1 | 2005-11-02 11:44:33 +1100 | [diff] [blame] | 1982 | if (mp->m_rtname) |
| 1983 | seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
| 1985 | if (mp->m_dalign > 0) |
| 1986 | seq_printf(m, "," MNTOPT_SUNIT "=%d", |
| 1987 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | if (mp->m_swidth > 0) |
| 1989 | seq_printf(m, "," MNTOPT_SWIDTH "=%d", |
| 1990 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
| 1991 | |
Nathan Scott | e15f195 | 2006-03-22 12:47:52 +1100 | [diff] [blame] | 1992 | if (!(mp->m_flags & XFS_MOUNT_IDELETE)) |
| 1993 | seq_printf(m, "," MNTOPT_IKEEP); |
Nathan Scott | fa7e7d7 | 2005-11-02 15:00:48 +1100 | [diff] [blame] | 1994 | if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE)) |
| 1995 | seq_printf(m, "," MNTOPT_LARGEIO); |
| 1996 | |
Nathan Scott | c11e2c3 | 2005-11-02 15:11:45 +1100 | [diff] [blame] | 1997 | if (!(vfsp->vfs_flag & VFS_32BITINODES)) |
| 1998 | seq_printf(m, "," MNTOPT_64BITINODE); |
Nathan Scott | e69a333 | 2005-09-02 16:42:26 +1000 | [diff] [blame] | 1999 | if (vfsp->vfs_flag & VFS_GRPID) |
| 2000 | seq_printf(m, "," MNTOPT_GRPID); |
| 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return 0; |
| 2003 | } |
| 2004 | |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 2005 | /* |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 2006 | * Second stage of a freeze. The data is already frozen so we only |
| 2007 | * need to take care of themetadata. Once that's done write a dummy |
| 2008 | * record to dirty the log in case of a crash while frozen. |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 2009 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | STATIC void |
| 2011 | xfs_freeze( |
| 2012 | bhv_desc_t *bdp) |
| 2013 | { |
| 2014 | xfs_mount_t *mp = XFS_BHVTOM(bdp); |
| 2015 | |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 2016 | xfs_attr_quiesce(mp); |
Christoph Hellwig | e13a73f | 2006-01-11 15:30:08 +1100 | [diff] [blame] | 2017 | xfs_fs_log_dummy(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 2021 | bhv_vfsops_t xfs_vfsops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS), |
| 2023 | .vfs_parseargs = xfs_parseargs, |
| 2024 | .vfs_showargs = xfs_showargs, |
| 2025 | .vfs_mount = xfs_mount, |
| 2026 | .vfs_unmount = xfs_unmount, |
| 2027 | .vfs_mntupdate = xfs_mntupdate, |
| 2028 | .vfs_root = xfs_root, |
| 2029 | .vfs_statvfs = xfs_statvfs, |
| 2030 | .vfs_sync = xfs_sync, |
| 2031 | .vfs_vget = xfs_vget, |
| 2032 | .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys, |
| 2033 | .vfs_quotactl = (vfs_quotactl_t)fs_nosys, |
| 2034 | .vfs_init_vnode = xfs_initialize_vnode, |
| 2035 | .vfs_force_shutdown = xfs_do_force_shutdown, |
| 2036 | .vfs_freeze = xfs_freeze, |
| 2037 | }; |