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