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