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 "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
15 int afs_osicred_initialized=0;
16 struct AFS_UCRED afs_osi_cred;
17 afs_lock_t afs_xosi; /* lock is for tvattr */
18 extern struct osi_dev cacheDev;
19 extern struct vfs *afs_cacheVfsp;
22 /* As of 6.2, we support either XFS or EFS clients. osi_UFSOpen
23 * now vectors to the correct EFS or XFS function. If new functionality is
24 * added which accesses the inode, that will also need EFS/XFS variants.
26 #ifdef AFS_SGI_EFS_IOPS_ENV
27 vnode_t *afs_EFSIGetVnode(ino_t ainode)
32 if ((error = igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
33 osi_Panic("afs_EFSIGetVnode: igetinode failed, error=%d", error);
35 /* We don't care about atimes on the cache files, so disable them. I'm not
36 * sure that this is the right place to do this: it should be *after* readi
37 * and getattr and stuff.
39 ip->i_flags &= ~(ISYN|IACC);
41 return (EFS_ITOV(ip));
43 #endif /* AFS_SGI_EFS_IOPS_ENV */
45 vnode_t *afs_XFSIGetVnode(ino_t ainode)
52 xfs_igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
53 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error);
59 /* Force to 64 bits, even for EFS filesystems. */
60 void *osi_UFSOpen(ino_t ainode)
63 register struct osi_file *afile = NULL;
64 extern int cacheDiskType;
67 AFS_STATCNT(osi_UFSOpen);
68 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
69 osi_Panic("UFSOpen called for non-UFS cache\n");
71 if (!afs_osicred_initialized) {
72 /* valid for alpha_osf, SunOS, Ultrix */
73 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
74 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
75 afs_osicred_initialized = 1;
77 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
79 afile->vnode = AFS_SGI_IGETVNODE(ainode);
81 afile->size = VnodeToSize(afile->vnode);
83 afile->proc = (int (*)()) 0;
84 afile->inum = ainode; /* for hint validity checking */
88 afs_osi_Stat(afile, astat)
89 register struct osi_file *afile;
90 register struct osi_stat *astat; {
91 register afs_int32 code;
93 AFS_STATCNT(osi_Stat);
94 MObtainWriteLock(&afs_xosi,320);
96 tvattr.va_mask = AT_SIZE|AT_BLKSIZE|AT_MTIME|AT_ATIME;
97 AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
100 astat->size = tvattr.va_size;
101 astat->blksize = tvattr.va_blocksize;
102 astat->mtime = tvattr.va_mtime.tv_sec;
103 astat->atime = tvattr.va_atime.tv_sec;
105 MReleaseWriteLock(&afs_xosi);
110 register struct osi_file *afile;
112 AFS_STATCNT(osi_Close);
114 VN_RELE(afile->vnode);
117 osi_FreeSmallSpace(afile);
121 osi_UFSTruncate(afile, asize)
122 register struct osi_file *afile;
124 struct AFS_UCRED *oldCred;
126 register afs_int32 code;
127 struct osi_stat tstat;
129 AFS_STATCNT(osi_Truncate);
131 /* This routine only shrinks files, and most systems
132 * have very slow truncates, even when the file is already
133 * small enough. Check now and save some time.
135 code = afs_osi_Stat(afile, &tstat);
136 if (code || tstat.size <= asize) return code;
137 MObtainWriteLock(&afs_xosi,321);
139 tvattr.va_mask = AT_SIZE;
140 tvattr.va_size = asize;
141 AFS_VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
143 MReleaseWriteLock(&afs_xosi);
147 #ifdef AFS_SGI_EFS_IOPS_ENV
148 void osi_DisableAtimes(avp)
151 if (afs_CacheFSType == AFS_SGI_EFS_CACHE)
153 struct inode *ip = EFS_VTOI(avp);
154 ip->i_flags &= ~IACC;
158 #endif /* AFS_SGI_EFS_IOPS_ENV */
161 /* Generic read interface */
162 afs_osi_Read(afile, offset, aptr, asize)
163 register struct osi_file *afile;
167 struct AFS_UCRED *oldCred;
169 register afs_int32 code;
170 register afs_int32 cnt1=0;
171 AFS_STATCNT(osi_Read);
174 * If the osi_file passed in is NULL, panic only if AFS is not shutting
175 * down. No point in crashing when we are already shutting down
178 if ( !afs_shuttingdown )
179 osi_Panic("osi_Read called with null param");
184 if (offset != -1) afile->offset = offset;
186 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
187 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
190 code = asize - resid;
191 afile->offset += code;
192 #ifdef AFS_SGI_EFS_IOPS_ENV
193 osi_DisableAtimes(afile->vnode);
194 #endif /* AFS_SGI_EFS_IOPS_ENV */
197 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
198 ICL_TYPE_INT32, code);
204 /* Generic write interface */
205 afs_osi_Write(afile, offset, aptr, asize)
206 register struct osi_file *afile;
210 struct AFS_UCRED *oldCred;
212 register afs_int32 code;
213 AFS_STATCNT(osi_Write);
215 osi_Panic("afs_osi_Write called with null param");
216 if (offset != -1) afile->offset = offset;
218 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
219 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
222 code = asize - resid;
223 afile->offset += code;
226 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
230 (*afile->proc)(afile, code);
236 /* This work should be handled by physstrat in ca/machdep.c.
237 This routine written from the RT NFS port strategy routine.
238 It has been generalized a bit, but should still be pretty clear. */
239 int afs_osi_MapStrategy(aproc, bp)
241 register struct buf *bp;
243 afs_int32 returnCode;
245 AFS_STATCNT(osi_MapStrategy);
246 returnCode = (*aproc) (bp);
256 extern int afs_cold_shutdown;
258 AFS_STATCNT(shutdown_osifile);
259 if (afs_cold_shutdown) {
260 afs_osicred_initialized = 0;