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