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"
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 */
20 int afs_osicred_initialized=0;
21 struct AFS_UCRED afs_osi_cred;
22 afs_lock_t afs_xosi; /* lock is for tvattr */
23 extern struct osi_dev cacheDev;
24 extern struct vfs *afs_cacheVfsp;
27 void *osi_UFSOpen(ainode)
31 register struct osi_file *afile = NULL;
32 extern struct vfs *rootvfs;
33 struct vnode *vp = (struct vnode *)0;
34 extern int cacheDiskType;
37 AFS_STATCNT(osi_UFSOpen);
38 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
39 osi_Panic("UFSOpen called for non-UFS cache\n");
41 if (!afs_osicred_initialized) {
42 /* valid for alpha_osf, SunOS, Ultrix */
43 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
44 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
45 afs_osicred_initialized = 1;
47 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
50 ip = (struct inode *) igetinode((dev_t) cacheDev.dev, rootvfs, (ino_t)ainode, &vp,&dummy);
53 osi_FreeSmallSpace(afile);
54 osi_Panic("UFSOpen: igetinode failed");
56 afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */
57 afile->size = VTOI(afile->vnode)->i_size;
59 afile->proc = (int (*)()) 0;
60 afile->inum = ainode; /* for hint validity checking */
64 afs_osi_Stat(afile, astat)
65 register struct osi_file *afile;
66 register struct osi_stat *astat; {
67 register afs_int32 code;
69 AFS_STATCNT(osi_Stat);
70 MObtainWriteLock(&afs_xosi,320);
72 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
75 astat->size = tvattr.va_size;
76 astat->blksize = tvattr.va_blocksize;
77 astat->mtime = tvattr.va_mtime.tv_sec;
78 astat->atime = tvattr.va_atime.tv_sec;
80 MReleaseWriteLock(&afs_xosi);
85 register struct osi_file *afile;
87 AFS_STATCNT(osi_Close);
89 /* AIX writes entire data regions at a time when dumping core. We've
90 * seen a 26M write go through the system. When this happens, we run
91 * out of available pages. So, we'll flush the vnode's vm if we're short
96 if (afile->vnode->v_gnode->gn_seg) {
97 /* 524287 is the max number of pages for a file. See test in
100 code = vm_writep(afile->vnode->v_gnode->gn_seg, 0, 524287);
103 AFS_RELE(afile->vnode);
106 osi_FreeSmallSpace(afile);
110 osi_UFSTruncate(afile, asize)
111 register struct osi_file *afile;
113 struct AFS_UCRED *oldCred;
115 register afs_int32 code;
116 struct osi_stat tstat;
117 afs_int32 mode=FWRITE|FSYNC;
118 AFS_STATCNT(osi_Truncate);
120 /* This routine only shrinks files, and most systems
121 * have very slow truncates, even when the file is already
122 * small enough. Check now and save some time.
124 code = afs_osi_Stat(afile, &tstat);
125 if (code || tstat.size <= asize) return code;
126 MObtainWriteLock(&afs_xosi,321);
128 * If we're truncating an unopened file to a non-zero length,
129 * we need to bind it to a vm segment
130 * Note that that the binding will actually happen inside
131 * jfs by xix_ftrunc; setting mode to 0 will enable that.
133 if (asize && !VTOGP(afile->vnode)->gn_seg)
136 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t)0, &afs_osi_cred);
138 MReleaseWriteLock(&afs_xosi);
142 void osi_DisableAtimes(avp)
145 struct inode *ip = VTOIP(avp);
150 /* Generic read interface */
151 afs_osi_Read(afile, offset, aptr, asize)
152 register struct osi_file *afile;
156 struct AFS_UCRED *oldCred;
158 register afs_int32 code;
159 register afs_int32 cnt1=0;
160 AFS_STATCNT(osi_Read);
163 * If the osi_file passed in is NULL, panic only if AFS is not shutting
164 * down. No point in crashing when we are already shutting down
167 if ( !afs_shuttingdown )
168 osi_Panic("osi_Read called with null param");
173 if (offset != -1) afile->offset = offset;
175 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
177 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
178 (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid);
181 code = asize - resid;
182 afile->offset += code;
183 osi_DisableAtimes(afile->vnode);
186 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
187 ICL_TYPE_INT32, code);
189 * To handle periodic low-level EFAULT failures that we've seen with the
190 * Weitek chip; in all observed failed cases a second read succeeded.
192 if ((code == EFAULT) && (cnt1++ < 5)) {
193 afs_stats_cmperf.osiread_efaults++;
202 /* Generic write interface */
203 afs_osi_Write(afile, offset, aptr, asize)
204 register struct osi_file *afile;
208 struct AFS_UCRED *oldCred;
210 register afs_int32 code;
211 AFS_STATCNT(osi_Write);
213 osi_Panic("afs_osi_Write called with null param");
214 if (offset != -1) afile->offset = offset;
215 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
217 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
218 (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid);
221 code = asize - resid;
222 afile->offset += code;
225 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;