2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
19 #include "afs/osi_inode.h"
22 int afs_osicred_initialized = 0;
23 struct AFS_UCRED afs_osi_cred;
24 afs_lock_t afs_xosi; /* lock is for tvattr */
25 extern struct osi_dev cacheDev;
26 extern struct vfs *afs_cacheVfsp;
31 /* Support for UFS and VXFS caches. The assumption here is that the size of
32 * a cache file also does not exceed 32 bits.
35 /* Initialized in osi_InitCacheFSType(). Used to determine inode type. */
36 int afs_CacheFSType = -1;
38 /* pointer to VXFS routine to access vnodes by inode number */
39 int (*vxfs_vx_vp_byino) ();
41 /* Initialize the cache operations. Called while initializing cache files. */
43 afs_InitDualFSCacheOps(struct vnode *vp)
46 static int inited = 0;
49 struct statvfs64 vfst;
50 #else /* AFS_SUN56_ENV */
52 #endif /* AFS_SUN56_ENV */
63 osi_Panic("afs_InitDualFSCacheOps: vp->v_vfsp is NULL");
64 code = VFS_STATVFS(vfsp, &vfst);
66 osi_Panic("afs_InitDualFSCacheOps: statvfs failed");
68 if (strcmp(vfst.f_basetype, "vxfs") == 0) {
69 vxfs_vx_vp_byino = (int (*)())modlookup("vxfs", "vx_vp_byino");
70 if (vxfs_vx_vp_byino == NULL)
72 ("afs_InitDualFSCacheOps: modlookup(vx_vp_byino) failed");
74 afs_CacheFSType = AFS_SUN_VXFS_CACHE;
78 afs_CacheFSType = AFS_SUN_UFS_CACHE;
83 VnodeToIno(vnode_t * vp)
88 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
89 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
91 osi_Panic("VnodeToIno");
93 return vattr.va_nodeid;
97 VnodeToDev(vnode_t * vp)
102 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
104 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
107 osi_Panic("VnodeToDev");
109 return (dev_t) vattr.va_fsid;
113 VnodeToSize(vnode_t * vp)
119 * We lock xosi in osi_Stat, so we probably should
120 * lock it here too - RWH.
122 MObtainWriteLock(&afs_xosi, 578);
123 vattr.va_mask = AT_SIZE;
125 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
128 osi_Panic("VnodeToSize");
130 MReleaseWriteLock(&afs_xosi);
131 return (afs_int32) (vattr.va_size);
135 osi_VxfsOpen(afs_int32 ainode)
138 register struct osi_file *afile = NULL;
141 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
143 code = (*vxfs_vx_vp_byino) (afs_cacheVfsp, &vp, (unsigned int)ainode);
146 osi_FreeSmallSpace(afile);
147 osi_Panic("VxfsOpen: vx_vp_byino failed");
150 afile->size = VnodeToSize(afile->vnode);
152 afile->proc = (int (*)())0;
153 afile->inum = ainode; /* for hint validity checking */
154 return (void *)afile;
156 #endif /* AFS_HAVE_VXFS */
158 #if defined(AFS_SUN57_64BIT_ENV)
160 osi_UfsOpen(ino_t ainode)
163 osi_UfsOpen(afs_int32 ainode)
167 register struct osi_file *afile = NULL;
170 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
173 igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
177 osi_FreeSmallSpace(afile);
178 osi_Panic("UfsOpen: igetinode failed");
180 afile->vnode = ITOV(ip);
181 afile->size = VTOI(afile->vnode)->i_size;
183 afile->proc = (int (*)())0;
184 afile->inum = ainode; /* for hint validity checking */
185 return (void *)afile;
189 * In Solaris 7 we use 64 bit inode numbers
191 #if defined(AFS_SUN57_64BIT_ENV)
193 osi_UFSOpen(ino_t ainode)
196 osi_UFSOpen(afs_int32 ainode)
199 extern int cacheDiskType;
200 AFS_STATCNT(osi_UFSOpen);
201 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
202 osi_Panic("UFSOpen called for non-UFS cache\n");
204 if (!afs_osicred_initialized) {
205 /* valid for alpha_osf, SunOS, Ultrix */
206 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
207 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
208 afs_osicred_initialized = 1;
211 if (afs_CacheFSType == AFS_SUN_VXFS_CACHE)
212 return osi_VxfsOpen(ainode);
214 return osi_UfsOpen(ainode);
218 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
220 register afs_int32 code;
222 AFS_STATCNT(osi_Stat);
223 MObtainWriteLock(&afs_xosi, 320);
224 /* Ufs doesn't seem to care about the flags so we pass 0 for now */
225 tvattr.va_mask = AT_ALL;
227 code = VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
230 astat->size = tvattr.va_size;
231 astat->blksize = tvattr.va_blksize;
232 astat->mtime = tvattr.va_mtime.tv_sec;
233 astat->atime = tvattr.va_atime.tv_sec;
235 MReleaseWriteLock(&afs_xosi);
240 osi_UFSClose(register struct osi_file *afile)
242 AFS_STATCNT(osi_Close);
244 AFS_RELE(afile->vnode);
247 osi_FreeSmallSpace(afile);
252 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
254 struct AFS_UCRED *oldCred;
256 register afs_int32 code;
257 struct osi_stat tstat;
258 AFS_STATCNT(osi_Truncate);
260 /* This routine only shrinks files, and most systems
261 * have very slow truncates, even when the file is already
262 * small enough. Check now and save some time.
264 code = afs_osi_Stat(afile, &tstat);
265 if (code || tstat.size <= asize)
267 MObtainWriteLock(&afs_xosi, 321);
268 tvattr.va_mask = AT_SIZE;
269 tvattr.va_size = asize;
271 * The only time a flag is used (ATTR_UTIME) is when we're changing the time
274 code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
276 MReleaseWriteLock(&afs_xosi);
281 osi_DisableAtimes(struct vnode *avp)
283 if (afs_CacheFSType == AFS_SUN_UFS_CACHE) {
284 struct inode *ip = VTOI(avp);
285 rw_enter(&ip->i_contents, RW_READER);
286 mutex_enter(&ip->i_tlock);
288 mutex_exit(&ip->i_tlock);
289 rw_exit(&ip->i_contents);
294 /* Generic read interface */
296 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
299 struct AFS_UCRED *oldCred;
300 #if defined(AFS_SUN57_ENV)
305 register afs_int32 code;
306 register afs_int32 cnt1 = 0;
307 AFS_STATCNT(osi_Read);
310 * If the osi_file passed in is NULL, panic only if AFS is not shutting
311 * down. No point in crashing when we are already shutting down
314 if (!afs_shuttingdown)
315 osi_Panic("osi_Read called with null param");
321 afile->offset = offset;
324 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
325 AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid);
328 code = asize - resid;
329 afile->offset += code;
330 osi_DisableAtimes(afile->vnode);
332 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
333 ICL_TYPE_INT32, code);
339 /* Generic write interface */
341 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
344 struct AFS_UCRED *oldCred;
345 #if defined(AFS_SUN57_ENV)
350 register afs_int32 code;
351 AFS_STATCNT(osi_Write);
353 osi_Panic("afs_osi_Write called with null param");
355 afile->offset = offset;
358 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
359 afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, &afs_osi_cred,
363 code = asize - resid;
364 afile->offset += code;
369 (*afile->proc) (afile, code);
375 /* This work should be handled by physstrat in ca/machdep.c.
376 This routine written from the RT NFS port strategy routine.
377 It has been generalized a bit, but should still be pretty clear. */
379 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
381 afs_int32 returnCode;
383 AFS_STATCNT(osi_MapStrategy);
384 returnCode = (*aproc) (bp);
392 shutdown_osifile(void)
394 extern int afs_cold_shutdown;
396 AFS_STATCNT(shutdown_osifile);
397 if (afs_cold_shutdown) {
398 afs_osicred_initialized = 0;