]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/xfs/linux-2.6/xfs_super.c
[XFS] remove unessecary vnode flags
[linux-2.6-omap-h63xx.git] / fs / xfs / linux-2.6 / xfs_super.c
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "xfs.h"
34
35 #include "xfs_inum.h"
36 #include "xfs_log.h"
37 #include "xfs_clnt.h"
38 #include "xfs_trans.h"
39 #include "xfs_sb.h"
40 #include "xfs_dir.h"
41 #include "xfs_dir2.h"
42 #include "xfs_alloc.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_quota.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_ialloc.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode.h"
56 #include "xfs_bmap.h"
57 #include "xfs_bit.h"
58 #include "xfs_rtalloc.h"
59 #include "xfs_error.h"
60 #include "xfs_itable.h"
61 #include "xfs_rw.h"
62 #include "xfs_acl.h"
63 #include "xfs_cap.h"
64 #include "xfs_mac.h"
65 #include "xfs_attr.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
68 #include "xfs_version.h"
69
70 #include <linux/namei.h>
71 #include <linux/init.h>
72 #include <linux/mount.h>
73 #include <linux/writeback.h>
74
75 STATIC struct quotactl_ops linvfs_qops;
76 STATIC struct super_operations linvfs_sops;
77 STATIC kmem_zone_t *linvfs_inode_zone;
78
79 STATIC struct xfs_mount_args *
80 xfs_args_allocate(
81         struct super_block      *sb)
82 {
83         struct xfs_mount_args   *args;
84
85         args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
86         args->logbufs = args->logbufsize = -1;
87         strncpy(args->fsname, sb->s_id, MAXNAMELEN);
88
89         /* Copy the already-parsed mount(2) flags we're interested in */
90         if (sb->s_flags & MS_NOATIME)
91                 args->flags |= XFSMNT_NOATIME;
92         if (sb->s_flags & MS_DIRSYNC)
93                 args->flags |= XFSMNT_DIRSYNC;
94         if (sb->s_flags & MS_SYNCHRONOUS)
95                 args->flags |= XFSMNT_WSYNC;
96
97         /* Default to 32 bit inodes on Linux all the time */
98         args->flags |= XFSMNT_32BITINODES;
99
100         return args;
101 }
102
103 __uint64_t
104 xfs_max_file_offset(
105         unsigned int            blockshift)
106 {
107         unsigned int            pagefactor = 1;
108         unsigned int            bitshift = BITS_PER_LONG - 1;
109
110         /* Figure out maximum filesize, on Linux this can depend on
111          * the filesystem blocksize (on 32 bit platforms).
112          * __block_prepare_write does this in an [unsigned] long...
113          *      page->index << (PAGE_CACHE_SHIFT - bbits)
114          * So, for page sized blocks (4K on 32 bit platforms),
115          * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
116          *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
117          * but for smaller blocksizes it is less (bbits = log2 bsize).
118          * Note1: get_block_t takes a long (implicit cast from above)
119          * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
120          * can optionally convert the [unsigned] long from above into
121          * an [unsigned] long long.
122          */
123
124 #if BITS_PER_LONG == 32
125 # if defined(CONFIG_LBD)
126         ASSERT(sizeof(sector_t) == 8);
127         pagefactor = PAGE_CACHE_SIZE;
128         bitshift = BITS_PER_LONG;
129 # else
130         pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
131 # endif
132 #endif
133
134         return (((__uint64_t)pagefactor) << bitshift) - 1;
135 }
136
137 STATIC __inline__ void
138 xfs_set_inodeops(
139         struct inode            *inode)
140 {
141         switch (inode->i_mode & S_IFMT) {
142         case S_IFREG:
143                 inode->i_op = &linvfs_file_inode_operations;
144                 inode->i_fop = &linvfs_file_operations;
145                 inode->i_mapping->a_ops = &linvfs_aops;
146                 break;
147         case S_IFDIR:
148                 inode->i_op = &linvfs_dir_inode_operations;
149                 inode->i_fop = &linvfs_dir_operations;
150                 break;
151         case S_IFLNK:
152                 inode->i_op = &linvfs_symlink_inode_operations;
153                 if (inode->i_blocks)
154                         inode->i_mapping->a_ops = &linvfs_aops;
155                 break;
156         default:
157                 inode->i_op = &linvfs_file_inode_operations;
158                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
159                 break;
160         }
161 }
162
163 STATIC __inline__ void
164 xfs_revalidate_inode(
165         xfs_mount_t             *mp,
166         vnode_t                 *vp,
167         xfs_inode_t             *ip)
168 {
169         struct inode            *inode = LINVFS_GET_IP(vp);
170
171         inode->i_mode   = ip->i_d.di_mode;
172         inode->i_nlink  = ip->i_d.di_nlink;
173         inode->i_uid    = ip->i_d.di_uid;
174         inode->i_gid    = ip->i_d.di_gid;
175
176         switch (inode->i_mode & S_IFMT) {
177         case S_IFBLK:
178         case S_IFCHR:
179                 inode->i_rdev =
180                         MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
181                               sysv_minor(ip->i_df.if_u2.if_rdev));
182                 break;
183         default:
184                 inode->i_rdev = 0;
185                 break;
186         }
187
188         inode->i_blksize = PAGE_CACHE_SIZE;
189         inode->i_generation = ip->i_d.di_gen;
190         i_size_write(inode, ip->i_d.di_size);
191         inode->i_blocks =
192                 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
193         inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
194         inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
195         inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
196         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
197         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
198         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
199         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
200                 inode->i_flags |= S_IMMUTABLE;
201         else
202                 inode->i_flags &= ~S_IMMUTABLE;
203         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
204                 inode->i_flags |= S_APPEND;
205         else
206                 inode->i_flags &= ~S_APPEND;
207         if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
208                 inode->i_flags |= S_SYNC;
209         else
210                 inode->i_flags &= ~S_SYNC;
211         if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
212                 inode->i_flags |= S_NOATIME;
213         else
214                 inode->i_flags &= ~S_NOATIME;
215         vp->v_flag &= ~VMODIFIED;
216 }
217
218 void
219 xfs_initialize_vnode(
220         bhv_desc_t              *bdp,
221         vnode_t                 *vp,
222         bhv_desc_t              *inode_bhv,
223         int                     unlock)
224 {
225         xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
226         struct inode            *inode = LINVFS_GET_IP(vp);
227
228         if (!inode_bhv->bd_vobj) {
229                 vp->v_vfsp = bhvtovfs(bdp);
230                 bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
231                 bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
232         }
233
234         /*
235          * We need to set the ops vectors, and unlock the inode, but if
236          * we have been called during the new inode create process, it is
237          * too early to fill in the Linux inode.  We will get called a
238          * second time once the inode is properly set up, and then we can
239          * finish our work.
240          */
241         if (ip->i_d.di_mode != 0 && unlock && (inode->i_state & I_NEW)) {
242                 xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip);
243                 xfs_set_inodeops(inode);
244         
245                 ip->i_flags &= ~XFS_INEW;
246                 barrier();
247
248                 unlock_new_inode(inode);
249         }
250 }
251
252 int
253 xfs_blkdev_get(
254         xfs_mount_t             *mp,
255         const char              *name,
256         struct block_device     **bdevp)
257 {
258         int                     error = 0;
259
260         *bdevp = open_bdev_excl(name, 0, mp);
261         if (IS_ERR(*bdevp)) {
262                 error = PTR_ERR(*bdevp);
263                 printk("XFS: Invalid device [%s], error=%d\n", name, error);
264         }
265
266         return -error;
267 }
268
269 void
270 xfs_blkdev_put(
271         struct block_device     *bdev)
272 {
273         if (bdev)
274                 close_bdev_excl(bdev);
275 }
276
277
278 STATIC struct inode *
279 linvfs_alloc_inode(
280         struct super_block      *sb)
281 {
282         vnode_t                 *vp;
283
284         vp = (vnode_t *)kmem_cache_alloc(linvfs_inode_zone, 
285                 kmem_flags_convert(KM_SLEEP));
286         if (!vp)
287                 return NULL;
288         return LINVFS_GET_IP(vp);
289 }
290
291 STATIC void
292 linvfs_destroy_inode(
293         struct inode            *inode)
294 {
295         kmem_cache_free(linvfs_inode_zone, LINVFS_GET_VP(inode));
296 }
297
298 STATIC void
299 init_once(
300         void                    *data,
301         kmem_cache_t            *cachep,
302         unsigned long           flags)
303 {
304         vnode_t                 *vp = (vnode_t *)data;
305
306         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
307             SLAB_CTOR_CONSTRUCTOR)
308                 inode_init_once(LINVFS_GET_IP(vp));
309 }
310
311 STATIC int
312 init_inodecache( void )
313 {
314         linvfs_inode_zone = kmem_cache_create("linvfs_icache",
315                                 sizeof(vnode_t), 0, SLAB_RECLAIM_ACCOUNT,
316                                 init_once, NULL);
317         if (linvfs_inode_zone == NULL)
318                 return -ENOMEM;
319         return 0;
320 }
321
322 STATIC void
323 destroy_inodecache( void )
324 {
325         if (kmem_cache_destroy(linvfs_inode_zone))
326                 printk(KERN_WARNING "%s: cache still in use!\n", __FUNCTION__);
327 }
328
329 /*
330  * Attempt to flush the inode, this will actually fail
331  * if the inode is pinned, but we dirty the inode again
332  * at the point when it is unpinned after a log write,
333  * since this is when the inode itself becomes flushable. 
334  */
335 STATIC int
336 linvfs_write_inode(
337         struct inode            *inode,
338         int                     sync)
339 {
340         vnode_t                 *vp = LINVFS_GET_VP(inode);
341         int                     error = 0, flags = FLUSH_INODE;
342
343         if (vp) {
344                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
345                 if (sync)
346                         flags |= FLUSH_SYNC;
347                 VOP_IFLUSH(vp, flags, error);
348                 if (error == EAGAIN) {
349                         if (sync)
350                                 VOP_IFLUSH(vp, flags | FLUSH_LOG, error);
351                         else
352                                 error = 0;
353                 }
354         }
355
356         return -error;
357 }
358
359 STATIC void
360 linvfs_clear_inode(
361         struct inode            *inode)
362 {
363         vnode_t                 *vp = LINVFS_GET_VP(inode);
364
365         if (vp) {
366                 vn_rele(vp);
367                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
368                 /*
369                  * Do all our cleanup, and remove this vnode.
370                  */
371                 vn_remove(vp);
372         }
373 }
374
375
376 /*
377  * Enqueue a work item to be picked up by the vfs xfssyncd thread.
378  * Doing this has two advantages:
379  * - It saves on stack space, which is tight in certain situations
380  * - It can be used (with care) as a mechanism to avoid deadlocks.
381  * Flushing while allocating in a full filesystem requires both.
382  */
383 STATIC void
384 xfs_syncd_queue_work(
385         struct vfs      *vfs,
386         void            *data,
387         void            (*syncer)(vfs_t *, void *))
388 {
389         vfs_sync_work_t *work;
390
391         work = kmem_alloc(sizeof(struct vfs_sync_work), KM_SLEEP);
392         INIT_LIST_HEAD(&work->w_list);
393         work->w_syncer = syncer;
394         work->w_data = data;
395         work->w_vfs = vfs;
396         spin_lock(&vfs->vfs_sync_lock);
397         list_add_tail(&work->w_list, &vfs->vfs_sync_list);
398         spin_unlock(&vfs->vfs_sync_lock);
399         wake_up_process(vfs->vfs_sync_task);
400 }
401
402 /*
403  * Flush delayed allocate data, attempting to free up reserved space
404  * from existing allocations.  At this point a new allocation attempt
405  * has failed with ENOSPC and we are in the process of scratching our
406  * heads, looking about for more room...
407  */
408 STATIC void
409 xfs_flush_inode_work(
410         vfs_t           *vfs,
411         void            *inode)
412 {
413         filemap_flush(((struct inode *)inode)->i_mapping);
414         iput((struct inode *)inode);
415 }
416
417 void
418 xfs_flush_inode(
419         xfs_inode_t     *ip)
420 {
421         struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
422         struct vfs      *vfs = XFS_MTOVFS(ip->i_mount);
423
424         igrab(inode);
425         xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work);
426         delay(HZ/2);
427 }
428
429 /*
430  * This is the "bigger hammer" version of xfs_flush_inode_work...
431  * (IOW, "If at first you don't succeed, use a Bigger Hammer").
432  */
433 STATIC void
434 xfs_flush_device_work(
435         vfs_t           *vfs,
436         void            *inode)
437 {
438         sync_blockdev(vfs->vfs_super->s_bdev);
439         iput((struct inode *)inode);
440 }
441
442 void
443 xfs_flush_device(
444         xfs_inode_t     *ip)
445 {
446         struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
447         struct vfs      *vfs = XFS_MTOVFS(ip->i_mount);
448
449         igrab(inode);
450         xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work);
451         delay(HZ/2);
452         xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
453 }
454
455 #define SYNCD_FLAGS     (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
456 STATIC void
457 vfs_sync_worker(
458         vfs_t           *vfsp,
459         void            *unused)
460 {
461         int             error;
462
463         if (!(vfsp->vfs_flag & VFS_RDONLY))
464                 VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error);
465         vfsp->vfs_sync_seq++;
466         wmb();
467         wake_up(&vfsp->vfs_wait_single_sync_task);
468 }
469
470 STATIC int
471 xfssyncd(
472         void                    *arg)
473 {
474         long                    timeleft;
475         vfs_t                   *vfsp = (vfs_t *) arg;
476         struct list_head        tmp;
477         struct vfs_sync_work    *work, *n;
478
479         daemonize("xfssyncd");
480
481         vfsp->vfs_sync_work.w_vfs = vfsp;
482         vfsp->vfs_sync_work.w_syncer = vfs_sync_worker;
483         vfsp->vfs_sync_task = current;
484         wmb();
485         wake_up(&vfsp->vfs_wait_sync_task);
486
487         INIT_LIST_HEAD(&tmp);
488         timeleft = (xfs_syncd_centisecs * HZ) / 100;
489         for (;;) {
490                 set_current_state(TASK_INTERRUPTIBLE);
491                 timeleft = schedule_timeout(timeleft);
492                 /* swsusp */
493                 try_to_freeze();
494                 if (vfsp->vfs_flag & VFS_UMOUNT)
495                         break;
496
497                 spin_lock(&vfsp->vfs_sync_lock);
498                 /*
499                  * We can get woken by laptop mode, to do a sync -
500                  * that's the (only!) case where the list would be
501                  * empty with time remaining.
502                  */
503                 if (!timeleft || list_empty(&vfsp->vfs_sync_list)) {
504                         if (!timeleft)
505                                 timeleft = (xfs_syncd_centisecs * HZ) / 100;
506                         INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list);
507                         list_add_tail(&vfsp->vfs_sync_work.w_list,
508                                         &vfsp->vfs_sync_list);
509                 }
510                 list_for_each_entry_safe(work, n, &vfsp->vfs_sync_list, w_list)
511                         list_move(&work->w_list, &tmp);
512                 spin_unlock(&vfsp->vfs_sync_lock);
513
514                 list_for_each_entry_safe(work, n, &tmp, w_list) {
515                         (*work->w_syncer)(vfsp, work->w_data);
516                         list_del(&work->w_list);
517                         if (work == &vfsp->vfs_sync_work)
518                                 continue;
519                         kmem_free(work, sizeof(struct vfs_sync_work));
520                 }
521         }
522
523         vfsp->vfs_sync_task = NULL;
524         wmb();
525         wake_up(&vfsp->vfs_wait_sync_task);
526
527         return 0;
528 }
529
530 STATIC int
531 linvfs_start_syncd(
532         vfs_t                   *vfsp)
533 {
534         int                     pid;
535
536         pid = kernel_thread(xfssyncd, (void *) vfsp,
537                         CLONE_VM | CLONE_FS | CLONE_FILES);
538         if (pid < 0)
539                 return -pid;
540         wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task);
541         return 0;
542 }
543
544 STATIC void
545 linvfs_stop_syncd(
546         vfs_t                   *vfsp)
547 {
548         vfsp->vfs_flag |= VFS_UMOUNT;
549         wmb();
550
551         wake_up_process(vfsp->vfs_sync_task);
552         wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task);
553 }
554
555 STATIC void
556 linvfs_put_super(
557         struct super_block      *sb)
558 {
559         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
560         int                     error;
561
562         linvfs_stop_syncd(vfsp);
563         VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error);
564         if (!error)
565                 VFS_UNMOUNT(vfsp, 0, NULL, error);
566         if (error) {
567                 printk("XFS unmount got error %d\n", error);
568                 printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp);
569                 return;
570         }
571
572         vfs_deallocate(vfsp);
573 }
574
575 STATIC void
576 linvfs_write_super(
577         struct super_block      *sb)
578 {
579         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
580         int                     error;
581
582         if (sb->s_flags & MS_RDONLY) {
583                 sb->s_dirt = 0; /* paranoia */
584                 return;
585         }
586         /* Push the log and superblock a little */
587         VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error);
588         sb->s_dirt = 0;
589 }
590
591 STATIC int
592 linvfs_sync_super(
593         struct super_block      *sb,
594         int                     wait)
595 {
596         vfs_t           *vfsp = LINVFS_GET_VFS(sb);
597         int             error;
598         int             flags = SYNC_FSDATA;
599
600         if (unlikely(sb->s_frozen == SB_FREEZE_WRITE))
601                 flags = SYNC_QUIESCE;
602         else
603                 flags = SYNC_FSDATA | (wait ? SYNC_WAIT : 0);
604
605         VFS_SYNC(vfsp, flags, NULL, error);
606         sb->s_dirt = 0;
607
608         if (unlikely(laptop_mode)) {
609                 int     prev_sync_seq = vfsp->vfs_sync_seq;
610
611                 /*
612                  * The disk must be active because we're syncing.
613                  * We schedule xfssyncd now (now that the disk is
614                  * active) instead of later (when it might not be).
615                  */
616                 wake_up_process(vfsp->vfs_sync_task);
617                 /*
618                  * We have to wait for the sync iteration to complete.
619                  * If we don't, the disk activity caused by the sync
620                  * will come after the sync is completed, and that
621                  * triggers another sync from laptop mode.
622                  */
623                 wait_event(vfsp->vfs_wait_single_sync_task,
624                                 vfsp->vfs_sync_seq != prev_sync_seq);
625         }
626
627         return -error;
628 }
629
630 STATIC int
631 linvfs_statfs(
632         struct super_block      *sb,
633         struct kstatfs          *statp)
634 {
635         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
636         int                     error;
637
638         VFS_STATVFS(vfsp, statp, NULL, error);
639         return -error;
640 }
641
642 STATIC int
643 linvfs_remount(
644         struct super_block      *sb,
645         int                     *flags,
646         char                    *options)
647 {
648         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
649         struct xfs_mount_args   *args = xfs_args_allocate(sb);
650         int                     error;
651
652         VFS_PARSEARGS(vfsp, options, args, 1, error);
653         if (!error)
654                 VFS_MNTUPDATE(vfsp, flags, args, error);
655         kmem_free(args, sizeof(*args));
656         return -error;
657 }
658
659 STATIC void
660 linvfs_freeze_fs(
661         struct super_block      *sb)
662 {
663         VFS_FREEZE(LINVFS_GET_VFS(sb));
664 }
665
666 STATIC int
667 linvfs_show_options(
668         struct seq_file         *m,
669         struct vfsmount         *mnt)
670 {
671         struct vfs              *vfsp = LINVFS_GET_VFS(mnt->mnt_sb);
672         int                     error;
673
674         VFS_SHOWARGS(vfsp, m, error);
675         return error;
676 }
677
678 STATIC int
679 linvfs_getxstate(
680         struct super_block      *sb,
681         struct fs_quota_stat    *fqs)
682 {
683         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
684         int                     error;
685
686         VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error);
687         return -error;
688 }
689
690 STATIC int
691 linvfs_setxstate(
692         struct super_block      *sb,
693         unsigned int            flags,
694         int                     op)
695 {
696         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
697         int                     error;
698
699         VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error);
700         return -error;
701 }
702
703 STATIC int
704 linvfs_getxquota(
705         struct super_block      *sb,
706         int                     type,
707         qid_t                   id,
708         struct fs_disk_quota    *fdq)
709 {
710         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
711         int                     error, getmode;
712
713         getmode = (type == USRQUOTA) ? Q_XGETQUOTA :
714                  ((type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETPQUOTA);
715         VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error);
716         return -error;
717 }
718
719 STATIC int
720 linvfs_setxquota(
721         struct super_block      *sb,
722         int                     type,
723         qid_t                   id,
724         struct fs_disk_quota    *fdq)
725 {
726         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
727         int                     error, setmode;
728
729         setmode = (type == USRQUOTA) ? Q_XSETQLIM :
730                  ((type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETPQLIM);
731         VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error);
732         return -error;
733 }
734
735 STATIC int
736 linvfs_fill_super(
737         struct super_block      *sb,
738         void                    *data,
739         int                     silent)
740 {
741         vnode_t                 *rootvp;
742         struct vfs              *vfsp = vfs_allocate();
743         struct xfs_mount_args   *args = xfs_args_allocate(sb);
744         struct kstatfs          statvfs;
745         int                     error, error2;
746
747         vfsp->vfs_super = sb;
748         LINVFS_SET_VFS(sb, vfsp);
749         if (sb->s_flags & MS_RDONLY)
750                 vfsp->vfs_flag |= VFS_RDONLY;
751         bhv_insert_all_vfsops(vfsp);
752
753         VFS_PARSEARGS(vfsp, (char *)data, args, 0, error);
754         if (error) {
755                 bhv_remove_all_vfsops(vfsp, 1);
756                 goto fail_vfsop;
757         }
758
759         sb_min_blocksize(sb, BBSIZE);
760 #ifdef CONFIG_XFS_EXPORT
761         sb->s_export_op = &linvfs_export_ops;
762 #endif
763         sb->s_qcop = &linvfs_qops;
764         sb->s_op = &linvfs_sops;
765
766         VFS_MOUNT(vfsp, args, NULL, error);
767         if (error) {
768                 bhv_remove_all_vfsops(vfsp, 1);
769                 goto fail_vfsop;
770         }
771
772         VFS_STATVFS(vfsp, &statvfs, NULL, error);
773         if (error)
774                 goto fail_unmount;
775
776         sb->s_dirt = 1;
777         sb->s_magic = statvfs.f_type;
778         sb->s_blocksize = statvfs.f_bsize;
779         sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
780         sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
781         sb->s_time_gran = 1;
782         set_posix_acl_flag(sb);
783
784         VFS_ROOT(vfsp, &rootvp, error);
785         if (error)
786                 goto fail_unmount;
787
788         sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp));
789         if (!sb->s_root) {
790                 error = ENOMEM;
791                 goto fail_vnrele;
792         }
793         if (is_bad_inode(sb->s_root->d_inode)) {
794                 error = EINVAL;
795                 goto fail_vnrele;
796         }
797         if ((error = linvfs_start_syncd(vfsp)))
798                 goto fail_vnrele;
799         vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address);
800
801         kmem_free(args, sizeof(*args));
802         return 0;
803
804 fail_vnrele:
805         if (sb->s_root) {
806                 dput(sb->s_root);
807                 sb->s_root = NULL;
808         } else {
809                 VN_RELE(rootvp);
810         }
811
812 fail_unmount:
813         VFS_UNMOUNT(vfsp, 0, NULL, error2);
814
815 fail_vfsop:
816         vfs_deallocate(vfsp);
817         kmem_free(args, sizeof(*args));
818         return -error;
819 }
820
821 STATIC struct super_block *
822 linvfs_get_sb(
823         struct file_system_type *fs_type,
824         int                     flags,
825         const char              *dev_name,
826         void                    *data)
827 {
828         return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super);
829 }
830
831 STATIC struct super_operations linvfs_sops = {
832         .alloc_inode            = linvfs_alloc_inode,
833         .destroy_inode          = linvfs_destroy_inode,
834         .write_inode            = linvfs_write_inode,
835         .clear_inode            = linvfs_clear_inode,
836         .put_super              = linvfs_put_super,
837         .write_super            = linvfs_write_super,
838         .sync_fs                = linvfs_sync_super,
839         .write_super_lockfs     = linvfs_freeze_fs,
840         .statfs                 = linvfs_statfs,
841         .remount_fs             = linvfs_remount,
842         .show_options           = linvfs_show_options,
843 };
844
845 STATIC struct quotactl_ops linvfs_qops = {
846         .get_xstate             = linvfs_getxstate,
847         .set_xstate             = linvfs_setxstate,
848         .get_xquota             = linvfs_getxquota,
849         .set_xquota             = linvfs_setxquota,
850 };
851
852 STATIC struct file_system_type xfs_fs_type = {
853         .owner                  = THIS_MODULE,
854         .name                   = "xfs",
855         .get_sb                 = linvfs_get_sb,
856         .kill_sb                = kill_block_super,
857         .fs_flags               = FS_REQUIRES_DEV,
858 };
859
860
861 STATIC int __init
862 init_xfs_fs( void )
863 {
864         int                     error;
865         struct sysinfo          si;
866         static char             message[] __initdata = KERN_INFO \
867                 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
868
869         printk(message);
870
871         si_meminfo(&si);
872         xfs_physmem = si.totalram;
873
874         ktrace_init(64);
875
876         error = init_inodecache();
877         if (error < 0)
878                 goto undo_inodecache;
879
880         error = pagebuf_init();
881         if (error < 0)
882                 goto undo_pagebuf;
883
884         vn_init();
885         xfs_init();
886         uuid_init();
887         vfs_initquota();
888
889         error = register_filesystem(&xfs_fs_type);
890         if (error)
891                 goto undo_register;
892         XFS_DM_INIT(&xfs_fs_type);
893         return 0;
894
895 undo_register:
896         pagebuf_terminate();
897
898 undo_pagebuf:
899         destroy_inodecache();
900
901 undo_inodecache:
902         return error;
903 }
904
905 STATIC void __exit
906 exit_xfs_fs( void )
907 {
908         vfs_exitquota();
909         XFS_DM_EXIT(&xfs_fs_type);
910         unregister_filesystem(&xfs_fs_type);
911         xfs_cleanup();
912         pagebuf_terminate();
913         destroy_inodecache();
914         ktrace_uninit();
915 }
916
917 module_init(init_xfs_fs);
918 module_exit(exit_xfs_fs);
919
920 MODULE_AUTHOR("Silicon Graphics, Inc.");
921 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
922 MODULE_LICENSE("GPL");