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