bbaf61beea024d82994a8ff114b4798f8d045aac
[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_APPEND)
193                 inode->i_flags |= S_APPEND;
194         else
195                 inode->i_flags &= ~S_APPEND;
196         if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
197                 inode->i_flags |= S_SYNC;
198         else
199                 inode->i_flags &= ~S_SYNC;
200         if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
201                 inode->i_flags |= S_NOATIME;
202         else
203                 inode->i_flags &= ~S_NOATIME;
204         vp->v_flag &= ~VMODIFIED;
205 }
206
207 void
208 xfs_initialize_vnode(
209         bhv_desc_t              *bdp,
210         vnode_t                 *vp,
211         bhv_desc_t              *inode_bhv,
212         int                     unlock)
213 {
214         xfs_inode_t             *ip = XFS_BHVTOI(inode_bhv);
215         struct inode            *inode = LINVFS_GET_IP(vp);
216
217         if (!inode_bhv->bd_vobj) {
218                 vp->v_vfsp = bhvtovfs(bdp);
219                 bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
220                 bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
221         }
222
223         vp->v_type = IFTOVT(ip->i_d.di_mode);
224
225         /* Have we been called during the new inode create process,
226          * in which case we are too early to fill in the Linux inode.
227          */
228         if (vp->v_type == VNON)
229                 return;
230
231         xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip);
232
233         /* For new inodes we need to set the ops vectors,
234          * and unlock the inode.
235          */
236         if (unlock && (inode->i_state & I_NEW)) {
237                 xfs_set_inodeops(inode);
238                 unlock_new_inode(inode);
239         }
240 }
241
242 void
243 xfs_flush_inode(
244         xfs_inode_t     *ip)
245 {
246         struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
247
248         filemap_flush(inode->i_mapping);
249 }
250
251 void
252 xfs_flush_device(
253         xfs_inode_t     *ip)
254 {
255         sync_blockdev(XFS_ITOV(ip)->v_vfsp->vfs_super->s_bdev);
256         xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
257 }
258
259 int
260 xfs_blkdev_get(
261         xfs_mount_t             *mp,
262         const char              *name,
263         struct block_device     **bdevp)
264 {
265         int                     error = 0;
266
267         *bdevp = open_bdev_excl(name, 0, mp);
268         if (IS_ERR(*bdevp)) {
269                 error = PTR_ERR(*bdevp);
270                 printk("XFS: Invalid device [%s], error=%d\n", name, error);
271         }
272
273         return -error;
274 }
275
276 void
277 xfs_blkdev_put(
278         struct block_device     *bdev)
279 {
280         if (bdev)
281                 close_bdev_excl(bdev);
282 }
283
284
285 STATIC struct inode *
286 linvfs_alloc_inode(
287         struct super_block      *sb)
288 {
289         vnode_t                 *vp;
290
291         vp = (vnode_t *)kmem_cache_alloc(linvfs_inode_cachep, 
292                 kmem_flags_convert(KM_SLEEP));
293         if (!vp)
294                 return NULL;
295         return LINVFS_GET_IP(vp);
296 }
297
298 STATIC void
299 linvfs_destroy_inode(
300         struct inode            *inode)
301 {
302         kmem_cache_free(linvfs_inode_cachep, LINVFS_GET_VP(inode));
303 }
304
305 STATIC void
306 init_once(
307         void                    *data,
308         kmem_cache_t            *cachep,
309         unsigned long           flags)
310 {
311         vnode_t                 *vp = (vnode_t *)data;
312
313         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
314             SLAB_CTOR_CONSTRUCTOR)
315                 inode_init_once(LINVFS_GET_IP(vp));
316 }
317
318 STATIC int
319 init_inodecache( void )
320 {
321         linvfs_inode_cachep = kmem_cache_create("linvfs_icache",
322                                 sizeof(vnode_t), 0,
323                                 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
324                                 init_once, NULL);
325
326         if (linvfs_inode_cachep == NULL)
327                 return -ENOMEM;
328         return 0;
329 }
330
331 STATIC void
332 destroy_inodecache( void )
333 {
334         if (kmem_cache_destroy(linvfs_inode_cachep))
335                 printk(KERN_WARNING "%s: cache still in use!\n", __FUNCTION__);
336 }
337
338 /*
339  * Attempt to flush the inode, this will actually fail
340  * if the inode is pinned, but we dirty the inode again
341  * at the point when it is unpinned after a log write,
342  * since this is when the inode itself becomes flushable. 
343  */
344 STATIC void
345 linvfs_write_inode(
346         struct inode            *inode,
347         int                     sync)
348 {
349         vnode_t                 *vp = LINVFS_GET_VP(inode);
350         int                     error, flags = FLUSH_INODE;
351
352         if (vp) {
353                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
354                 if (sync)
355                         flags |= FLUSH_SYNC;
356                 VOP_IFLUSH(vp, flags, error);
357         }
358 }
359
360 STATIC void
361 linvfs_clear_inode(
362         struct inode            *inode)
363 {
364         vnode_t                 *vp = LINVFS_GET_VP(inode);
365
366         if (vp) {
367                 vn_rele(vp);
368                 vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
369                 /*
370                  * Do all our cleanup, and remove this vnode.
371                  */
372                 vn_remove(vp);
373         }
374 }
375
376
377 #define SYNCD_FLAGS     (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
378
379 STATIC int
380 xfssyncd(
381         void                    *arg)
382 {
383         vfs_t                   *vfsp = (vfs_t *) arg;
384         int                     error;
385
386         daemonize("xfssyncd");
387
388         vfsp->vfs_sync_task = current;
389         wmb();
390         wake_up(&vfsp->vfs_wait_sync_task);
391
392         for (;;) {
393                 set_current_state(TASK_INTERRUPTIBLE);
394                 schedule_timeout(xfs_syncd_interval);
395                 /* swsusp */
396                 if (current->flags & PF_FREEZE)
397                         refrigerator(PF_FREEZE);
398                 if (vfsp->vfs_flag & VFS_UMOUNT)
399                         break;
400                 if (vfsp->vfs_flag & VFS_RDONLY)
401                         continue;
402                 VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error);
403         }
404
405         vfsp->vfs_sync_task = NULL;
406         wmb();
407         wake_up(&vfsp->vfs_wait_sync_task);
408
409         return 0;
410 }
411
412 STATIC int
413 linvfs_start_syncd(
414         vfs_t                   *vfsp)
415 {
416         int                     pid;
417
418         pid = kernel_thread(xfssyncd, (void *) vfsp,
419                         CLONE_VM | CLONE_FS | CLONE_FILES);
420         if (pid < 0)
421                 return -pid;
422         wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task);
423         return 0;
424 }
425
426 STATIC void
427 linvfs_stop_syncd(
428         vfs_t                   *vfsp)
429 {
430         vfsp->vfs_flag |= VFS_UMOUNT;
431         wmb();
432
433         wake_up_process(vfsp->vfs_sync_task);
434         wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task);
435 }
436
437 STATIC void
438 linvfs_put_super(
439         struct super_block      *sb)
440 {
441         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
442         int                     error;
443
444         linvfs_stop_syncd(vfsp);
445         VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error);
446         if (!error)
447                 VFS_UNMOUNT(vfsp, 0, NULL, error);
448         if (error) {
449                 printk("XFS unmount got error %d\n", error);
450                 printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp);
451                 return;
452         }
453
454         vfs_deallocate(vfsp);
455 }
456
457 STATIC void
458 linvfs_write_super(
459         struct super_block      *sb)
460 {
461         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
462         int                     error;
463
464         if (sb->s_flags & MS_RDONLY) {
465                 sb->s_dirt = 0; /* paranoia */
466                 return;
467         }
468         /* Push the log and superblock a little */
469         VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error);
470         sb->s_dirt = 0;
471 }
472
473 STATIC int
474 linvfs_sync_super(
475         struct super_block      *sb,
476         int                     wait)
477 {
478         vfs_t           *vfsp = LINVFS_GET_VFS(sb);
479         int             error;
480         int             flags = SYNC_FSDATA;
481
482         if (wait)
483                 flags |= SYNC_WAIT;
484
485         VFS_SYNC(vfsp, flags, NULL, error);
486         sb->s_dirt = 0;
487
488         return -error;
489 }
490
491 STATIC int
492 linvfs_statfs(
493         struct super_block      *sb,
494         struct kstatfs          *statp)
495 {
496         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
497         int                     error;
498
499         VFS_STATVFS(vfsp, statp, NULL, error);
500         return -error;
501 }
502
503 STATIC int
504 linvfs_remount(
505         struct super_block      *sb,
506         int                     *flags,
507         char                    *options)
508 {
509         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
510         struct xfs_mount_args   *args = xfs_args_allocate(sb);
511         int                     error;
512
513         VFS_PARSEARGS(vfsp, options, args, 1, error);
514         if (!error)
515                 VFS_MNTUPDATE(vfsp, flags, args, error);
516         kmem_free(args, sizeof(*args));
517         return -error;
518 }
519
520 STATIC void
521 linvfs_freeze_fs(
522         struct super_block      *sb)
523 {
524         VFS_FREEZE(LINVFS_GET_VFS(sb));
525 }
526
527 STATIC struct dentry *
528 linvfs_get_parent(
529         struct dentry           *child)
530 {
531         int                     error;
532         vnode_t                 *vp, *cvp;
533         struct dentry           *parent;
534         struct inode            *ip = NULL;
535         struct dentry           dotdot;
536
537         dotdot.d_name.name = "..";
538         dotdot.d_name.len = 2;
539         dotdot.d_inode = 0;
540
541         cvp = NULL;
542         vp = LINVFS_GET_VP(child->d_inode);
543         VOP_LOOKUP(vp, &dotdot, &cvp, 0, NULL, NULL, error);
544
545         if (!error) {
546                 ASSERT(cvp);
547                 ip = LINVFS_GET_IP(cvp);
548                 if (!ip) {
549                         VN_RELE(cvp);
550                         return ERR_PTR(-EACCES);
551                 }
552         }
553         if (error)
554                 return ERR_PTR(-error);
555         parent = d_alloc_anon(ip);
556         if (!parent) {
557                 VN_RELE(cvp);
558                 parent = ERR_PTR(-ENOMEM);
559         }
560         return parent;
561 }
562
563 STATIC struct dentry *
564 linvfs_get_dentry(
565         struct super_block      *sb,
566         void                    *data)
567 {
568         vnode_t                 *vp;
569         struct inode            *inode;
570         struct dentry           *result;
571         xfs_fid2_t              xfid;
572         vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
573         int                     error;
574
575         xfid.fid_len = sizeof(xfs_fid2_t) - sizeof(xfid.fid_len);
576         xfid.fid_pad = 0;
577         xfid.fid_gen = ((__u32 *)data)[1];
578         xfid.fid_ino = ((__u32 *)data)[0];
579
580         VFS_VGET(vfsp, &vp, (fid_t *)&xfid, error);
581         if (error || vp == NULL)
582                 return ERR_PTR(-ESTALE) ;
583
584         inode = LINVFS_GET_IP(vp);
585         result = d_alloc_anon(inode);
586         if (!result) {
587                 iput(inode);
588                 return ERR_PTR(-ENOMEM);
589         }
590         return result;
591 }
592
593 STATIC int
594 linvfs_show_options(
595         struct seq_file         *m,
596         struct vfsmount         *mnt)
597 {
598         struct vfs              *vfsp = LINVFS_GET_VFS(mnt->mnt_sb);
599         int                     error;
600
601         VFS_SHOWARGS(vfsp, m, error);
602         return error;
603 }
604
605 STATIC int
606 linvfs_getxstate(
607         struct super_block      *sb,
608         struct fs_quota_stat    *fqs)
609 {
610         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
611         int                     error;
612
613         VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error);
614         return -error;
615 }
616
617 STATIC int
618 linvfs_setxstate(
619         struct super_block      *sb,
620         unsigned int            flags,
621         int                     op)
622 {
623         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
624         int                     error;
625
626         VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error);
627         return -error;
628 }
629
630 STATIC int
631 linvfs_getxquota(
632         struct super_block      *sb,
633         int                     type,
634         qid_t                   id,
635         struct fs_disk_quota    *fdq)
636 {
637         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
638         int                     error, getmode;
639
640         getmode = (type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETQUOTA;
641         VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error);
642         return -error;
643 }
644
645 STATIC int
646 linvfs_setxquota(
647         struct super_block      *sb,
648         int                     type,
649         qid_t                   id,
650         struct fs_disk_quota    *fdq)
651 {
652         struct vfs              *vfsp = LINVFS_GET_VFS(sb);
653         int                     error, setmode;
654
655         setmode = (type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETQLIM;
656         VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error);
657         return -error;
658 }
659
660 STATIC int
661 linvfs_fill_super(
662         struct super_block      *sb,
663         void                    *data,
664         int                     silent)
665 {
666         vnode_t                 *rootvp;
667         struct vfs              *vfsp = vfs_allocate();
668         struct xfs_mount_args   *args = xfs_args_allocate(sb);
669         struct kstatfs          statvfs;
670         int                     error, error2;
671
672         vfsp->vfs_super = sb;
673         LINVFS_SET_VFS(sb, vfsp);
674         if (sb->s_flags & MS_RDONLY)
675                 vfsp->vfs_flag |= VFS_RDONLY;
676         bhv_insert_all_vfsops(vfsp);
677
678         VFS_PARSEARGS(vfsp, (char *)data, args, 0, error);
679         if (error) {
680                 bhv_remove_all_vfsops(vfsp, 1);
681                 goto fail_vfsop;
682         }
683
684         sb_min_blocksize(sb, BBSIZE);
685         sb->s_export_op = &linvfs_export_ops;
686         sb->s_qcop = &linvfs_qops;
687         sb->s_op = &linvfs_sops;
688
689         VFS_MOUNT(vfsp, args, NULL, error);
690         if (error) {
691                 bhv_remove_all_vfsops(vfsp, 1);
692                 goto fail_vfsop;
693         }
694
695         VFS_STATVFS(vfsp, &statvfs, NULL, error);
696         if (error)
697                 goto fail_unmount;
698
699         sb->s_dirt = 1;
700         sb->s_magic = statvfs.f_type;
701         sb->s_blocksize = statvfs.f_bsize;
702         sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
703         sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
704         set_posix_acl_flag(sb);
705
706         VFS_ROOT(vfsp, &rootvp, error);
707         if (error)
708                 goto fail_unmount;
709
710         sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp));
711         if (!sb->s_root) {
712                 error = ENOMEM;
713                 goto fail_vnrele;
714         }
715         if (is_bad_inode(sb->s_root->d_inode)) {
716                 error = EINVAL;
717                 goto fail_vnrele;
718         }
719         if ((error = linvfs_start_syncd(vfsp)))
720                 goto fail_vnrele;
721         vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address);
722
723         kmem_free(args, sizeof(*args));
724         return 0;
725
726 fail_vnrele:
727         if (sb->s_root) {
728                 dput(sb->s_root);
729                 sb->s_root = NULL;
730         } else {
731                 VN_RELE(rootvp);
732         }
733
734 fail_unmount:
735         VFS_UNMOUNT(vfsp, 0, NULL, error2);
736
737 fail_vfsop:
738         vfs_deallocate(vfsp);
739         kmem_free(args, sizeof(*args));
740         return -error;
741 }
742
743 STATIC struct super_block *
744 linvfs_get_sb(
745         struct file_system_type *fs_type,
746         int                     flags,
747         const char              *dev_name,
748         void                    *data)
749 {
750         return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super);
751 }
752
753
754 STATIC struct export_operations linvfs_export_ops = {
755         .get_parent             = linvfs_get_parent,
756         .get_dentry             = linvfs_get_dentry,
757 };
758
759 STATIC struct super_operations linvfs_sops = {
760         .alloc_inode            = linvfs_alloc_inode,
761         .destroy_inode          = linvfs_destroy_inode,
762         .write_inode            = linvfs_write_inode,
763         .clear_inode            = linvfs_clear_inode,
764         .put_super              = linvfs_put_super,
765         .write_super            = linvfs_write_super,
766         .sync_fs                = linvfs_sync_super,
767         .write_super_lockfs     = linvfs_freeze_fs,
768         .statfs                 = linvfs_statfs,
769         .remount_fs             = linvfs_remount,
770         .show_options           = linvfs_show_options,
771 };
772
773 STATIC struct quotactl_ops linvfs_qops = {
774         .get_xstate             = linvfs_getxstate,
775         .set_xstate             = linvfs_setxstate,
776         .get_xquota             = linvfs_getxquota,
777         .set_xquota             = linvfs_setxquota,
778 };
779
780 STATIC struct file_system_type xfs_fs_type = {
781         .owner                  = THIS_MODULE,
782         .name                   = "xfs",
783         .get_sb                 = linvfs_get_sb,
784         .kill_sb                = kill_block_super,
785         .fs_flags               = FS_REQUIRES_DEV,
786 };
787
788
789 STATIC int __init
790 init_xfs_fs( void )
791 {
792         int                     error;
793         struct sysinfo          si;
794         static char             message[] __initdata = KERN_INFO \
795                 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
796
797         printk(message);
798
799         si_meminfo(&si);
800         xfs_physmem = si.totalram;
801
802         ktrace_init(64);
803
804         error = init_inodecache();
805         if (error < 0)
806                 goto undo_inodecache;
807
808         error = pagebuf_init();
809         if (error < 0)
810                 goto undo_pagebuf;
811
812         vn_init();
813         xfs_init();
814         uuid_init();
815         vfs_initdmapi();
816         vfs_initquota();
817
818         error = register_filesystem(&xfs_fs_type);
819         if (error)
820                 goto undo_register;
821         return 0;
822
823 undo_register:
824         pagebuf_terminate();
825
826 undo_pagebuf:
827         destroy_inodecache();
828
829 undo_inodecache:
830         return error;
831 }
832
833 STATIC void __exit
834 exit_xfs_fs( void )
835 {
836         vfs_exitquota();
837         vfs_exitdmapi();
838         unregister_filesystem(&xfs_fs_type);
839         xfs_cleanup();
840         pagebuf_terminate();
841         destroy_inodecache();
842         ktrace_uninit();
843 }
844
845 module_init(init_xfs_fs);
846 module_exit(exit_xfs_fs);
847
848 MODULE_AUTHOR("Silicon Graphics, Inc.");
849 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
850 MODULE_LICENSE("GPL");