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