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