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