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 "../afs/param.h" /* Should be always first */
11 #include <afsconfig.h>
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized=0;
20 struct AFS_UCRED afs_osi_cred;
21 afs_lock_t afs_xosi; /* lock is for tvattr */
22 extern struct osi_dev cacheDev;
23 extern struct vfs *afs_cacheVfsp;
26 /* As of 6.2, we support either XFS or EFS clients. osi_UFSOpen
27 * now vectors to the correct EFS or XFS function. If new functionality is
28 * added which accesses the inode, that will also need EFS/XFS variants.
30 #ifdef AFS_SGI_EFS_IOPS_ENV
31 vnode_t *afs_EFSIGetVnode(ino_t ainode)
36 if ((error = igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
37 osi_Panic("afs_EFSIGetVnode: igetinode failed, error=%d", error);
39 /* We don't care about atimes on the cache files, so disable them. I'm not
40 * sure that this is the right place to do this: it should be *after* readi
41 * and getattr and stuff.
43 ip->i_flags &= ~(ISYN|IACC);
45 return (EFS_ITOV(ip));
47 #endif /* AFS_SGI_EFS_IOPS_ENV */
49 vnode_t *afs_XFSIGetVnode(ino_t ainode)
56 xfs_igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
57 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error);
63 /* Force to 64 bits, even for EFS filesystems. */
64 void *osi_UFSOpen(ino_t ainode)
67 register struct osi_file *afile = NULL;
68 extern int cacheDiskType;
71 AFS_STATCNT(osi_UFSOpen);
72 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
73 osi_Panic("UFSOpen called for non-UFS cache\n");
75 if (!afs_osicred_initialized) {
76 /* valid for alpha_osf, SunOS, Ultrix */
77 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
78 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
79 afs_osicred_initialized = 1;
81 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
83 afile->vnode = AFS_SGI_IGETVNODE(ainode);
85 afile->size = VnodeToSize(afile->vnode);
87 afile->proc = (int (*)()) 0;
88 afile->inum = ainode; /* for hint validity checking */
92 afs_osi_Stat(afile, astat)
93 register struct osi_file *afile;
94 register struct osi_stat *astat; {
95 register afs_int32 code;
97 AFS_STATCNT(osi_Stat);
98 MObtainWriteLock(&afs_xosi,320);
100 tvattr.va_mask = AT_SIZE|AT_BLKSIZE|AT_MTIME|AT_ATIME;
101 AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
104 astat->size = tvattr.va_size;
105 astat->blksize = tvattr.va_blocksize;
106 astat->mtime = tvattr.va_mtime.tv_sec;
107 astat->atime = tvattr.va_atime.tv_sec;
109 MReleaseWriteLock(&afs_xosi);
114 register struct osi_file *afile;
116 AFS_STATCNT(osi_Close);
118 VN_RELE(afile->vnode);
121 osi_FreeSmallSpace(afile);
125 osi_UFSTruncate(afile, asize)
126 register struct osi_file *afile;
128 struct AFS_UCRED *oldCred;
130 register afs_int32 code;
131 struct osi_stat tstat;
133 AFS_STATCNT(osi_Truncate);
135 /* This routine only shrinks files, and most systems
136 * have very slow truncates, even when the file is already
137 * small enough. Check now and save some time.
139 code = afs_osi_Stat(afile, &tstat);
140 if (code || tstat.size <= asize) return code;
141 MObtainWriteLock(&afs_xosi,321);
143 tvattr.va_mask = AT_SIZE;
144 tvattr.va_size = asize;
145 AFS_VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
147 MReleaseWriteLock(&afs_xosi);
151 #ifdef AFS_SGI_EFS_IOPS_ENV
152 void osi_DisableAtimes(avp)
155 if (afs_CacheFSType == AFS_SGI_EFS_CACHE)
157 struct inode *ip = EFS_VTOI(avp);
158 ip->i_flags &= ~IACC;
162 #endif /* AFS_SGI_EFS_IOPS_ENV */
165 /* Generic read interface */
166 afs_osi_Read(afile, offset, aptr, asize)
167 register struct osi_file *afile;
171 struct AFS_UCRED *oldCred;
173 register afs_int32 code;
174 register afs_int32 cnt1=0;
175 AFS_STATCNT(osi_Read);
178 * If the osi_file passed in is NULL, panic only if AFS is not shutting
179 * down. No point in crashing when we are already shutting down
182 if ( !afs_shuttingdown )
183 osi_Panic("osi_Read called with null param");
188 if (offset != -1) afile->offset = offset;
190 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
191 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
194 code = asize - resid;
195 afile->offset += code;
196 #ifdef AFS_SGI_EFS_IOPS_ENV
197 osi_DisableAtimes(afile->vnode);
198 #endif /* AFS_SGI_EFS_IOPS_ENV */
201 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
202 ICL_TYPE_INT32, code);
208 /* Generic write interface */
209 afs_osi_Write(afile, offset, aptr, asize)
210 register struct osi_file *afile;
214 struct AFS_UCRED *oldCred;
216 register afs_int32 code;
217 AFS_STATCNT(osi_Write);
219 osi_Panic("afs_osi_Write called with null param");
220 if (offset != -1) afile->offset = offset;
222 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
223 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
226 code = asize - resid;
227 afile->offset += code;
230 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
234 (*afile->proc)(afile, code);
240 /* This work should be handled by physstrat in ca/machdep.c.
241 This routine written from the RT NFS port strategy routine.
242 It has been generalized a bit, but should still be pretty clear. */
243 int afs_osi_MapStrategy(aproc, bp)
245 register struct buf *bp;
247 afs_int32 returnCode;
249 AFS_STATCNT(osi_MapStrategy);
250 returnCode = (*aproc) (bp);
260 extern int afs_cold_shutdown;
262 AFS_STATCNT(shutdown_osifile);
263 if (afs_cold_shutdown) {
264 afs_osicred_initialized = 0;