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 #ifdef AFS_SUN510_ENV
278 code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, &ct);
281 code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
284 MReleaseWriteLock(&afs_xosi);
289 osi_DisableAtimes(struct vnode *avp)
291 if (afs_CacheFSType == AFS_SUN_UFS_CACHE) {
292 struct inode *ip = VTOI(avp);
293 rw_enter(&ip->i_contents, RW_READER);
294 mutex_enter(&ip->i_tlock);
296 mutex_exit(&ip->i_tlock);
297 rw_exit(&ip->i_contents);
302 /* Generic read interface */
304 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
307 struct AFS_UCRED *oldCred;
308 #if defined(AFS_SUN57_ENV)
313 register afs_int32 code;
314 register afs_int32 cnt1 = 0;
315 AFS_STATCNT(osi_Read);
318 * If the osi_file passed in is NULL, panic only if AFS is not shutting
319 * down. No point in crashing when we are already shutting down
322 if (!afs_shuttingdown)
323 osi_Panic("osi_Read called with null param");
329 afile->offset = offset;
332 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
333 AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid);
336 code = asize - resid;
337 afile->offset += code;
338 osi_DisableAtimes(afile->vnode);
340 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
341 ICL_TYPE_INT32, code);
347 /* Generic write interface */
349 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
352 struct AFS_UCRED *oldCred;
353 #if defined(AFS_SUN57_ENV)
358 register afs_int32 code;
359 AFS_STATCNT(osi_Write);
361 osi_Panic("afs_osi_Write called with null param");
363 afile->offset = offset;
366 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
367 afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, &afs_osi_cred,
371 code = asize - resid;
372 afile->offset += code;
377 (*afile->proc) (afile, code);
383 /* This work should be handled by physstrat in ca/machdep.c.
384 This routine written from the RT NFS port strategy routine.
385 It has been generalized a bit, but should still be pretty clear. */
387 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
389 afs_int32 returnCode;
391 AFS_STATCNT(osi_MapStrategy);
392 returnCode = (*aproc) (bp);
400 shutdown_osifile(void)
402 extern int afs_cold_shutdown;
404 AFS_STATCNT(shutdown_osifile);
405 if (afs_cold_shutdown) {
406 afs_osicred_initialized = 0;