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