commented early_printk patch because of rejects.
[linux-flexiantxendom0-3.2.10.git] / fs / xfs / linux / xfs_super.c
1 /*
2  * Copyright (c) 2000-2003 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/blkdev.h>
71 #include <linux/namei.h>
72 #include <linux/init.h>
73 #include <linux/mount.h>
74 #include <linux/suspend.h>
75
76 STATIC struct quotactl_ops linvfs_qops;
77 STATIC struct super_operations linvfs_sops;
78 STATIC struct export_operations linvfs_export_ops;
79 STATIC kmem_cache_t * linvfs_inode_cachep;
80
81 STATIC struct xfs_mount_args *
82 xfs_args_allocate(
83         struct super_block      *sb)
84 {
85         struct xfs_mount_args   *args;
86
87         args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
88         args->logbufs = args->logbufsize = -1;
89         strncpy(args->fsname, sb->s_id, MAXNAMELEN);
90
91         /* Copy the already-parsed mount(2) flags we're interested in */
92         if (sb->s_flags & MS_NOATIME)
93                 args->flags |= XFSMNT_NOATIME;
94
95         /* Default to 32 bit inodes on Linux all the time */
96         args->flags |= XFSMNT_32BITINODES;
97
98         return args;
99 }
100
101 __uint64_t
102 xfs_max_file_offset(
103         unsigned int            blockshift)
104 {
105         unsigned int            pagefactor = 1;
106         unsigned int            bitshift = BITS_PER_LONG - 1;
107
108         /* Figure out maximum filesize, on Linux this can depend on
109          * the filesystem blocksize (on 32 bit platforms).
110          * __block_prepare_write does this in an [unsigned] long...
111          *      page->index << (PAGE_CACHE_SHIFT - bbits)
112          * So, for page sized blocks (4K on 32 bit platforms),
113          * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
114          *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
115          * but for smaller blocksizes it is less (bbits = log2 bsize).
116          * Note1: get_block_t takes a long (implicit cast from above)
117          * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
118          * can optionally convert the [unsigned] long from above into
119          * an [unsigned] long long.
120          */
121
122 #if BITS_PER_LONG == 32
123 # if defined(HAVE_SECTOR_T)
124         ASSERT(sizeof(sector_t) == 8);
125         pagefactor = PAGE_CACHE_SIZE;
126         bitshift = BITS_PER_LONG;
127 # else
128         pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
129 # endif
130 #endif
131
132         return (((__uint64_t)pagefactor) << bitshift) - 1;
133 }
134
135 STATIC __inline__ void
136 xfs_set_inodeops(
137         struct inode            *inode)
138 {
139         vnode_t                 *vp = LINVFS_GET_VP(inode);
140
141         if (vp->v_type == VNON) {
142                 make_bad_inode(inode);
143         } else if (S_ISREG(inode->i_mode)) {
144                 inode->i_op = &linvfs_file_inode_operations;
145                 inode->i_fop = &linvfs_file_operations;
146                 inode->i_mapping->a_ops = &linvfs_aops;
147         } else if (S_ISDIR(inode->i_mode)) {
148                 inode->i_op = &linvfs_dir_inode_operations;
149                 inode->i_fop = &linvfs_dir_operations;
150         } else if (S_ISLNK(inode->i_mode)) {
151                 inode->i_op = &linvfs_symlink_inode_operations;
152                 if (inode->i_blocks)
153                         inode->i_mapping->a_ops = &linvfs_aops;
154         } else {
155                 inode->i_op = &linvfs_file_inode_operations;
156                 init_special_inode(inode, inode->i_mode,
157                                         kdev_t_to_nr(inode->i_rdev));
158         }
159 }
160
161 STATIC __inline__ void
162 xfs_revalidate_inode(
163         xfs_mount_t             *mp,
164         vnode_t                 *vp,
165         xfs_inode_t             *ip)
166 {
167         struct inode            *inode = LINVFS_GET_IP(vp);
168
169         inode->i_mode   = (ip->i_d.di_mode & MODEMASK) | VTTOIF(vp->v_type);
170         inode->i_nlink  = ip->i_d.di_nlink;
171         inode->i_uid    = ip->i_d.di_uid;
172         inode->i_gid    = ip->i_d.di_gid;
173         if (((1 << vp->v_type) & ((1<<VBLK) | (1<<VCHR))) == 0) {
174                 inode->i_rdev = NODEV;
175         } else {
176                 xfs_dev_t dev = ip->i_df.if_u2.if_rdev;
177                 inode->i_rdev = XFS_DEV_TO_KDEVT(dev);
178         }
179         inode->i_blksize = PAGE_CACHE_SIZE;
180         inode->i_generation = ip->i_d.di_gen;
181         i_size_write(inode, ip->i_d.di_size);
182         inode->i_blocks =
183                 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
184         inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
185         inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
186         inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
187         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
188         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
189         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
190
191         vp->v_flag &= ~VMODIFIED;
192 }
193
194 void
195 xfs_initialize_vnode(
196         bhv_desc_t              *bdp,
197         vnode_t                 *vp,
198         bhv_desc_t              *inode_bhv,
199         int                     unlock)
200 {
201         xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
202         struct inode            *inode = LINVFS_GET_IP(vp);
203
204         if (!inode_bhv->bd_vobj) {
205                 vp->v_vfsp = bhvtovfs(bdp);
206                 bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
207                 bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
208         }
209
210         vp->v_type = IFTOVT(ip->i_d.di_mode);
211
212         /* Have we been called during the new inode create process,
213          * in which case we are too early to fill in the Linux inode.
214          */
215         if (vp->v_type == VNON)
216                 return;
217
218         xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip);
219
220         /* For new inodes we need to set the ops vectors,
221          * and unlock the inode.
222          */
223         if (unlock && (inode->i_state & I_NEW)) {
224                 xfs_set_inodeops(inode);
225                 unlock_new_inode(inode);
226         }
227 }
228
229 int
230 xfs_blkdev_get(
231         xfs_mount_t             *mp,
232         const char              *name,
233         struct block_device     **bdevp)
234 {
235         int                     error = 0;
236
237         *bdevp = open_bdev_excl(name, 0, BDEV_FS, mp);
238         if (IS_ERR(*bdevp)) {
239                 error = PTR_ERR(*bdevp);
240                 printk("XFS: Invalid device [%s], error=%d\n", name, error);
241         }
242
243         return -error;
244 }
245
246 void
247 xfs_blkdev_put(
248         struct block_device     *bdev)
249 {
250         if (bdev)
251                 close_bdev_excl(bdev, BDEV_FS);
252 }
253
254 void
255 xfs_flush_buftarg(
256         xfs_buftarg_t           *btp)
257 {
258         pagebuf_delwri_flush(btp, PBDF_WAIT, NULL);
259 }
260
261 void
262 xfs_free_buftarg(
263         xfs_buftarg_t           *btp)
264 {
265         xfs_flush_buftarg(btp);
266         kmem_free(btp, sizeof(*btp));
267 }
268
269 int
270 xfs_readonly_buftarg(
271         xfs_buftarg_t           *btp)
272 {
273         return bdev_read_only(btp->pbr_bdev);
274 }
275
276 void
277 xfs_relse_buftarg(
278         xfs_buftarg_t           *btp)
279 {
280         invalidate_bdev(btp->pbr_bdev, 1);
281         truncate_inode_pages(btp->pbr_mapping, 0LL);
282 }
283
284 unsigned int
285 xfs_getsize_buftarg(
286         xfs_buftarg_t           *btp)
287 {
288         return block_size(btp->pbr_bdev);
289 }
290
291 void
292 xfs_setsize_buftarg(
293         xfs_buftarg_t           *btp,
294         unsigned int            blocksize,
295         unsigned int            sectorsize)
296 {
297         btp->pbr_bsize = blocksize;
298         btp->pbr_sshift = ffs(sectorsize) - 1;
299         btp->pbr_smask = sectorsize - 1;
300
301         if (set_blocksize(btp->pbr_bdev, sectorsize)) {
302                 printk(KERN_WARNING
303                         "XFS: Cannot set_blocksize to %u on device 0x%lx\n",
304                         sectorsize, (unsigned long)btp->pbr_dev);
305         }
306 }
307
308 xfs_buftarg_t *
309 xfs_alloc_buftarg(
310         struct block_device     *bdev)
311 {
312         xfs_buftarg_t           *btp;
313
314         btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
315
316         btp->pbr_dev =  bdev->bd_dev;
317         btp->pbr_bdev = bdev;
318         btp->pbr_mapping = bdev->bd_inode->i_mapping;
319         xfs_setsize_buftarg(btp, PAGE_CACHE_SIZE, bdev_hardsect_size(bdev));
320
321         return btp;
322 }
323
324 STATIC struct inode *
325 linvfs_alloc_inode(
326         struct super_block      *sb)
327 {
328         vnode_t                 *vp;
329
330         vp = (vnode_t *)kmem_cache_alloc(linvfs_inode_cachep, 
331                 kmem_flags_convert(KM_SLEEP));
332         if (!vp)
333                 return NULL;
334         return LINVFS_GET_IP(vp);
335 }
336
337 STATIC void
338 linvfs_destroy_inode(
339         struct inode            *inode)
340 {
341         kmem_cache_free(linvfs_inode_cachep, LINVFS_GET_VP(inode));
342 }
343
344 STATIC void
345 init_once(
346         void                    *data,
347         kmem_cache_t            *cachep,
348         unsigned long           flags)
349 {
350         vnode_t                 *vp = (vnode_t *)data;
351
352         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
353             SLAB_CTOR_CONSTRUCTOR)
354                 inode_init_once(LINVFS_GET_IP(vp));
355 }
356
357 STATIC int
358 init_inodecache( void )
359 {
360         linvfs_inode_cachep = kmem_cache_create("linvfs_icache",
361                                 sizeof(vnode_t), 0, 
362                                 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
363                                 init_once, NULL);
364
365         if (linvfs_inode_cachep == NULL)
366                 return -ENOMEM;
367         return 0;
368 }
369
370 STATIC void
371 destroy_inodecache( void )
372 {
373         if (kmem_cache_destroy(linvfs_inode_cachep))
374                 printk(KERN_WARNING "%s: cache still in use!\n", __FUNCTION__);
375 }
376
377 /*
378  * Attempt to flush the inode, this will actually fail
379  * if the inode is pinned, but we dirty the inode again
380  * at the point when it is unpinned after a log write,
381  * since this is when the inode itself becomes flushable. 
382  */
383 STATIC void
384 linvfs_write_inode(
385         struct inode            *inode,
386         int                     sync)
387 {
388         vnode_t                 *vp = LINVFS_GET_VP(inode);
389         int                     error, flags = FLUSH_INODE;
390
391         if (vp) {
392                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
393                 if (sync)
394                         flags |= FLUSH_SYNC;
395                 VOP_IFLUSH(vp, flags, error);
396         }
397 }
398
399 STATIC void
400 linvfs_clear_inode(
401         struct inode            *inode)
402 {
403         vnode_t                 *vp = LINVFS_GET_VP(inode);
404
405         if (vp) {
406                 vn_rele(vp);
407                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
408                 /*
409                  * Do all our cleanup, and remove this vnode.
410                  */
411                 vn_remove(vp);
412         }
413 }
414
415
416 #define SYNCD_FLAGS     (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
417
418 STATIC int
419 syncd(void *arg)
420 {
421         vfs_t                   *vfsp = (vfs_t *) arg;
422         int                     error;
423
424         daemonize("xfs_syncd");
425
426         vfsp->vfs_sync_task = current;
427         wmb();
428         wake_up(&vfsp->vfs_wait_sync_task);
429
430         for (;;) {
431                 set_current_state(TASK_INTERRUPTIBLE);
432                 schedule_timeout(xfs_syncd_interval);
433                 /* swsusp */
434                 if (current->flags & PF_FREEZE)
435                         refrigerator(PF_IOTHREAD);
436                 if (vfsp->vfs_flag & VFS_UMOUNT)
437                         break;
438                 if (vfsp->vfs_flag & VFS_RDONLY)
439                         continue;
440                 VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error);
441         }
442
443         vfsp->vfs_sync_task = NULL;
444         wmb();
445         wake_up(&vfsp->vfs_wait_sync_task);
446
447         return 0;
448 }
449
450 STATIC int
451 linvfs_start_syncd(vfs_t *vfsp)
452 {
453         int pid;
454
455         pid = kernel_thread(syncd, (void *) vfsp,
456                         CLONE_VM | CLONE_FS | CLONE_FILES);
457         if (pid < 0)
458                 return pid;
459         wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task);
460         return 0;
461 }
462
463 STATIC void
464 linvfs_stop_syncd(vfs_t *vfsp)
465 {
466         vfsp->vfs_flag |= VFS_UMOUNT;
467         wmb();
468
469         wake_up_process(vfsp->vfs_sync_task);
470         wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task);
471 }
472
473 STATIC void
474 linvfs_put_super(
475         struct super_block      *sb)
476 {
477         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
478         int                     error;
479
480         linvfs_stop_syncd(vfsp);
481         VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error);
482         if (!error)
483                 VFS_UNMOUNT(vfsp, 0, NULL, error);
484         if (error) {
485                 printk("XFS unmount got error %d\n", error);
486                 printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp);
487                 return;
488         }
489
490         vfs_deallocate(vfsp);
491 }
492
493 STATIC void
494 linvfs_write_super(
495         struct super_block      *sb)
496 {
497         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
498         int                     error;
499
500         if (sb->s_flags & MS_RDONLY) {
501                 sb->s_dirt = 0; /* paranoia */
502                 return;
503         }
504         /* Push the log and superblock a little */
505         VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error);
506         sb->s_dirt = 0;
507 }
508
509 STATIC int
510 linvfs_statfs(
511         struct super_block      *sb,
512         struct kstatfs          *statp)
513 {
514         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
515         int                     error;
516
517         VFS_STATVFS(vfsp, statp, NULL, error);
518         return -error;
519 }
520
521 STATIC int
522 linvfs_remount(
523         struct super_block      *sb,
524         int                     *flags,
525         char                    *options)
526 {
527         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
528         struct xfs_mount_args   *args = xfs_args_allocate(sb);
529         int                     error;
530
531         VFS_PARSEARGS(vfsp, options, args, 1, error);
532         if (!error)
533                 VFS_MNTUPDATE(vfsp, flags, args, error);
534         kmem_free(args, sizeof(*args));
535         return -error;
536 }
537
538 STATIC void
539 linvfs_freeze_fs(
540         struct super_block      *sb)
541 {
542         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
543         vnode_t                 *vp;
544         int                     error;
545
546         if (sb->s_flags & MS_RDONLY)
547                 return;
548         VFS_ROOT(vfsp, &vp, error);
549         VOP_IOCTL(vp, LINVFS_GET_IP(vp), NULL, XFS_IOC_FREEZE, 0, error);
550         VN_RELE(vp);
551 }
552
553 STATIC void
554 linvfs_unfreeze_fs(
555         struct super_block      *sb)
556 {
557         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
558         vnode_t                 *vp;
559         int                     error;
560
561         VFS_ROOT(vfsp, &vp, error);
562         VOP_IOCTL(vp, LINVFS_GET_IP(vp), NULL, XFS_IOC_THAW, 0, error);
563         VN_RELE(vp);
564 }
565
566 STATIC struct dentry *
567 linvfs_get_parent(
568         struct dentry           *child)
569 {
570         int                     error;
571         vnode_t                 *vp, *cvp;
572         struct dentry           *parent;
573         struct inode            *ip = NULL;
574         struct dentry           dotdot;
575
576         dotdot.d_name.name = "..";
577         dotdot.d_name.len = 2;
578         dotdot.d_inode = 0;
579
580         cvp = NULL;
581         vp = LINVFS_GET_VP(child->d_inode);
582         VOP_LOOKUP(vp, &dotdot, &cvp, 0, NULL, NULL, error);
583
584         if (!error) {
585                 ASSERT(cvp);
586                 ip = LINVFS_GET_IP(cvp);
587                 if (!ip) {
588                         VN_RELE(cvp);
589                         return ERR_PTR(-EACCES);
590                 }
591         }
592         if (error)
593                 return ERR_PTR(-error);
594         parent = d_alloc_anon(ip);
595         if (!parent) {
596                 VN_RELE(cvp);
597                 parent = ERR_PTR(-ENOMEM);
598         }
599         return parent;
600 }
601
602 STATIC struct dentry *
603 linvfs_get_dentry(
604         struct super_block      *sb,
605         void                    *data)
606 {
607         vnode_t                 *vp;
608         struct inode            *inode;
609         struct dentry           *result;
610         xfs_fid2_t              xfid;
611         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
612         int                     error;
613
614         xfid.fid_len = sizeof(xfs_fid2_t) - sizeof(xfid.fid_len);
615         xfid.fid_pad = 0;
616         xfid.fid_gen = ((__u32 *)data)[1];
617         xfid.fid_ino = ((__u32 *)data)[0];
618
619         VFS_VGET(vfsp, &vp, (fid_t *)&xfid, error);
620         if (error || vp == NULL)
621                 return ERR_PTR(-ESTALE) ;
622
623         inode = LINVFS_GET_IP(vp);
624         result = d_alloc_anon(inode);
625         if (!result) {
626                 iput(inode);
627                 return ERR_PTR(-ENOMEM);
628         }
629         return result;
630 }
631
632 STATIC int
633 linvfs_show_options(
634         struct seq_file         *m,
635         struct vfsmount         *mnt)
636 {
637         struct vfs              *vfsp = LINVFS_GET_VFS(mnt->mnt_sb);
638         int                     error;
639
640         VFS_SHOWARGS(vfsp, m, error);
641         return error;
642 }
643
644 STATIC int
645 linvfs_getxstate(
646         struct super_block      *sb,
647         struct fs_quota_stat    *fqs)
648 {
649         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
650         int                     error;
651
652         VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error);
653         return -error;
654 }
655
656 STATIC int
657 linvfs_setxstate(
658         struct super_block      *sb,
659         unsigned int            flags,
660         int                     op)
661 {
662         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
663         int                     error;
664
665         VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error);
666         return -error;
667 }
668
669 STATIC int
670 linvfs_getxquota(
671         struct super_block      *sb,
672         int                     type,
673         qid_t                   id,
674         struct fs_disk_quota    *fdq)
675 {
676         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
677         int                     error, getmode;
678
679         getmode = (type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETQUOTA;
680         VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error);
681         return -error;
682 }
683
684 STATIC int
685 linvfs_setxquota(
686         struct super_block      *sb,
687         int                     type,
688         qid_t                   id,
689         struct fs_disk_quota    *fdq)
690 {
691         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
692         int                     error, setmode;
693
694         setmode = (type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETQLIM;
695         VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error);
696         return -error;
697 }
698
699 STATIC int
700 linvfs_fill_super(
701         struct super_block      *sb,
702         void                    *data,
703         int                     silent)
704 {
705         vnode_t                 *rootvp;
706         struct vfs              *vfsp = vfs_allocate();
707         struct xfs_mount_args   *args = xfs_args_allocate(sb);
708         struct kstatfs          statvfs;
709         int                     error;
710
711         vfsp->vfs_super = sb;
712         LINVFS_SET_VFS(sb, vfsp);
713         if (sb->s_flags & MS_RDONLY)
714                 vfsp->vfs_flag |= VFS_RDONLY;
715         bhv_insert_all_vfsops(vfsp);
716
717         VFS_PARSEARGS(vfsp, (char *)data, args, 0, error);
718         if (error) {
719                 bhv_remove_all_vfsops(vfsp, 1);
720                 goto fail_vfsop;
721         }
722
723         sb_min_blocksize(sb, BBSIZE);
724         sb->s_export_op = &linvfs_export_ops;
725         sb->s_qcop = &linvfs_qops;
726         sb->s_op = &linvfs_sops;
727
728         VFS_MOUNT(vfsp, args, NULL, error);
729         if (error) {
730                 bhv_remove_all_vfsops(vfsp, 1);
731                 goto fail_vfsop;
732         }
733
734         VFS_STATVFS(vfsp, &statvfs, NULL, error);
735         if (error)
736                 goto fail_unmount;
737
738         sb->s_dirt = 1;
739         sb->s_magic = statvfs.f_type;
740         sb->s_blocksize = statvfs.f_bsize;
741         sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
742         sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
743         set_posix_acl_flag(sb);
744
745         VFS_ROOT(vfsp, &rootvp, error);
746         if (error)
747                 goto fail_unmount;
748
749         sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp));
750         if (!sb->s_root)
751                 goto fail_vnrele;
752         if (is_bad_inode(sb->s_root->d_inode))
753                 goto fail_vnrele;
754         if (linvfs_start_syncd(vfsp))
755                 goto fail_vnrele;
756         vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address);
757
758         kmem_free(args, sizeof(*args));
759         return 0;
760
761 fail_vnrele:
762         if (sb->s_root) {
763                 dput(sb->s_root);
764                 sb->s_root = NULL;
765         } else {
766                 VN_RELE(rootvp);
767         }
768
769 fail_unmount:
770         VFS_UNMOUNT(vfsp, 0, NULL, error);
771
772 fail_vfsop:
773         vfs_deallocate(vfsp);
774         kmem_free(args, sizeof(*args));
775         return -error;
776 }
777
778 STATIC struct super_block *
779 linvfs_get_sb(
780         struct file_system_type *fs_type,
781         int                     flags,
782         const char              *dev_name,
783         void                    *data)
784 {
785         return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super);
786 }
787
788
789 STATIC struct export_operations linvfs_export_ops = {
790         .get_parent             = linvfs_get_parent,
791         .get_dentry             = linvfs_get_dentry,
792 };
793
794 STATIC struct super_operations linvfs_sops = {
795         .alloc_inode            = linvfs_alloc_inode,
796         .destroy_inode          = linvfs_destroy_inode,
797         .write_inode            = linvfs_write_inode,
798         .clear_inode            = linvfs_clear_inode,
799         .put_super              = linvfs_put_super,
800         .write_super            = linvfs_write_super,
801         .write_super_lockfs     = linvfs_freeze_fs,
802         .unlockfs               = linvfs_unfreeze_fs,
803         .statfs                 = linvfs_statfs,
804         .remount_fs             = linvfs_remount,
805         .show_options           = linvfs_show_options,
806 };
807
808 STATIC struct quotactl_ops linvfs_qops = {
809         .get_xstate             = linvfs_getxstate,
810         .set_xstate             = linvfs_setxstate,
811         .get_xquota             = linvfs_getxquota,
812         .set_xquota             = linvfs_setxquota,
813 };
814
815 STATIC struct file_system_type xfs_fs_type = {
816         .owner                  = THIS_MODULE,
817         .name                   = "xfs",
818         .get_sb                 = linvfs_get_sb,
819         .kill_sb                = kill_block_super,
820         .fs_flags               = FS_REQUIRES_DEV,
821 };
822
823
824 STATIC int __init
825 init_xfs_fs( void )
826 {
827         int                     error;
828         struct sysinfo          si;
829         static char             message[] __initdata =
830                 KERN_INFO "SGI XFS " XFS_VERSION_STRING " with "
831                 XFS_BUILD_OPTIONS " enabled\n";
832
833         printk(message);
834
835         si_meminfo(&si);
836         xfs_physmem = si.totalram;
837
838         error = init_inodecache();
839         if (error < 0)
840                 goto undo_inodecache;
841
842         error = pagebuf_init();
843         if (error < 0)
844                 goto undo_pagebuf;
845
846         vn_init();
847         xfs_init();
848         uuid_init();
849         vfs_initdmapi();
850         vfs_initquota();
851
852         error = register_filesystem(&xfs_fs_type);
853         if (error)
854                 goto undo_register;
855         return 0;
856
857 undo_register:
858         pagebuf_terminate();
859
860 undo_pagebuf:
861         destroy_inodecache();
862
863 undo_inodecache:
864         return error;
865 }
866
867 STATIC void __exit
868 exit_xfs_fs( void )
869 {
870         unregister_filesystem(&xfs_fs_type);
871         xfs_cleanup();
872         vfs_exitquota();
873         vfs_exitdmapi();
874         pagebuf_terminate();
875         destroy_inodecache();
876 }
877
878 module_init(init_xfs_fs);
879 module_exit(exit_xfs_fs);
880
881 MODULE_AUTHOR("Silicon Graphics, Inc.");
882 MODULE_DESCRIPTION(
883         "SGI XFS " XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
884 MODULE_LICENSE("GPL");