2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #include "xfs_trans.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"
58 #include "xfs_rtalloc.h"
59 #include "xfs_error.h"
60 #include "xfs_itable.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
68 #include "xfs_version.h"
70 #include <linux/blkdev.h>
71 #include <linux/namei.h>
72 #include <linux/init.h>
73 #include <linux/mount.h>
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
;
80 STATIC
struct xfs_mount_args
*
82 struct super_block
*sb
)
84 struct xfs_mount_args
*args
;
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
);
90 /* Copy the already-parsed mount(2) flags we're interested in */
91 if (sb
->s_flags
& MS_NOATIME
)
92 args
->flags
|= XFSMNT_NOATIME
;
94 /* Default to 32 bit inodes on Linux all the time */
95 args
->flags
|= XFSMNT_32BITINODES
;
100 STATIC __inline__
void
104 vnode_t
*vp
= LINVFS_GET_VP(inode
);
106 if (vp
->v_type
== VNON
) {
107 make_bad_inode(inode
);
108 } else if (S_ISREG(inode
->i_mode
)) {
109 inode
->i_op
= &linvfs_file_inode_operations
;
110 inode
->i_fop
= &linvfs_file_operations
;
111 inode
->i_mapping
->a_ops
= &linvfs_aops
;
112 } else if (S_ISDIR(inode
->i_mode
)) {
113 inode
->i_op
= &linvfs_dir_inode_operations
;
114 inode
->i_fop
= &linvfs_dir_operations
;
115 } else if (S_ISLNK(inode
->i_mode
)) {
116 inode
->i_op
= &linvfs_symlink_inode_operations
;
118 inode
->i_mapping
->a_ops
= &linvfs_aops
;
120 inode
->i_op
= &linvfs_file_inode_operations
;
121 init_special_inode(inode
, inode
->i_mode
,
122 kdev_t_to_nr(inode
->i_rdev
));
126 STATIC __inline__
void
127 xfs_revalidate_inode(
132 struct inode
*inode
= LINVFS_GET_IP(vp
);
134 inode
->i_mode
= (ip
->i_d
.di_mode
& MODEMASK
) | VTTOIF(vp
->v_type
);
135 inode
->i_nlink
= ip
->i_d
.di_nlink
;
136 inode
->i_uid
= ip
->i_d
.di_uid
;
137 inode
->i_gid
= ip
->i_d
.di_gid
;
138 if (((1 << vp
->v_type
) & ((1<<VBLK
) | (1<<VCHR
))) == 0) {
139 inode
->i_rdev
= NODEV
;
141 xfs_dev_t dev
= ip
->i_df
.if_u2
.if_rdev
;
142 inode
->i_rdev
= XFS_DEV_TO_KDEVT(dev
);
144 inode
->i_blksize
= PAGE_CACHE_SIZE
;
145 inode
->i_generation
= ip
->i_d
.di_gen
;
146 inode
->i_size
= ip
->i_d
.di_size
;
148 XFS_FSB_TO_BB(mp
, ip
->i_d
.di_nblocks
+ ip
->i_delayed_blks
);
149 inode
->i_atime
.tv_sec
= ip
->i_d
.di_atime
.t_sec
;
150 inode
->i_atime
.tv_nsec
= ip
->i_d
.di_atime
.t_nsec
;
151 inode
->i_mtime
.tv_sec
= ip
->i_d
.di_mtime
.t_sec
;
152 inode
->i_mtime
.tv_nsec
= ip
->i_d
.di_mtime
.t_nsec
;
153 inode
->i_ctime
.tv_sec
= ip
->i_d
.di_ctime
.t_sec
;
154 inode
->i_ctime
.tv_nsec
= ip
->i_d
.di_ctime
.t_nsec
;
156 vp
->v_flag
&= ~VMODIFIED
;
160 xfs_initialize_vnode(
163 bhv_desc_t
*inode_bhv
,
166 xfs_inode_t
*ip
= XFS_BHVTOI(inode_bhv
);
167 struct inode
*inode
= LINVFS_GET_IP(vp
);
169 if (!inode_bhv
->bd_vobj
) {
170 vp
->v_vfsp
= bhvtovfs(bdp
);
171 bhv_desc_init(inode_bhv
, ip
, vp
, &xfs_vnodeops
);
172 bhv_insert(VN_BHV_HEAD(vp
), inode_bhv
);
175 vp
->v_type
= IFTOVT(ip
->i_d
.di_mode
);
177 /* Have we been called during the new inode create process,
178 * in which case we are too early to fill in the Linux inode.
180 if (vp
->v_type
== VNON
)
183 xfs_revalidate_inode(XFS_BHVTOM(bdp
), vp
, ip
);
185 /* For new inodes we need to set the ops vectors,
186 * and unlock the inode.
188 if (unlock
&& (inode
->i_state
& I_NEW
)) {
189 xfs_set_inodeops(inode
);
190 unlock_new_inode(inode
);
198 struct block_device
**bdevp
)
202 *bdevp
= open_bdev_excl(name
, 0, BDEV_FS
, mp
);
203 if (IS_ERR(*bdevp
)) {
204 error
= PTR_ERR(*bdevp
);
205 printk("XFS: Invalid device [%s], error=%d\n", name
, error
);
213 struct block_device
*bdev
)
216 close_bdev_excl(bdev
, BDEV_FS
);
223 pagebuf_delwri_flush(btp
, PBDF_WAIT
, NULL
);
230 xfs_flush_buftarg(btp
);
231 kmem_free(btp
, sizeof(*btp
));
235 xfs_readonly_buftarg(
238 return bdev_read_only(btp
->pbr_bdev
);
245 invalidate_bdev(btp
->pbr_bdev
, 1);
246 truncate_inode_pages(btp
->pbr_mapping
, 0LL);
253 return block_size(btp
->pbr_bdev
);
259 unsigned int blocksize
,
260 unsigned int sectorsize
)
262 btp
->pbr_bsize
= blocksize
;
263 btp
->pbr_sshift
= ffs(sectorsize
) - 1;
264 btp
->pbr_smask
= sectorsize
- 1;
266 if (set_blocksize(btp
->pbr_bdev
, sectorsize
)) {
268 "XFS: Cannot set_blocksize to %u on device 0x%x\n",
269 sectorsize
, btp
->pbr_dev
);
275 struct block_device
*bdev
)
279 btp
= kmem_zalloc(sizeof(*btp
), KM_SLEEP
);
281 btp
->pbr_dev
= bdev
->bd_dev
;
282 btp
->pbr_bdev
= bdev
;
283 btp
->pbr_mapping
= bdev
->bd_inode
->i_mapping
;
284 xfs_setsize_buftarg(btp
, PAGE_CACHE_SIZE
, bdev_hardsect_size(bdev
));
289 STATIC __inline__
unsigned int gfp_mask(void)
291 /* If we're not in a transaction, FS activity is ok */
292 if (current
->flags
& PF_FSTRANS
) return GFP_NOFS
;
296 STATIC
struct inode
*
298 struct super_block
*sb
)
302 vp
= (vnode_t
*)kmem_cache_alloc(linvfs_inode_cachep
, gfp_mask());
305 return LINVFS_GET_IP(vp
);
309 linvfs_destroy_inode(
312 kmem_cache_free(linvfs_inode_cachep
, LINVFS_GET_VP(inode
));
318 kmem_cache_t
*cachep
,
321 vnode_t
*vp
= (vnode_t
*)data
;
323 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
324 SLAB_CTOR_CONSTRUCTOR
)
325 inode_init_once(LINVFS_GET_IP(vp
));
329 init_inodecache( void )
331 linvfs_inode_cachep
= kmem_cache_create("linvfs_icache",
333 SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
,
336 if (linvfs_inode_cachep
== NULL
)
342 destroy_inodecache( void )
344 if (kmem_cache_destroy(linvfs_inode_cachep
))
345 printk(KERN_WARNING
"%s: cache still in use!\n", __FUNCTION__
);
349 * Attempt to flush the inode, this will actually fail
350 * if the inode is pinned, but we dirty the inode again
351 * at the point when it is unpinned after a log write,
352 * since this is when the inode itself becomes flushable.
359 vnode_t
*vp
= LINVFS_GET_VP(inode
);
360 int error
, flags
= FLUSH_INODE
;
363 vn_trace_entry(vp
, __FUNCTION__
, (inst_t
*)__return_address
);
366 VOP_IFLUSH(vp
, flags
, error
);
374 vnode_t
*vp
= LINVFS_GET_VP(inode
);
378 vn_trace_entry(vp
, __FUNCTION__
, (inst_t
*)__return_address
);
380 * Do all our cleanup, and remove this vnode.
387 #define SYNCD_FLAGS (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
392 vfs_t
*vfsp
= (vfs_t
*) arg
;
395 daemonize("xfs_syncd");
397 vfsp
->vfs_sync_task
= current
;
399 wake_up(&vfsp
->vfs_wait_sync_task
);
402 set_current_state(TASK_INTERRUPTIBLE
);
403 schedule_timeout(xfs_params
.sync_interval
);
404 if (vfsp
->vfs_flag
& VFS_UMOUNT
)
406 if (vfsp
->vfs_flag
& VFS_RDONLY
)
408 VFS_SYNC(vfsp
, SYNCD_FLAGS
, NULL
, error
);
411 vfsp
->vfs_sync_task
= NULL
;
413 wake_up(&vfsp
->vfs_wait_sync_task
);
419 linvfs_start_syncd(vfs_t
*vfsp
)
423 pid
= kernel_thread(syncd
, (void *) vfsp
,
424 CLONE_VM
| CLONE_FS
| CLONE_FILES
);
427 wait_event(vfsp
->vfs_wait_sync_task
, vfsp
->vfs_sync_task
);
432 linvfs_stop_syncd(vfs_t
*vfsp
)
434 vfsp
->vfs_flag
|= VFS_UMOUNT
;
437 wake_up_process(vfsp
->vfs_sync_task
);
438 wait_event(vfsp
->vfs_wait_sync_task
, !vfsp
->vfs_sync_task
);
443 struct super_block
*sb
)
445 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
448 linvfs_stop_syncd(vfsp
);
449 VFS_SYNC(vfsp
, SYNC_ATTR
|SYNC_DELWRI
, NULL
, error
);
451 VFS_UNMOUNT(vfsp
, 0, NULL
, error
);
453 printk("XFS unmount got error %d\n", error
);
454 printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__
, vfsp
);
458 vfs_deallocate(vfsp
);
463 struct super_block
*sb
)
465 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
468 if (sb
->s_flags
& MS_RDONLY
) {
469 sb
->s_dirt
= 0; /* paranoia */
472 /* Push the log and superblock a little */
473 VFS_SYNC(vfsp
, SYNC_FSDATA
, NULL
, error
);
479 struct super_block
*sb
,
480 struct kstatfs
*statp
)
482 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
485 VFS_STATVFS(vfsp
, statp
, NULL
, error
);
491 struct super_block
*sb
,
495 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
496 struct xfs_mount_args
*args
= args_allocate(sb
);
499 VFS_PARSEARGS(vfsp
, options
, args
, 1, error
);
501 VFS_MNTUPDATE(vfsp
, flags
, args
, error
);
502 kmem_free(args
, sizeof(*args
));
508 struct super_block
*sb
)
510 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
514 if (sb
->s_flags
& MS_RDONLY
)
516 VFS_ROOT(vfsp
, &vp
, error
);
517 VOP_IOCTL(vp
, LINVFS_GET_IP(vp
), NULL
, XFS_IOC_FREEZE
, 0, error
);
523 struct super_block
*sb
)
525 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
529 VFS_ROOT(vfsp
, &vp
, error
);
530 VOP_IOCTL(vp
, LINVFS_GET_IP(vp
), NULL
, XFS_IOC_THAW
, 0, error
);
534 STATIC
struct dentry
*
536 struct dentry
*child
)
540 struct dentry
*parent
;
541 struct inode
*ip
= NULL
;
542 struct dentry dotdot
;
544 dotdot
.d_name
.name
= "..";
545 dotdot
.d_name
.len
= 2;
549 vp
= LINVFS_GET_VP(child
->d_inode
);
550 VOP_LOOKUP(vp
, &dotdot
, &cvp
, 0, NULL
, NULL
, error
);
554 ip
= LINVFS_GET_IP(cvp
);
557 return ERR_PTR(-EACCES
);
561 return ERR_PTR(-error
);
562 parent
= d_alloc_anon(ip
);
565 parent
= ERR_PTR(-ENOMEM
);
570 STATIC
struct dentry
*
572 struct super_block
*sb
,
577 struct dentry
*result
;
579 vfs_t
*vfsp
= LINVFS_GET_VFS(sb
);
582 xfid
.fid_len
= sizeof(xfs_fid2_t
) - sizeof(xfid
.fid_len
);
584 xfid
.fid_gen
= ((__u32
*)data
)[1];
585 xfid
.fid_ino
= ((__u32
*)data
)[0];
587 VFS_VGET(vfsp
, &vp
, (fid_t
*)&xfid
, error
);
588 if (error
|| vp
== NULL
)
589 return ERR_PTR(-ESTALE
) ;
591 inode
= LINVFS_GET_IP(vp
);
592 result
= d_alloc_anon(inode
);
595 return ERR_PTR(-ENOMEM
);
603 struct vfsmount
*mnt
)
605 struct vfs
*vfsp
= LINVFS_GET_VFS(mnt
->mnt_sb
);
608 VFS_SHOWARGS(vfsp
, m
, error
);
614 struct super_block
*sb
,
615 struct fs_quota_stat
*fqs
)
617 struct vfs
*vfsp
= LINVFS_GET_VFS(sb
);
620 VFS_QUOTACTL(vfsp
, Q_XGETQSTAT
, 0, (caddr_t
)fqs
, error
);
626 struct super_block
*sb
,
630 struct vfs
*vfsp
= LINVFS_GET_VFS(sb
);
633 VFS_QUOTACTL(vfsp
, op
, 0, (caddr_t
)&flags
, error
);
639 struct super_block
*sb
,
642 struct fs_disk_quota
*fdq
)
644 struct vfs
*vfsp
= LINVFS_GET_VFS(sb
);
647 getmode
= (type
== GRPQUOTA
) ? Q_XGETGQUOTA
: Q_XGETQUOTA
;
648 VFS_QUOTACTL(vfsp
, getmode
, id
, (caddr_t
)fdq
, error
);
654 struct super_block
*sb
,
657 struct fs_disk_quota
*fdq
)
659 struct vfs
*vfsp
= LINVFS_GET_VFS(sb
);
662 setmode
= (type
== GRPQUOTA
) ? Q_XSETGQLIM
: Q_XSETQLIM
;
663 VFS_QUOTACTL(vfsp
, setmode
, id
, (caddr_t
)fdq
, error
);
669 struct super_block
*sb
,
674 struct vfs
*vfsp
= vfs_allocate();
675 struct xfs_mount_args
*args
= args_allocate(sb
);
676 struct kstatfs statvfs
;
679 vfsp
->vfs_super
= sb
;
680 LINVFS_SET_VFS(sb
, vfsp
);
681 if (sb
->s_flags
& MS_RDONLY
)
682 vfsp
->vfs_flag
|= VFS_RDONLY
;
683 bhv_insert_all_vfsops(vfsp
);
685 VFS_PARSEARGS(vfsp
, (char *)data
, args
, 0, error
);
687 bhv_remove_all_vfsops(vfsp
, 1);
691 sb_min_blocksize(sb
, BBSIZE
);
692 sb
->s_maxbytes
= XFS_MAX_FILE_OFFSET
;
693 sb
->s_export_op
= &linvfs_export_ops
;
694 sb
->s_qcop
= &linvfs_qops
;
695 sb
->s_op
= &linvfs_sops
;
697 VFS_MOUNT(vfsp
, args
, NULL
, error
);
699 bhv_remove_all_vfsops(vfsp
, 1);
703 VFS_STATVFS(vfsp
, &statvfs
, NULL
, error
);
708 sb
->s_magic
= XFS_SB_MAGIC
;
709 sb
->s_blocksize
= statvfs
.f_bsize
;
710 sb
->s_blocksize_bits
= ffs(statvfs
.f_bsize
) - 1;
711 set_posix_acl_flag(sb
);
713 VFS_ROOT(vfsp
, &rootvp
, error
);
717 sb
->s_root
= d_alloc_root(LINVFS_GET_IP(rootvp
));
720 if (is_bad_inode(sb
->s_root
->d_inode
))
722 if (linvfs_start_syncd(vfsp
))
724 vn_trace_exit(rootvp
, __FUNCTION__
, (inst_t
*)__return_address
);
726 kmem_free(args
, sizeof(*args
));
738 VFS_UNMOUNT(vfsp
, 0, NULL
, error
);
741 vfs_deallocate(vfsp
);
742 kmem_free(args
, sizeof(*args
));
746 STATIC
struct super_block
*
748 struct file_system_type
*fs_type
,
750 const char *dev_name
,
753 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, linvfs_fill_super
);
757 STATIC
struct export_operations linvfs_export_ops
= {
758 .get_parent
= linvfs_get_parent
,
759 .get_dentry
= linvfs_get_dentry
,
762 STATIC
struct super_operations linvfs_sops
= {
763 .alloc_inode
= linvfs_alloc_inode
,
764 .destroy_inode
= linvfs_destroy_inode
,
765 .write_inode
= linvfs_write_inode
,
766 .clear_inode
= linvfs_clear_inode
,
767 .put_super
= linvfs_put_super
,
768 .write_super
= linvfs_write_super
,
769 .write_super_lockfs
= linvfs_freeze_fs
,
770 .unlockfs
= linvfs_unfreeze_fs
,
771 .statfs
= linvfs_statfs
,
772 .remount_fs
= linvfs_remount
,
773 .show_options
= linvfs_show_options
,
776 STATIC
struct quotactl_ops linvfs_qops
= {
777 .get_xstate
= linvfs_getxstate
,
778 .set_xstate
= linvfs_setxstate
,
779 .get_xquota
= linvfs_getxquota
,
780 .set_xquota
= linvfs_setxquota
,
783 STATIC
struct file_system_type xfs_fs_type
= {
784 .owner
= THIS_MODULE
,
786 .get_sb
= linvfs_get_sb
,
787 .kill_sb
= kill_block_super
,
788 .fs_flags
= FS_REQUIRES_DEV
,
797 static char message
[] __initdata
=
798 KERN_INFO
"SGI XFS " XFS_VERSION_STRING
" with "
799 XFS_BUILD_OPTIONS
" enabled\n";
804 xfs_physmem
= si
.totalram
;
806 error
= init_inodecache();
808 goto undo_inodecache
;
810 error
= pagebuf_init();
820 error
= register_filesystem(&xfs_fs_type
);
829 destroy_inodecache();
838 unregister_filesystem(&xfs_fs_type
);
843 destroy_inodecache();
846 module_init(init_xfs_fs
);
847 module_exit(exit_xfs_fs
);
849 MODULE_AUTHOR("Silicon Graphics, Inc.");
851 "SGI XFS " XFS_VERSION_STRING
" with " XFS_BUILD_OPTIONS
" enabled");
852 MODULE_LICENSE("GPL");