diff options
Diffstat (limited to 'fs/xfs/xfs_vfsops.c')
-rw-r--r-- | fs/xfs/xfs_vfsops.c | 623 |
1 files changed, 9 insertions, 614 deletions
diff --git a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c index 30bacd8bb0e5..439dd3939dda 100644 --- a/fs/xfs/xfs_vfsops.c +++ b/fs/xfs/xfs_vfsops.c | |||
@@ -58,586 +58,6 @@ | |||
58 | #include "xfs_utils.h" | 58 | #include "xfs_utils.h" |
59 | 59 | ||
60 | 60 | ||
61 | int __init | ||
62 | xfs_init(void) | ||
63 | { | ||
64 | #ifdef XFS_DABUF_DEBUG | ||
65 | extern spinlock_t xfs_dabuf_global_lock; | ||
66 | spin_lock_init(&xfs_dabuf_global_lock); | ||
67 | #endif | ||
68 | |||
69 | /* | ||
70 | * Initialize all of the zone allocators we use. | ||
71 | */ | ||
72 | xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t), | ||
73 | "xfs_log_ticket"); | ||
74 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), | ||
75 | "xfs_bmap_free_item"); | ||
76 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), | ||
77 | "xfs_btree_cur"); | ||
78 | xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t), | ||
79 | "xfs_da_state"); | ||
80 | xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf"); | ||
81 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); | ||
82 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); | ||
83 | xfs_acl_zone_init(xfs_acl_zone, "xfs_acl"); | ||
84 | xfs_mru_cache_init(); | ||
85 | xfs_filestream_init(); | ||
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"); | ||
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))), | ||
101 | "xfs_efd_item"); | ||
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))), | ||
106 | "xfs_efi_item"); | ||
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 | |||
119 | /* | ||
120 | * Allocate global trace buffers. | ||
121 | */ | ||
122 | #ifdef XFS_ALLOC_TRACE | ||
123 | xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP); | ||
124 | #endif | ||
125 | #ifdef XFS_BMAP_TRACE | ||
126 | xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP); | ||
127 | #endif | ||
128 | #ifdef XFS_BMBT_TRACE | ||
129 | xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP); | ||
130 | #endif | ||
131 | #ifdef XFS_ATTR_TRACE | ||
132 | xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP); | ||
133 | #endif | ||
134 | #ifdef XFS_DIR2_TRACE | ||
135 | xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP); | ||
136 | #endif | ||
137 | |||
138 | xfs_dir_startup(); | ||
139 | |||
140 | #if (defined(DEBUG) || defined(INDUCE_IO_ERROR)) | ||
141 | xfs_error_test_init(); | ||
142 | #endif /* DEBUG || INDUCE_IO_ERROR */ | ||
143 | |||
144 | xfs_init_procfs(); | ||
145 | xfs_sysctl_register(); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | void __exit | ||
150 | xfs_cleanup(void) | ||
151 | { | ||
152 | extern kmem_zone_t *xfs_inode_zone; | ||
153 | extern kmem_zone_t *xfs_efd_zone; | ||
154 | extern kmem_zone_t *xfs_efi_zone; | ||
155 | |||
156 | xfs_cleanup_procfs(); | ||
157 | xfs_sysctl_unregister(); | ||
158 | xfs_filestream_uninit(); | ||
159 | xfs_mru_cache_uninit(); | ||
160 | xfs_acl_zone_destroy(xfs_acl_zone); | ||
161 | |||
162 | #ifdef XFS_DIR2_TRACE | ||
163 | ktrace_free(xfs_dir2_trace_buf); | ||
164 | #endif | ||
165 | #ifdef XFS_ATTR_TRACE | ||
166 | ktrace_free(xfs_attr_trace_buf); | ||
167 | #endif | ||
168 | #ifdef XFS_BMBT_TRACE | ||
169 | ktrace_free(xfs_bmbt_trace_buf); | ||
170 | #endif | ||
171 | #ifdef XFS_BMAP_TRACE | ||
172 | ktrace_free(xfs_bmap_trace_buf); | ||
173 | #endif | ||
174 | #ifdef XFS_ALLOC_TRACE | ||
175 | ktrace_free(xfs_alloc_trace_buf); | ||
176 | #endif | ||
177 | |||
178 | kmem_zone_destroy(xfs_bmap_free_item_zone); | ||
179 | kmem_zone_destroy(xfs_btree_cur_zone); | ||
180 | kmem_zone_destroy(xfs_inode_zone); | ||
181 | kmem_zone_destroy(xfs_trans_zone); | ||
182 | kmem_zone_destroy(xfs_da_state_zone); | ||
183 | kmem_zone_destroy(xfs_dabuf_zone); | ||
184 | kmem_zone_destroy(xfs_buf_item_zone); | ||
185 | kmem_zone_destroy(xfs_efd_zone); | ||
186 | kmem_zone_destroy(xfs_efi_zone); | ||
187 | kmem_zone_destroy(xfs_ifork_zone); | ||
188 | kmem_zone_destroy(xfs_ili_zone); | ||
189 | kmem_zone_destroy(xfs_log_ticket_zone); | ||
190 | } | ||
191 | |||
192 | /* | ||
193 | * xfs_start_flags | ||
194 | * | ||
195 | * This function fills in xfs_mount_t fields based on mount args. | ||
196 | * Note: the superblock has _not_ yet been read in. | ||
197 | */ | ||
198 | STATIC int | ||
199 | xfs_start_flags( | ||
200 | struct xfs_mount_args *ap, | ||
201 | struct xfs_mount *mp) | ||
202 | { | ||
203 | /* Values are in BBs */ | ||
204 | if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { | ||
205 | /* | ||
206 | * At this point the superblock has not been read | ||
207 | * in, therefore we do not know the block size. | ||
208 | * Before the mount call ends we will convert | ||
209 | * these to FSBs. | ||
210 | */ | ||
211 | mp->m_dalign = ap->sunit; | ||
212 | mp->m_swidth = ap->swidth; | ||
213 | } | ||
214 | |||
215 | if (ap->logbufs != -1 && | ||
216 | ap->logbufs != 0 && | ||
217 | (ap->logbufs < XLOG_MIN_ICLOGS || | ||
218 | ap->logbufs > XLOG_MAX_ICLOGS)) { | ||
219 | cmn_err(CE_WARN, | ||
220 | "XFS: invalid logbufs value: %d [not %d-%d]", | ||
221 | ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); | ||
222 | return XFS_ERROR(EINVAL); | ||
223 | } | ||
224 | mp->m_logbufs = ap->logbufs; | ||
225 | if (ap->logbufsize != -1 && | ||
226 | ap->logbufsize != 0 && | ||
227 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || | ||
228 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || | ||
229 | !is_power_of_2(ap->logbufsize))) { | ||
230 | cmn_err(CE_WARN, | ||
231 | "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", | ||
232 | ap->logbufsize); | ||
233 | return XFS_ERROR(EINVAL); | ||
234 | } | ||
235 | mp->m_logbsize = ap->logbufsize; | ||
236 | mp->m_fsname_len = strlen(ap->fsname) + 1; | ||
237 | mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP); | ||
238 | strcpy(mp->m_fsname, ap->fsname); | ||
239 | if (ap->rtname[0]) { | ||
240 | mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP); | ||
241 | strcpy(mp->m_rtname, ap->rtname); | ||
242 | } | ||
243 | if (ap->logname[0]) { | ||
244 | mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP); | ||
245 | strcpy(mp->m_logname, ap->logname); | ||
246 | } | ||
247 | |||
248 | if (ap->flags & XFSMNT_WSYNC) | ||
249 | mp->m_flags |= XFS_MOUNT_WSYNC; | ||
250 | #if XFS_BIG_INUMS | ||
251 | if (ap->flags & XFSMNT_INO64) { | ||
252 | mp->m_flags |= XFS_MOUNT_INO64; | ||
253 | mp->m_inoadd = XFS_INO64_OFFSET; | ||
254 | } | ||
255 | #endif | ||
256 | if (ap->flags & XFSMNT_RETERR) | ||
257 | mp->m_flags |= XFS_MOUNT_RETERR; | ||
258 | if (ap->flags & XFSMNT_NOALIGN) | ||
259 | mp->m_flags |= XFS_MOUNT_NOALIGN; | ||
260 | if (ap->flags & XFSMNT_SWALLOC) | ||
261 | mp->m_flags |= XFS_MOUNT_SWALLOC; | ||
262 | if (ap->flags & XFSMNT_OSYNCISOSYNC) | ||
263 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; | ||
264 | if (ap->flags & XFSMNT_32BITINODES) | ||
265 | mp->m_flags |= XFS_MOUNT_32BITINODES; | ||
266 | |||
267 | if (ap->flags & XFSMNT_IOSIZE) { | ||
268 | if (ap->iosizelog > XFS_MAX_IO_LOG || | ||
269 | ap->iosizelog < XFS_MIN_IO_LOG) { | ||
270 | cmn_err(CE_WARN, | ||
271 | "XFS: invalid log iosize: %d [not %d-%d]", | ||
272 | ap->iosizelog, XFS_MIN_IO_LOG, | ||
273 | XFS_MAX_IO_LOG); | ||
274 | return XFS_ERROR(EINVAL); | ||
275 | } | ||
276 | |||
277 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; | ||
278 | mp->m_readio_log = mp->m_writeio_log = ap->iosizelog; | ||
279 | } | ||
280 | |||
281 | if (ap->flags & XFSMNT_IKEEP) | ||
282 | mp->m_flags |= XFS_MOUNT_IKEEP; | ||
283 | if (ap->flags & XFSMNT_DIRSYNC) | ||
284 | mp->m_flags |= XFS_MOUNT_DIRSYNC; | ||
285 | if (ap->flags & XFSMNT_ATTR2) | ||
286 | mp->m_flags |= XFS_MOUNT_ATTR2; | ||
287 | |||
288 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) | ||
289 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; | ||
290 | |||
291 | /* | ||
292 | * no recovery flag requires a read-only mount | ||
293 | */ | ||
294 | if (ap->flags & XFSMNT_NORECOVERY) { | ||
295 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { | ||
296 | cmn_err(CE_WARN, | ||
297 | "XFS: tried to mount a FS read-write without recovery!"); | ||
298 | return XFS_ERROR(EINVAL); | ||
299 | } | ||
300 | mp->m_flags |= XFS_MOUNT_NORECOVERY; | ||
301 | } | ||
302 | |||
303 | if (ap->flags & XFSMNT_NOUUID) | ||
304 | mp->m_flags |= XFS_MOUNT_NOUUID; | ||
305 | if (ap->flags & XFSMNT_BARRIER) | ||
306 | mp->m_flags |= XFS_MOUNT_BARRIER; | ||
307 | else | ||
308 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | ||
309 | |||
310 | if (ap->flags2 & XFSMNT2_FILESTREAMS) | ||
311 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; | ||
312 | |||
313 | if (ap->flags & XFSMNT_DMAPI) | ||
314 | mp->m_flags |= XFS_MOUNT_DMAPI; | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | * This function fills in xfs_mount_t fields based on mount args. | ||
320 | * Note: the superblock _has_ now been read in. | ||
321 | */ | ||
322 | STATIC int | ||
323 | xfs_finish_flags( | ||
324 | struct xfs_mount_args *ap, | ||
325 | struct xfs_mount *mp) | ||
326 | { | ||
327 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); | ||
328 | |||
329 | /* Fail a mount where the logbuf is smaller then the log stripe */ | ||
330 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { | ||
331 | if ((ap->logbufsize <= 0) && | ||
332 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { | ||
333 | mp->m_logbsize = mp->m_sb.sb_logsunit; | ||
334 | } else if (ap->logbufsize > 0 && | ||
335 | ap->logbufsize < mp->m_sb.sb_logsunit) { | ||
336 | cmn_err(CE_WARN, | ||
337 | "XFS: logbuf size must be greater than or equal to log stripe size"); | ||
338 | return XFS_ERROR(EINVAL); | ||
339 | } | ||
340 | } else { | ||
341 | /* Fail a mount if the logbuf is larger than 32K */ | ||
342 | if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) { | ||
343 | cmn_err(CE_WARN, | ||
344 | "XFS: logbuf size for version 1 logs must be 16K or 32K"); | ||
345 | return XFS_ERROR(EINVAL); | ||
346 | } | ||
347 | } | ||
348 | |||
349 | if (xfs_sb_version_hasattr2(&mp->m_sb)) | ||
350 | mp->m_flags |= XFS_MOUNT_ATTR2; | ||
351 | |||
352 | /* | ||
353 | * prohibit r/w mounts of read-only filesystems | ||
354 | */ | ||
355 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { | ||
356 | cmn_err(CE_WARN, | ||
357 | "XFS: cannot mount a read-only filesystem as read-write"); | ||
358 | return XFS_ERROR(EROFS); | ||
359 | } | ||
360 | |||
361 | /* | ||
362 | * check for shared mount. | ||
363 | */ | ||
364 | if (ap->flags & XFSMNT_SHARED) { | ||
365 | if (!xfs_sb_version_hasshared(&mp->m_sb)) | ||
366 | return XFS_ERROR(EINVAL); | ||
367 | |||
368 | /* | ||
369 | * For IRIX 6.5, shared mounts must have the shared | ||
370 | * version bit set, have the persistent readonly | ||
371 | * field set, must be version 0 and can only be mounted | ||
372 | * read-only. | ||
373 | */ | ||
374 | if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) || | ||
375 | (mp->m_sb.sb_shared_vn != 0)) | ||
376 | return XFS_ERROR(EINVAL); | ||
377 | |||
378 | mp->m_flags |= XFS_MOUNT_SHARED; | ||
379 | |||
380 | /* | ||
381 | * Shared XFS V0 can't deal with DMI. Return EINVAL. | ||
382 | */ | ||
383 | if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI)) | ||
384 | return XFS_ERROR(EINVAL); | ||
385 | } | ||
386 | |||
387 | if (ap->flags & XFSMNT_UQUOTA) { | ||
388 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); | ||
389 | if (ap->flags & XFSMNT_UQUOTAENF) | ||
390 | mp->m_qflags |= XFS_UQUOTA_ENFD; | ||
391 | } | ||
392 | |||
393 | if (ap->flags & XFSMNT_GQUOTA) { | ||
394 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); | ||
395 | if (ap->flags & XFSMNT_GQUOTAENF) | ||
396 | mp->m_qflags |= XFS_OQUOTA_ENFD; | ||
397 | } else if (ap->flags & XFSMNT_PQUOTA) { | ||
398 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); | ||
399 | if (ap->flags & XFSMNT_PQUOTAENF) | ||
400 | mp->m_qflags |= XFS_OQUOTA_ENFD; | ||
401 | } | ||
402 | |||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | /* | ||
407 | * xfs_mount | ||
408 | * | ||
409 | * The file system configurations are: | ||
410 | * (1) device (partition) with data and internal log | ||
411 | * (2) logical volume with data and log subvolumes. | ||
412 | * (3) logical volume with data, log, and realtime subvolumes. | ||
413 | * | ||
414 | * We only have to handle opening the log and realtime volumes here if | ||
415 | * they are present. The data subvolume has already been opened by | ||
416 | * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev. | ||
417 | */ | ||
418 | int | ||
419 | xfs_mount( | ||
420 | struct xfs_mount *mp, | ||
421 | struct xfs_mount_args *args, | ||
422 | cred_t *credp) | ||
423 | { | ||
424 | struct block_device *ddev, *logdev, *rtdev; | ||
425 | int flags = 0, error; | ||
426 | |||
427 | ddev = mp->m_super->s_bdev; | ||
428 | logdev = rtdev = NULL; | ||
429 | |||
430 | error = xfs_dmops_get(mp, args); | ||
431 | if (error) | ||
432 | return error; | ||
433 | error = xfs_qmops_get(mp, args); | ||
434 | if (error) | ||
435 | return error; | ||
436 | |||
437 | if (args->flags & XFSMNT_QUIET) | ||
438 | flags |= XFS_MFSI_QUIET; | ||
439 | |||
440 | /* | ||
441 | * Open real time and log devices - order is important. | ||
442 | */ | ||
443 | if (args->logname[0]) { | ||
444 | error = xfs_blkdev_get(mp, args->logname, &logdev); | ||
445 | if (error) | ||
446 | return error; | ||
447 | } | ||
448 | if (args->rtname[0]) { | ||
449 | error = xfs_blkdev_get(mp, args->rtname, &rtdev); | ||
450 | if (error) { | ||
451 | xfs_blkdev_put(logdev); | ||
452 | return error; | ||
453 | } | ||
454 | |||
455 | if (rtdev == ddev || rtdev == logdev) { | ||
456 | cmn_err(CE_WARN, | ||
457 | "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev."); | ||
458 | xfs_blkdev_put(logdev); | ||
459 | xfs_blkdev_put(rtdev); | ||
460 | return EINVAL; | ||
461 | } | ||
462 | } | ||
463 | |||
464 | /* | ||
465 | * Setup xfs_mount buffer target pointers | ||
466 | */ | ||
467 | error = ENOMEM; | ||
468 | mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0); | ||
469 | if (!mp->m_ddev_targp) { | ||
470 | xfs_blkdev_put(logdev); | ||
471 | xfs_blkdev_put(rtdev); | ||
472 | return error; | ||
473 | } | ||
474 | if (rtdev) { | ||
475 | mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1); | ||
476 | if (!mp->m_rtdev_targp) { | ||
477 | xfs_blkdev_put(logdev); | ||
478 | xfs_blkdev_put(rtdev); | ||
479 | goto error0; | ||
480 | } | ||
481 | } | ||
482 | mp->m_logdev_targp = (logdev && logdev != ddev) ? | ||
483 | xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp; | ||
484 | if (!mp->m_logdev_targp) { | ||
485 | xfs_blkdev_put(logdev); | ||
486 | xfs_blkdev_put(rtdev); | ||
487 | goto error0; | ||
488 | } | ||
489 | |||
490 | /* | ||
491 | * Setup flags based on mount(2) options and then the superblock | ||
492 | */ | ||
493 | error = xfs_start_flags(args, mp); | ||
494 | if (error) | ||
495 | goto error1; | ||
496 | error = xfs_readsb(mp, flags); | ||
497 | if (error) | ||
498 | goto error1; | ||
499 | error = xfs_finish_flags(args, mp); | ||
500 | if (error) | ||
501 | goto error2; | ||
502 | |||
503 | /* | ||
504 | * Setup xfs_mount buffer target pointers based on superblock | ||
505 | */ | ||
506 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize, | ||
507 | mp->m_sb.sb_sectsize); | ||
508 | if (!error && logdev && logdev != ddev) { | ||
509 | unsigned int log_sector_size = BBSIZE; | ||
510 | |||
511 | if (xfs_sb_version_hassector(&mp->m_sb)) | ||
512 | log_sector_size = mp->m_sb.sb_logsectsize; | ||
513 | error = xfs_setsize_buftarg(mp->m_logdev_targp, | ||
514 | mp->m_sb.sb_blocksize, | ||
515 | log_sector_size); | ||
516 | } | ||
517 | if (!error && rtdev) | ||
518 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, | ||
519 | mp->m_sb.sb_blocksize, | ||
520 | mp->m_sb.sb_sectsize); | ||
521 | if (error) | ||
522 | goto error2; | ||
523 | |||
524 | if (mp->m_flags & XFS_MOUNT_BARRIER) | ||
525 | xfs_mountfs_check_barriers(mp); | ||
526 | |||
527 | if ((error = xfs_filestream_mount(mp))) | ||
528 | goto error2; | ||
529 | |||
530 | error = xfs_mountfs(mp, flags); | ||
531 | if (error) | ||
532 | goto error2; | ||
533 | |||
534 | XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname); | ||
535 | |||
536 | return 0; | ||
537 | |||
538 | error2: | ||
539 | if (mp->m_sb_bp) | ||
540 | xfs_freesb(mp); | ||
541 | error1: | ||
542 | xfs_binval(mp->m_ddev_targp); | ||
543 | if (logdev && logdev != ddev) | ||
544 | xfs_binval(mp->m_logdev_targp); | ||
545 | if (rtdev) | ||
546 | xfs_binval(mp->m_rtdev_targp); | ||
547 | error0: | ||
548 | xfs_unmountfs_close(mp, credp); | ||
549 | xfs_qmops_put(mp); | ||
550 | xfs_dmops_put(mp); | ||
551 | return error; | ||
552 | } | ||
553 | |||
554 | int | ||
555 | xfs_unmount( | ||
556 | xfs_mount_t *mp, | ||
557 | int flags, | ||
558 | cred_t *credp) | ||
559 | { | ||
560 | xfs_inode_t *rip; | ||
561 | bhv_vnode_t *rvp; | ||
562 | int unmount_event_wanted = 0; | ||
563 | int unmount_event_flags = 0; | ||
564 | int xfs_unmountfs_needed = 0; | ||
565 | int error; | ||
566 | |||
567 | rip = mp->m_rootip; | ||
568 | rvp = XFS_ITOV(rip); | ||
569 | |||
570 | #ifdef HAVE_DMAPI | ||
571 | if (mp->m_flags & XFS_MOUNT_DMAPI) { | ||
572 | error = XFS_SEND_PREUNMOUNT(mp, | ||
573 | rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL, | ||
574 | NULL, NULL, 0, 0, | ||
575 | (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))? | ||
576 | 0:DM_FLAGS_UNWANTED); | ||
577 | if (error) | ||
578 | return XFS_ERROR(error); | ||
579 | unmount_event_wanted = 1; | ||
580 | unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))? | ||
581 | 0 : DM_FLAGS_UNWANTED; | ||
582 | } | ||
583 | #endif | ||
584 | |||
585 | /* | ||
586 | * Blow away any referenced inode in the filestreams cache. | ||
587 | * This can and will cause log traffic as inodes go inactive | ||
588 | * here. | ||
589 | */ | ||
590 | xfs_filestream_unmount(mp); | ||
591 | |||
592 | XFS_bflush(mp->m_ddev_targp); | ||
593 | error = xfs_unmount_flush(mp, 0); | ||
594 | if (error) | ||
595 | goto out; | ||
596 | |||
597 | ASSERT(vn_count(rvp) == 1); | ||
598 | |||
599 | /* | ||
600 | * Drop the reference count | ||
601 | */ | ||
602 | IRELE(rip); | ||
603 | |||
604 | /* | ||
605 | * If we're forcing a shutdown, typically because of a media error, | ||
606 | * we want to make sure we invalidate dirty pages that belong to | ||
607 | * referenced vnodes as well. | ||
608 | */ | ||
609 | if (XFS_FORCED_SHUTDOWN(mp)) { | ||
610 | error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE); | ||
611 | ASSERT(error != EFSCORRUPTED); | ||
612 | } | ||
613 | xfs_unmountfs_needed = 1; | ||
614 | |||
615 | out: | ||
616 | /* Send DMAPI event, if required. | ||
617 | * Then do xfs_unmountfs() if needed. | ||
618 | * Then return error (or zero). | ||
619 | */ | ||
620 | if (unmount_event_wanted) { | ||
621 | /* Note: mp structure must still exist for | ||
622 | * XFS_SEND_UNMOUNT() call. | ||
623 | */ | ||
624 | XFS_SEND_UNMOUNT(mp, error == 0 ? rip : NULL, | ||
625 | DM_RIGHT_NULL, 0, error, unmount_event_flags); | ||
626 | } | ||
627 | if (xfs_unmountfs_needed) { | ||
628 | /* | ||
629 | * Call common unmount function to flush to disk | ||
630 | * and free the super block buffer & mount structures. | ||
631 | */ | ||
632 | xfs_unmountfs(mp, credp); | ||
633 | xfs_qmops_put(mp); | ||
634 | xfs_dmops_put(mp); | ||
635 | kmem_free(mp, sizeof(xfs_mount_t)); | ||
636 | } | ||
637 | |||
638 | return XFS_ERROR(error); | ||
639 | } | ||
640 | |||
641 | STATIC void | 61 | STATIC void |
642 | xfs_quiesce_fs( | 62 | xfs_quiesce_fs( |
643 | xfs_mount_t *mp) | 63 | xfs_mount_t *mp) |
@@ -694,30 +114,6 @@ xfs_attr_quiesce( | |||
694 | xfs_unmountfs_writesb(mp); | 114 | xfs_unmountfs_writesb(mp); |
695 | } | 115 | } |
696 | 116 | ||
697 | int | ||
698 | xfs_mntupdate( | ||
699 | struct xfs_mount *mp, | ||
700 | int *flags, | ||
701 | struct xfs_mount_args *args) | ||
702 | { | ||
703 | if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */ | ||
704 | if (mp->m_flags & XFS_MOUNT_RDONLY) | ||
705 | mp->m_flags &= ~XFS_MOUNT_RDONLY; | ||
706 | if (args->flags & XFSMNT_BARRIER) { | ||
707 | mp->m_flags |= XFS_MOUNT_BARRIER; | ||
708 | xfs_mountfs_check_barriers(mp); | ||
709 | } else { | ||
710 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | ||
711 | } | ||
712 | } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */ | ||
713 | xfs_filestream_flush(mp); | ||
714 | xfs_sync(mp, SYNC_DATA_QUIESCE); | ||
715 | xfs_attr_quiesce(mp); | ||
716 | mp->m_flags |= XFS_MOUNT_RDONLY; | ||
717 | } | ||
718 | return 0; | ||
719 | } | ||
720 | |||
721 | /* | 117 | /* |
722 | * xfs_unmount_flush implements a set of flush operation on special | 118 | * xfs_unmount_flush implements a set of flush operation on special |
723 | * inodes, which are needed as a separate set of operations so that | 119 | * inodes, which are needed as a separate set of operations so that |
@@ -732,7 +128,6 @@ xfs_unmount_flush( | |||
732 | xfs_inode_t *rip = mp->m_rootip; | 128 | xfs_inode_t *rip = mp->m_rootip; |
733 | xfs_inode_t *rbmip; | 129 | xfs_inode_t *rbmip; |
734 | xfs_inode_t *rsumip = NULL; | 130 | xfs_inode_t *rsumip = NULL; |
735 | bhv_vnode_t *rvp = XFS_ITOV(rip); | ||
736 | int error; | 131 | int error; |
737 | 132 | ||
738 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); | 133 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
@@ -750,7 +145,7 @@ xfs_unmount_flush( | |||
750 | if (error == EFSCORRUPTED) | 145 | if (error == EFSCORRUPTED) |
751 | goto fscorrupt_out; | 146 | goto fscorrupt_out; |
752 | 147 | ||
753 | ASSERT(vn_count(XFS_ITOV(rbmip)) == 1); | 148 | ASSERT(vn_count(VFS_I(rbmip)) == 1); |
754 | 149 | ||
755 | rsumip = mp->m_rsumip; | 150 | rsumip = mp->m_rsumip; |
756 | xfs_ilock(rsumip, XFS_ILOCK_EXCL); | 151 | xfs_ilock(rsumip, XFS_ILOCK_EXCL); |
@@ -761,7 +156,7 @@ xfs_unmount_flush( | |||
761 | if (error == EFSCORRUPTED) | 156 | if (error == EFSCORRUPTED) |
762 | goto fscorrupt_out; | 157 | goto fscorrupt_out; |
763 | 158 | ||
764 | ASSERT(vn_count(XFS_ITOV(rsumip)) == 1); | 159 | ASSERT(vn_count(VFS_I(rsumip)) == 1); |
765 | } | 160 | } |
766 | 161 | ||
767 | /* | 162 | /* |
@@ -771,7 +166,7 @@ xfs_unmount_flush( | |||
771 | if (error == EFSCORRUPTED) | 166 | if (error == EFSCORRUPTED) |
772 | goto fscorrupt_out2; | 167 | goto fscorrupt_out2; |
773 | 168 | ||
774 | if (vn_count(rvp) != 1 && !relocation) { | 169 | if (vn_count(VFS_I(rip)) != 1 && !relocation) { |
775 | xfs_iunlock(rip, XFS_ILOCK_EXCL); | 170 | xfs_iunlock(rip, XFS_ILOCK_EXCL); |
776 | return XFS_ERROR(EBUSY); | 171 | return XFS_ERROR(EBUSY); |
777 | } | 172 | } |
@@ -888,7 +283,7 @@ xfs_sync_inodes( | |||
888 | int *bypassed) | 283 | int *bypassed) |
889 | { | 284 | { |
890 | xfs_inode_t *ip = NULL; | 285 | xfs_inode_t *ip = NULL; |
891 | bhv_vnode_t *vp = NULL; | 286 | struct inode *vp = NULL; |
892 | int error; | 287 | int error; |
893 | int last_error; | 288 | int last_error; |
894 | uint64_t fflag; | 289 | uint64_t fflag; |
@@ -1008,7 +403,7 @@ xfs_sync_inodes( | |||
1008 | continue; | 403 | continue; |
1009 | } | 404 | } |
1010 | 405 | ||
1011 | vp = XFS_ITOV_NULL(ip); | 406 | vp = VFS_I(ip); |
1012 | 407 | ||
1013 | /* | 408 | /* |
1014 | * If the vnode is gone then this is being torn down, | 409 | * If the vnode is gone then this is being torn down, |
@@ -1048,7 +443,7 @@ xfs_sync_inodes( | |||
1048 | 443 | ||
1049 | if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) { | 444 | if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) { |
1050 | XFS_MOUNT_IUNLOCK(mp); | 445 | XFS_MOUNT_IUNLOCK(mp); |
1051 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | 446 | kmem_free(ipointer); |
1052 | return 0; | 447 | return 0; |
1053 | } | 448 | } |
1054 | 449 | ||
@@ -1083,7 +478,7 @@ xfs_sync_inodes( | |||
1083 | IPOINTER_INSERT(ip, mp); | 478 | IPOINTER_INSERT(ip, mp); |
1084 | xfs_ilock(ip, lock_flags); | 479 | xfs_ilock(ip, lock_flags); |
1085 | 480 | ||
1086 | ASSERT(vp == XFS_ITOV(ip)); | 481 | ASSERT(vp == VFS_I(ip)); |
1087 | ASSERT(ip->i_mount == mp); | 482 | ASSERT(ip->i_mount == mp); |
1088 | 483 | ||
1089 | vnode_refed = B_TRUE; | 484 | vnode_refed = B_TRUE; |
@@ -1194,7 +589,7 @@ xfs_sync_inodes( | |||
1194 | } | 589 | } |
1195 | XFS_MOUNT_IUNLOCK(mp); | 590 | XFS_MOUNT_IUNLOCK(mp); |
1196 | ASSERT(ipointer_in == B_FALSE); | 591 | ASSERT(ipointer_in == B_FALSE); |
1197 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | 592 | kmem_free(ipointer); |
1198 | return XFS_ERROR(error); | 593 | return XFS_ERROR(error); |
1199 | } | 594 | } |
1200 | 595 | ||
@@ -1224,7 +619,7 @@ xfs_sync_inodes( | |||
1224 | 619 | ||
1225 | ASSERT(ipointer_in == B_FALSE); | 620 | ASSERT(ipointer_in == B_FALSE); |
1226 | 621 | ||
1227 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | 622 | kmem_free(ipointer); |
1228 | return XFS_ERROR(last_error); | 623 | return XFS_ERROR(last_error); |
1229 | } | 624 | } |
1230 | 625 | ||