Standardize License information
[openafs.git] / src / afs / IRIX / osi_vfs.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * SGI specific vfs related defines
12  */
13 #ifndef _SGI_VFS_H_
14 #define _SGI_VFS_H_
15
16 #if !defined(AFS_SGI65_ENV)
17 /* In Irix 6.5, the r/w-vops rwlocks the vnode if not already locked. */
18 #define IO_ISLOCKED 0
19 #endif
20
21 /*
22  * UFS -> EFS/XFS translations
23  */
24 #ifdef AFS_SGI62_ENV
25 #ifdef AFS_SGI64_ENV
26 #define EFS_VTOI(vp)    bhvtoi(VNODE_TO_FIRST_BHV(vp))
27 /* Note: If SGI ever has more than one behavior per vnode, we'll have
28  * to search for the one we want.
29  */
30 #define XFS_VTOI(V) ((xfs_inode_t*)((V)->v_fbhv->bd_pdata))
31 #define vfstom(V) (bhvtom((V)->vfs_fbhv))
32 #else
33 #define EFS_VTOI(vp)    vtoi(vp)
34 #endif
35 #define EFS_ITOV(ip)    itov(ip)
36 #else
37 #define ITOV(ip)        itov(ip)
38 #define VTOI(vp)        vtoi(vp)
39 #define EFS_ITOV ITOV
40 #define EFS_VTOI VTOI
41 #endif
42
43 #ifdef AFS_SGI62_ENV
44 struct xfs_inode;
45 typedef struct xfs_inode xfs_inode_t;
46 #define xfs_ino_t uint64_t
47 #define XFS_ILOCK_SHARED 0x08
48 struct xfs_trans;
49 struct xfs_mount;
50 extern int xfs_iget(struct mount *, struct xfs_trans *, xfs_ino_t,
51                          uint, xfs_inode_t **, daddr_t);
52
53 #ifdef AFS_SGI64_ENV
54 #define XFS_ITOV(ip) BHV_TO_VNODE((struct bhv_desc *)(((char*)(ip)) + 6*sizeof(void*)))
55 #else
56 #define XFS_ITOV(ip) (*((vnode_t**)((((char*)(ip)) + 6*sizeof(void*)))))
57 #endif
58
59 /* When we have XFS only clients, then these macros will be defined in
60  * terms of the XFS inode only.
61  */
62 #ifdef AFS_SGI_DUAL_FS_CACHE
63 #define AFS_SGI_EFS_CACHE 0
64 #define AFS_SGI_XFS_CACHE 1
65 extern int afs_CacheFSType;
66 extern vnode_t * (*afs_IGetVnode)(ino_t);
67 extern struct vnodeops *afs_efs_vnodeopsp;
68 extern struct vnodeops *afs_xfs_vnodeopsp;
69
70 #define AFS_SGI_IGETVNODE(INO) (*afs_IGetVnode)(INO)
71 /* These need to be functions to wrap the vnode op calls. */
72 extern ino_t VnodeToIno(vnode_t *vp);
73 extern dev_t VnodeToDev(vnode_t *vp);
74 extern off_t VnodeToSize(vnode_t *vp);
75 #else
76 /* Just the EFS variants exist for now. */
77 #define VnodeToIno(vp)          ((ino_t)(EFS_VTOI((vp))->i_number))
78 #define VnodeToDev(vp)          EFS_VTOI((vp))->i_dev
79 #define VnodeToSize(vp)         EFS_VTOI((vp))->i_size
80 #define AFS_SGI_IGETVNODE(INO)  afs_EFSIGetVnode(INO)
81 #endif
82 #else /* AFS_SGI62_ENV */
83 #define AFS_SGI_IGETVNODE(INO)  afs_EFSIGetVnode(INO)
84 #endif
85
86 /* Page routines are vnode ops in Irix 6.5. These macros paper over the
87  * differences.
88  */
89 #ifdef AFS_SGI65_ENV
90 #define PTOSSVP(vp, off, len)  VOP_TOSS_PAGES((vp), (off), (len), 0)
91 #define PFLUSHINVALVP(vp, off, len) VOP_INVALFREE_PAGES((vp), (len))
92 #define PFLUSHVP(vp, len, flags, code) \
93                 VOP_FLUSH_PAGES((vp), 0, (len), (flags), 0, code)
94 #define PINVALFREE(vp, off)    VOP_INVALFREE_PAGES((vp), (off))
95 #else
96 #define PTOSSVP         ptossvp
97 #define PFLUSHINVALVP   pflushinvalp
98 #define PFLUSHVP(vp, len, flags, code) code = pflushvp(vp, len, flags)
99 #define PINVALFREE      pinvalfree
100 #endif
101
102
103 /*
104  * VFS translations
105  */
106 #ifdef AFS_SGI_VNODE_GLUE
107 /* The Octane does not have the mrlock_t in the bvh_head_t. So we should
108  * not lock it.
109  */
110 extern int afs_is_numa_arch;
111 #define BHV_IPREVENT(BHP) afs_is_numa_arch ? BHV_INSERT_PREVENT(BHP) : (void)0
112 #define BHV_IALLOW(BHP)   afs_is_numa_arch ? BHV_INSERT_ALLOW(BHP) : (void)0
113
114 /* similar definition in /usr/include/sys/vfs.h (sgi_64) */
115 #define VFS_STATFS(vfsp,sp,vp)\
116         (*((vfsops_t *)(vfsp)->vfs_fops)->vfs_statvfs)((vfsp)->vfs_fbhv,sp,vp)
117 #define AFS_VOP_ATTR_SET(vp, name, value, valuelen, flags, cred, rv) \
118 {       \
119         BHV_IPREVENT(&(vp)->v_bh);      \
120         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_attr_set)((vp)->v_fbhv,name,value,valuelen,flags,cred); \
121         BHV_IALLOW(&(vp)->v_bh);        \
122 }
123
124 #define AFS_VOP_ATTR_GET(vp, name, value, valuelenp, flags, cred, rv) \
125 {       \
126         BHV_IPREVENT(&(vp)->v_bh);      \
127         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_attr_get)((vp)->v_fbhv,name,value,valuelenp,flags,cred); \
128         BHV_IALLOW(&(vp)->v_bh);        \
129 }
130 #define AFS_VOP_SETATTR(vp, vap, f, cr, rv) \
131 {       \
132         BHV_IPREVENT(&(vp)->v_bh);      \
133         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_setattr)((vp)->v_fbhv, vap, f, cr);    \
134         BHV_IALLOW(&(vp)->v_bh);        \
135 }
136 #define AFS_VOP_GETATTR(vp, vap, f, cr, rv) \
137 {       \
138         BHV_IPREVENT(&(vp)->v_bh);      \
139         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_getattr)((vp)->v_fbhv, vap, f, cr);    \
140         BHV_IALLOW(&(vp)->v_bh);        \
141 }
142 #define AFS_VOP_REMOVE(dvp,p,cr,rv) \
143 {       \
144         BHV_IPREVENT(&(dvp)->v_bh);     \
145         rv = (*((vnodeops_t *)(dvp)->v_fops)->vop_remove)((dvp)->v_fbhv,p,cr);  \
146         BHV_IALLOW(&(dvp)->v_bh);       \
147 }
148 #define AFS_VOP_LOOKUP(vp,cp,vpp,pnp,f,rdir,cr,rv) \
149 {       \
150         BHV_IPREVENT(&(vp)->v_bh);      \
151         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_lookup)((vp)->v_fbhv,cp,vpp,pnp,f,rdir,cr);    \
152         BHV_IALLOW(&(vp)->v_bh);        \
153 }
154 #define AFS_VOP_RMDIR(dp,p,cdir,cr,rv) \
155 {       \
156         BHV_IPREVENT(&(dp)->v_bh);      \
157         rv = (*((vnodeops_t *)(dp)->v_fops)->vop_rmdir)((dp)->v_fbhv,p,cdir,cr);        \
158         BHV_IALLOW(&(dp)->v_bh);        \
159 }
160 #define AFS_VOP_WRITE(vp,uiop,iof,cr,rv) \
161 {       \
162         BHV_IPREVENT(&(vp)->v_bh);      \
163         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_write)((vp)->v_fbhv,uiop,iof,cr,&(curprocp->p_flid));\
164         BHV_IALLOW(&(vp)->v_bh);        \
165 }
166 #define AFS_VOP_READ(vp,uiop,iof,cr,rv) \
167 {       \
168         BHV_IPREVENT(&(vp)->v_bh);      \
169         rv = (*((vnodeops_t *)(vp)->v_fops)->vop_read)((vp)->v_fbhv,uiop,iof,cr,&(curprocp->p_flid));\
170         BHV_IALLOW(&(vp)->v_bh);        \
171 }
172 #define AFS_VOP_RWLOCK(vp,i) \
173 {       \
174         BHV_IPREVENT(&(vp)->v_bh);      \
175         (void)(*((vnodeops_t *)(vp)->v_fops)->vop_rwlock)((vp)->v_fbhv, i); \
176         /* "allow" is done by rwunlock */       \
177 }
178 #define AFS_VOP_RWUNLOCK(vp,i) \
179 {       /* "prevent" was done by rwlock */    \
180         (void)(*((vnodeops_t *)(vp)->v_fops)->vop_rwunlock)((vp)->v_fbhv, i);\
181         BHV_IALLOW(&(vp)->v_bh);        \
182 }
183
184 /* VOP_RECLAIM remains as is, since it doesn't do the PREVENT/ALLOW */
185
186 #define AFS_VN_OPEN(path, seg, mode, perm, dvp, why) \
187         vn_open((path), (seg), (mode), (perm), (dvp), (why), 0)
188 #else /* AFS_SGI_VNODE_GLUE */
189 #define VFS_STATFS      VFS_STATVFS
190 #ifdef AFS_SGI65_ENV
191 #define AFS_VOP_ATTR_SET VOP_ATTR_SET
192 #define AFS_VOP_ATTR_GET VOP_ATTR_GET
193 #define AFS_VOP_SETATTR  VOP_SETATTR
194 #define AFS_VOP_GETATTR  VOP_GETATTR
195 #define AFS_VOP_REMOVE   VOP_REMOVE
196 #define AFS_VOP_LOOKUP   VOP_LOOKUP
197 #define AFS_VOP_RMDIR    VOP_RMDIR
198 #define AFS_VOP_READ(vp, uiop, iof, cr, code) \
199         VOP_READ((vp), (uiop), (iof), (cr), &curuthread->ut_flid, code)
200 #define AFS_VOP_WRITE(vp, uiop, iof, cr, code) \
201         VOP_WRITE((vp), (uiop), (iof), (cr), &curuthread->ut_flid, code)
202
203 #define AFS_VN_OPEN(path, seg, mode, perm, dvp, why) \
204         vn_open((path), (seg), (mode), (perm), (dvp), (why), 0, NULL)
205 #else
206 #define AFS_VOP_ATTR_SET(dvp, name, attr, size, flags, cred, code) \
207         code = VOP_ATTR_SET((dvp), (name), (attr), (size), (flags), (cred))
208 #define AFS_VOP_ATTR_GET(dvp, name, attr, sizep, flags, cred, code) \
209         code = VOP_ATTR_GET((dvp), (name), (attr), (sizep), (flags), (cred))
210 #define AFS_VOP_SETATTR(vp, vattr, flags, cred, code) \
211         code = VOP_SETATTR((vp), (vattr), (flags), (cred))
212 #define AFS_VOP_GETATTR(vp, vattr, flags, cred, code) \
213         code = VOP_GETATTR((vp), (vattr), (flags), (cred))
214 #define AFS_VOP_REMOVE(dvp, path,  cred, code) \
215         code = VOP_REMOVE((dvp), (path), (cred))
216 #define AFS_VOP_LOOKUP(dvp, name, dvpp, path, flags, rdir, cred, code) \
217         code = VOP_LOOKUP((dvp), (name), (dvpp), (path), (flags), \
218                           (rdir), (cred))
219 #define AFS_VOP_RMDIR(ddvp, path, cdir, cred, code) \
220         code = VOP_RMDIR((ddvp), (path), (cdir), (cred))
221 #define AFS_VOP_READ(vp,uiop,iof,cr,code) \
222         code = VOP_READ((vp), (uiop), (iof), (cr))
223 #define AFS_VOP_WRITE(vp,uiop,iof,cr,code) \
224         code = VOP_WRITE((vp), (uiop), (iof), (cr))
225 #define AFS_VN_OPEN     vn_open
226 #endif /* AFS_SGI65_ENV */
227
228 #define AFS_VOP_RWLOCK(vp, flag)        VOP_RWLOCK((vp), (flag))
229 #define AFS_VOP_RWUNLOCK(vp, flag)      VOP_RWUNLOCK((vp), (flag))
230
231 #endif /* AFS_SGI_VNODE_GLUE */
232 #define devtovfs        vfs_devsearch
233 #define va_blocksize    va_blksize
234 #define va_blocks       va_nblocks
235 #define MAXNAMLEN       256
236
237 /* These macros hide the shape change inthe vnode for sgi_64 w/o NUMA.
238  * They call routines so that if statements do not contain complex
239  * expressions.
240  */
241 #ifdef AFS_SGI_VNODE_GLUE
242 extern int afs_is_numa_arch;
243 typedef struct bhv_head1 {
244         struct bhv_desc *bh_first;      /* first behavior in chain */
245 #ifdef notdef
246         /* This is not present in the non NUMA machines. */
247         mrlock_t        bh_mrlock;      /* lock for ops-in-progress synch. */
248 #endif
249 } bhv_head1_t;
250
251 typedef struct vnode1 {
252         struct vnlist   v_list;                 /* freelist linkage */
253         uint            v_flag;                 /* vnode flags (see below) */
254         cnt_t           v_count;                /* reference count */
255         u_short         v_namecap;              /* name cache capability */
256         enum vtype      v_type;                 /* vnode type */
257         dev_t           v_rdev;                 /* device (VCHR, VBLK) */
258         struct vfs      *v_vfsmountedhere;      /* ptr to vfs mounted here */
259         struct vfs      *v_vfsp;                /* ptr to containing VFS */
260         struct stdata   *v_stream;              /* associated stream */
261         struct filock   *v_filocks;             /* ptr to filock list */
262         mutex_t         *v_filocksem;           /* ptr to mutex for list */
263         vnumber_t       v_number;               /* in-core vnode number */
264         short           v_listid;               /* free list id */
265         cnt_t           v_intpcount;            /* interp. refcount for imon */
266         bhv_head1_t     v_bh;                   /* behavior head */
267
268         /*
269          * Used only by global cache.
270          */
271         struct vnode    *v_hashp;               /* hash list for lookup */
272         struct vnode    *v_hashn;               /* hash list for lookup */
273
274         /*
275          * Values manipulated only by VM and
276          * the page/buffer caches.
277          */
278         struct pregion  *v_mreg;                /* mapped file region pointer */
279         int             v_dbuf;                 /* delwri buffer count */
280         pgno_t          v_pgcnt;                /* pages hashed to vnode */
281         struct pfdat    *v_dpages;              /* delwri pages */
282         struct buf      *v_buf;                 /* vnode buffer tree head */
283         unsigned int    v_bufgen;               /* buf list generation number */
284         mutex_t         v_buf_lock;             /* mutex for buffer tree */
285
286         vnode_pcache_t  v_pc;                   /* Page cache structure. 
287                                                  * per vnode. Refer to
288                                                  * vnode_pcache.h 
289                                                  * for details.
290                                                  */
291 #ifdef VNODE_TRACING
292         struct ktrace   *v_trace;               /* trace header structure    */
293 #endif
294 } vnode1_t;
295
296 extern struct pfdat *vnode_get_dpages(vnode_t*);
297 extern int vnode_get_dbuf(vnode_t*);
298 extern pgno_t vnode_get_pgcnt(vnode_t*);
299 extern struct pregion *vnode_get_mreg(vnode_t*);
300 #define VN_GET_DPAGES(V)        (afs_is_numa_arch ? \
301                                  ((V)->v_dpages) : \
302                                  (((vnode1_t*)(V))->v_dpages))
303 #define VN_SET_DPAGES(V, D)     (afs_is_numa_arch ? \
304                                   ((V)->v_dpages = (D)) : \
305                                  (((vnode1_t*)(V))->v_dpages = (D)))
306 #define VN_GET_DBUF(V)          (afs_is_numa_arch ? \
307                                  ((V)->v_dbuf) : (((vnode1_t*)(V))->v_dbuf))
308 #define VN_GET_PGCNT(V)         (afs_is_numa_arch ? \
309                                  ((V)->v_pgcnt) : (((vnode1_t*)(V))->v_pgcnt))
310 #define VN_GET_MREG(V)          (afs_is_numa_arch ? \
311                                  ((V)->v_mreg) : (((vnode1_t*)(V))->v_mreg))
312 #define AFS_VN_MAPPED(V)        (VN_GET_MREG(V) != NULL)
313 #define AFS_VN_DIRTY(V)         (VN_GET_DBUF(V) || VN_GET_DPAGES(V))
314 #define AFS_VN_INIT_BUF_LOCK(V) \
315         (afs_is_numa_arch ? \
316          init_mutex(&((V)->v_buf_lock), MUTEX_DEFAULT, "vn_buf_lock", \
317                     (long)(V) ) : \
318          init_mutex(&(((vnode1_t*)(V))->v_buf_lock), MUTEX_DEFAULT, \
319                     "vn_buf_lock", \
320                     (long)(V) ))
321 #define AFS_VN_DESTROY_BUF_LOCK(V) \
322         (afs_is_numa_arch ? \
323          mutex_destroy(&((V)->v_buf_lock)) : \
324          mutex_destroy(&(((vnode1_t*)(V))->v_buf_lock)))
325
326 #else
327 #define VN_GET_DPAGES(V)        ((V)->v_dpages)
328 #define VN_SET_DPAGES(V, D)     (V)->v_dpages = (D)
329 #define VN_GET_DBUF(V)          ((V)->v_dbuf)
330 #define VN_GET_PGCNT(V)         ((V)->v_pgcnt)
331 #define VN_GET_MREG(V)          ((V)->v_mreg)
332 #define AFS_VN_MAPPED           VN_MAPPED
333 #define AFS_VN_DIRTY            VN_DIRTY
334 #define AFS_VN_INIT_BUF_LOCK(V) \
335         init_mutex(&((V)->v_buf_lock), MUTEX_DEFAULT, "vn_buf_lock", (long)(V))
336 #define AFS_VN_DESTROY_BUF_LOCK(V)      \
337          mutex_destroy(&((V)->v_buf_lock))
338 #endif /* AFS_SGI_VNODE_GLUE */
339
340 /*
341  * Misc
342  */
343 #define ucred cred
344 #define uprintf printf
345 #define d_fileno d_ino
346
347 #define CLBYTES NBPC
348 /*
349  * Flock(3) call. (from sys/file.h)
350  */
351 #define LOCK_SH         1       /* shared lock */
352 #define LOCK_EX         2       /* exclusive lock */
353 #define LOCK_NB         4       /* don't block when locking */
354 #define LOCK_UN         8       /* unlock */
355
356 #endif
357
358
359 #if defined(AFS_SGI64_ENV) && defined(CKPT)
360 /* This is a fid for checkpoint restart. Note that the length will be
361  * greater than 10 and so afs_vget can distinguish this fid.
362  */
363 typedef struct {
364     u_short af_len;
365     u_short af_cell;
366     u_int af_volid;
367     u_int af_vno;
368     u_int af_uniq;
369 } afs_fid2_t;
370 #endif /* _SGI_VFS_H_ */