1 /*
2  * Copyright (c) 2000-2003 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 #ifndef __XFS_VFS_H__
33 #define __XFS_VFS_H__
34 
35 #include <linux/vfs.h>
36 #include "xfs_fs.h"
37 
38 struct fid;
39 struct vfs;
40 struct cred;
41 struct vnode;
42 struct statfs;
43 struct seq_file;
44 struct super_block;
45 struct xfs_mount_args;
46 
47 typedef struct statfs xfs_statfs_t;
48 
49 typedef struct vfs_sync_work {
50 	struct list_head	w_list;
51 	struct vfs		*w_vfs;
52 	void			*w_data;	/* syncer routine argument */
53 	void			(*w_syncer)(struct vfs *, void *);
54 } vfs_sync_work_t;
55 
56 typedef struct vfs {
57 	u_int			vfs_flag;	/* flags */
58 	xfs_fsid_t		vfs_fsid;	/* file system ID */
59 	xfs_fsid_t		*vfs_altfsid;	/* An ID fixed for life of FS */
60 	bhv_head_t		vfs_bh;		/* head of vfs behavior chain */
61 	struct super_block	*vfs_super;	/* generic superblock pointer */
62 	struct task_struct	*vfs_sync_task;	/* generalised sync thread */
63 	vfs_sync_work_t		vfs_sync_work;	/* work item for VFS_SYNC */
64 	struct list_head	vfs_sync_list;	/* sync thread work item list */
65 	spinlock_t		vfs_sync_lock;	/* work item list lock */
66 	wait_queue_head_t	vfs_wait_sync_task;
67 	int			vfs_frozen;
68 	wait_queue_head_t	vfs_wait_unfrozen;
69 } vfs_t;
70 
71 #define vfs_fbhv		vfs_bh.bh_first	/* 1st on vfs behavior chain */
72 
73 #define bhvtovfs(bdp)		( (struct vfs *)BHV_VOBJ(bdp) )
74 #define bhvtovfsops(bdp)	( (struct vfsops *)BHV_OPS(bdp) )
75 #define VFS_BHVHEAD(vfs)	( &(vfs)->vfs_bh )
76 #define VFS_REMOVEBHV(vfs, bdp)	( bhv_remove(VFS_BHVHEAD(vfs), bdp) )
77 
78 #define VFS_POSITION_BASE	BHV_POSITION_BASE	/* chain bottom */
79 #define VFS_POSITION_TOP	BHV_POSITION_TOP	/* chain top */
80 #define VFS_POSITION_INVALID	BHV_POSITION_INVALID	/* invalid pos. num */
81 
82 typedef enum {
83 	VFS_BHV_UNKNOWN,	/* not specified */
84 	VFS_BHV_XFS,		/* xfs */
85 	VFS_BHV_DM,		/* data migration */
86 	VFS_BHV_QM,		/* quota manager */
87 	VFS_BHV_IO,		/* IO path */
88 	VFS_BHV_END		/* housekeeping end-of-range */
89 } vfs_bhv_t;
90 
91 #define VFS_POSITION_XFS	(BHV_POSITION_BASE)
92 #define VFS_POSITION_DM		(VFS_POSITION_BASE+10)
93 #define VFS_POSITION_QM		(VFS_POSITION_BASE+20)
94 #define VFS_POSITION_IO		(VFS_POSITION_BASE+30)
95 
96 #define VFS_RDONLY		0x0001	/* read-only vfs */
97 #define VFS_GRPID		0x0002	/* group-ID assigned from directory */
98 #define VFS_DMI			0x0004	/* filesystem has the DMI enabled */
99 #define VFS_UMOUNT		0x0008	/* unmount in progress */
100 #define VFS_END			0x0008	/* max flag */
101 
102 #define SYNC_ATTR		0x0001	/* sync attributes */
103 #define SYNC_CLOSE		0x0002	/* close file system down */
104 #define SYNC_DELWRI		0x0004	/* look at delayed writes */
105 #define SYNC_WAIT		0x0008	/* wait for i/o to complete */
106 #define SYNC_BDFLUSH		0x0010	/* BDFLUSH is calling -- don't block */
107 #define SYNC_FSDATA		0x0020	/* flush fs data (e.g. superblocks) */
108 #define SYNC_REFCACHE		0x0040  /* prune some of the nfs ref cache */
109 #define SYNC_REMOUNT		0x0080  /* remount readonly, no dummy LRs */
110 
111 #define IGET_NOALLOC		0x0001	/* vfs_get_inode may return NULL */
112 
113 typedef int	(*vfs_mount_t)(bhv_desc_t *,
114 				struct xfs_mount_args *, struct cred *);
115 typedef int	(*vfs_parseargs_t)(bhv_desc_t *, char *,
116 				struct xfs_mount_args *, int);
117 typedef	int	(*vfs_showargs_t)(bhv_desc_t *, struct seq_file *);
118 typedef int	(*vfs_unmount_t)(bhv_desc_t *, int, struct cred *);
119 typedef int	(*vfs_mntupdate_t)(bhv_desc_t *, int *,
120 				struct xfs_mount_args *);
121 typedef int	(*vfs_root_t)(bhv_desc_t *, struct vnode **);
122 typedef int	(*vfs_statvfs_t)(bhv_desc_t *, xfs_statfs_t *, struct vnode *);
123 typedef int	(*vfs_sync_t)(bhv_desc_t *, int, struct cred *);
124 typedef int	(*vfs_vget_t)(bhv_desc_t *, struct vnode **, struct fid *);
125 typedef int	(*vfs_dmapiops_t)(bhv_desc_t *, caddr_t);
126 typedef int	(*vfs_quotactl_t)(bhv_desc_t *, int, int, caddr_t);
127 typedef void	(*vfs_init_vnode_t)(bhv_desc_t *,
128 				struct vnode *, bhv_desc_t *, int);
129 typedef void	(*vfs_force_shutdown_t)(bhv_desc_t *, int, char *, int);
130 typedef void	(*vfs_freeze_t)(bhv_desc_t *);
131 typedef	struct inode * (*vfs_get_inode_t)(bhv_desc_t *, xfs_ino_t, int);
132 
133 typedef struct vfsops {
134 	bhv_position_t		vf_position;	/* behavior chain position */
135 	vfs_mount_t		vfs_mount;	/* mount file system */
136 	vfs_parseargs_t		vfs_parseargs;	/* parse mount options */
137 	vfs_showargs_t		vfs_showargs;	/* unparse mount options */
138 	vfs_unmount_t		vfs_unmount;	/* unmount file system */
139 	vfs_mntupdate_t		vfs_mntupdate;	/* update file system options */
140 	vfs_root_t		vfs_root;	/* get root vnode */
141 	vfs_statvfs_t		vfs_statvfs;	/* file system statistics */
142 	vfs_sync_t		vfs_sync;	/* flush files */
143 	vfs_vget_t		vfs_vget;	/* get vnode from fid */
144 	vfs_dmapiops_t		vfs_dmapiops;	/* data migration */
145 	vfs_quotactl_t		vfs_quotactl;	/* disk quota */
146 	vfs_get_inode_t		vfs_get_inode;	/* bhv specific iget */
147 	vfs_init_vnode_t	vfs_init_vnode;	/* initialize a new vnode */
148 	vfs_force_shutdown_t	vfs_force_shutdown;	/* crash and burn */
149 	vfs_freeze_t		vfs_freeze;	/* freeze fs for snapshot */
150 } vfsops_t;
151 
152 /*
153  * VFS's.  Operates on vfs structure pointers (starts at bhv head).
154  */
155 #define VHEAD(v)			((v)->vfs_fbhv)
156 #define VFS_MOUNT(v, ma,cr, rv)		((rv) = vfs_mount(VHEAD(v), ma,cr))
157 #define VFS_PARSEARGS(v, o,ma,f, rv)	((rv) = vfs_parseargs(VHEAD(v), o,ma,f))
158 #define VFS_SHOWARGS(v, m, rv)		((rv) = vfs_showargs(VHEAD(v), m))
159 #define VFS_UNMOUNT(v, f, cr, rv)	((rv) = vfs_unmount(VHEAD(v), f,cr))
160 #define VFS_MNTUPDATE(v, fl, args, rv)	((rv) = vfs_mntupdate(VHEAD(v), fl, args))
161 #define VFS_ROOT(v, vpp, rv)		((rv) = vfs_root(VHEAD(v), vpp))
162 #define VFS_STATVFS(v, sp,vp, rv)	((rv) = vfs_statvfs(VHEAD(v), sp,vp))
163 #define VFS_SYNC(v, flag,cr, rv)	((rv) = vfs_sync(VHEAD(v), flag,cr))
164 #define VFS_VGET(v, vpp,fidp, rv)	((rv) = vfs_vget(VHEAD(v), vpp,fidp))
165 #define VFS_DMAPIOPS(v, p, rv)		((rv) = vfs_dmapiops(VHEAD(v), p))
166 #define VFS_QUOTACTL(v, c,id,p, rv)	((rv) = vfs_quotactl(VHEAD(v), c,id,p))
167 #define VFS_GET_INODE(v, ino, fl)	( vfs_get_inode(VHEAD(v), ino,fl) )
168 #define VFS_INIT_VNODE(v, vp,b,ul)	( vfs_init_vnode(VHEAD(v), vp,b,ul) )
169 #define VFS_FORCE_SHUTDOWN(v, fl,f,l)	( vfs_force_shutdown(VHEAD(v), fl,f,l) )
170 #define VFS_FREEZE(v)			( vfs_freeze(VHEAD(v)) )
171 
172 /*
173  * PVFS's.  Operates on behavior descriptor pointers.
174  */
175 #define PVFS_MOUNT(b, ma,cr, rv)	((rv) = vfs_mount(b, ma,cr))
176 #define PVFS_PARSEARGS(b, o,ma,f, rv)	((rv) = vfs_parseargs(b, o,ma,f))
177 #define PVFS_SHOWARGS(b, m, rv)		((rv) = vfs_showargs(b, m))
178 #define PVFS_UNMOUNT(b, f,cr, rv)	((rv) = vfs_unmount(b, f,cr))
179 #define PVFS_MNTUPDATE(b, fl, args, rv)	((rv) = vfs_mntupdate(b, fl, args))
180 #define PVFS_ROOT(b, vpp, rv)		((rv) = vfs_root(b, vpp))
181 #define PVFS_STATVFS(b, sp,vp, rv)	((rv) = vfs_statvfs(b, sp,vp))
182 #define PVFS_SYNC(b, flag,cr, rv)	((rv) = vfs_sync(b, flag,cr))
183 #define PVFS_VGET(b, vpp,fidp, rv)	((rv) = vfs_vget(b, vpp,fidp))
184 #define PVFS_DMAPIOPS(b, p, rv)		((rv) = vfs_dmapiops(b, p))
185 #define PVFS_QUOTACTL(b, c,id,p, rv)	((rv) = vfs_quotactl(b, c,id,p))
186 #define PVFS_GET_INODE(b, ino,fl)	( vfs_get_inode(b, ino,fl) )
187 #define PVFS_INIT_VNODE(b, vp,b2,ul)	( vfs_init_vnode(b, vp,b2,ul) )
188 #define PVFS_FORCE_SHUTDOWN(b, fl,f,l)	( vfs_force_shutdown(b, fl,f,l) )
189 #define PVFS_FREEZE(b)			( vfs_freeze(b) )
190 
191 extern int vfs_mount(bhv_desc_t *, struct xfs_mount_args *, struct cred *);
192 extern int vfs_parseargs(bhv_desc_t *, char *, struct xfs_mount_args *, int);
193 extern int vfs_showargs(bhv_desc_t *, struct seq_file *);
194 extern int vfs_unmount(bhv_desc_t *, int, struct cred *);
195 extern int vfs_mntupdate(bhv_desc_t *, int *, struct xfs_mount_args *);
196 extern int vfs_root(bhv_desc_t *, struct vnode **);
197 extern int vfs_statvfs(bhv_desc_t *, xfs_statfs_t *, struct vnode *);
198 extern int vfs_sync(bhv_desc_t *, int, struct cred *);
199 extern int vfs_vget(bhv_desc_t *, struct vnode **, struct fid *);
200 extern int vfs_dmapiops(bhv_desc_t *, caddr_t);
201 extern int vfs_quotactl(bhv_desc_t *, int, int, caddr_t);
202 extern struct inode *vfs_get_inode(bhv_desc_t *, xfs_ino_t, int);
203 extern void vfs_init_vnode(bhv_desc_t *, struct vnode *, bhv_desc_t *, int);
204 extern void vfs_force_shutdown(bhv_desc_t *, int, char *, int);
205 extern void vfs_freeze(bhv_desc_t *);
206 
207 typedef struct bhv_vfsops {
208 	struct vfsops		bhv_common;
209 	void *			bhv_custom;
210 } bhv_vfsops_t;
211 
212 #define vfs_bhv_lookup(v, id)	( bhv_lookup_range(&(v)->vfs_bh, (id), (id)) )
213 #define vfs_bhv_custom(b)	( ((bhv_vfsops_t *)BHV_OPS(b))->bhv_custom )
214 #define vfs_bhv_set_custom(b,o)	( (b)->bhv_custom = (void *)(o))
215 #define vfs_bhv_clr_custom(b)	( (b)->bhv_custom = NULL )
216 
217 extern vfs_t *vfs_allocate(void);
218 extern void vfs_deallocate(vfs_t *);
219 extern void vfs_insertops(vfs_t *, bhv_vfsops_t *);
220 extern void vfs_insertbhv(vfs_t *, bhv_desc_t *, vfsops_t *, void *);
221 
222 extern void bhv_insert_all_vfsops(struct vfs *);
223 extern void bhv_remove_all_vfsops(struct vfs *, int);
224 extern void bhv_remove_vfsops(struct vfs *, int);
225 
226 enum {
227 	SB_UNFROZEN = 0,
228 	SB_FREEZE_WRITE	= 1,
229 	SB_FREEZE_TRANS = 2,
230 };
231 
232 #define fs_frozen(vfsp)		((vfsp)->vfs_frozen)
233 #define fs_check_frozen(vfsp, level) \
234 	wait_event((vfsp)->vfs_wait_unfrozen, ((vfsp)->vfs_frozen < (level)))
235 
236 #endif	/* __XFS_VFS_H__ */
237