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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized = 0;
20 afs_ucred_t 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;
27 osi_UFSOpen(afs_dcache_id_t *ainode)
30 register struct osi_file *afile = NULL;
31 struct vnode *vp = NULL;
32 extern int cacheDiskType;
35 AFS_STATCNT(osi_UFSOpen);
36 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
37 osi_Panic("UFSOpen called for non-UFS cache\n");
39 if (!afs_osicred_initialized) {
40 /* valid for alpha_osf, SunOS, Ultrix */
41 memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
42 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
43 afs_osicred_initialized = 1;
45 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
48 ip = (struct inode *)igetinode((dev_t) cacheDev.dev, afs_cacheVfsp,
49 (ino_t) ainode->ufs, &vp, &dummy);
52 osi_FreeSmallSpace(afile);
53 osi_Panic("UFSOpen: igetinode failed");
55 afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */
56 afile->size = VTOI(afile->vnode)->i_size;
58 afile->proc = (int (*)())0;
63 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
65 register afs_int32 code;
67 AFS_STATCNT(osi_Stat);
68 ObtainWriteLock(&afs_xosi, 320);
70 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
73 astat->size = tvattr.va_size;
74 astat->mtime = tvattr.va_mtime.tv_sec;
75 astat->atime = tvattr.va_atime.tv_sec;
77 ReleaseWriteLock(&afs_xosi);
82 osi_UFSClose(register struct osi_file *afile)
84 AFS_STATCNT(osi_Close);
86 /* AIX writes entire data regions at a time when dumping core. We've
87 * seen a 26M write go through the system. When this happens, we run
88 * out of available pages. So, we'll flush the vnode's vm if we're short
93 if (afile->vnode->v_gnode->gn_seg) {
94 /* 524287 is the max number of pages for a file. See test in
97 code = vm_writep(afile->vnode->v_gnode->gn_seg, 0, 524287);
100 AFS_RELE(afile->vnode);
103 osi_FreeSmallSpace(afile);
108 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
110 afs_ucred_t *oldCred;
112 register afs_int32 code;
113 struct osi_stat tstat;
114 afs_int32 mode = FWRITE | FSYNC;
115 AFS_STATCNT(osi_Truncate);
117 /* This routine only shrinks files, and most systems
118 * have very slow truncates, even when the file is already
119 * small enough. Check now and save some time.
121 code = afs_osi_Stat(afile, &tstat);
122 if (code || tstat.size <= asize)
124 ObtainWriteLock(&afs_xosi, 321);
126 * If we're truncating an unopened file to a non-zero length,
127 * we need to bind it to a vm segment
128 * Note that that the binding will actually happen inside
129 * jfs by xix_ftrunc; setting mode to 0 will enable that.
131 if (asize && !VTOGP(afile->vnode)->gn_seg)
134 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t) 0, &afs_osi_cred);
136 ReleaseWriteLock(&afs_xosi);
141 osi_DisableAtimes(struct vnode *avp)
143 struct inode *ip = VTOIP(avp);
148 /* Generic read interface */
150 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
153 afs_ucred_t *oldCred;
155 register afs_int32 code;
156 register afs_int32 cnt1 = 0;
157 AFS_STATCNT(osi_Read);
160 * If the osi_file passed in is NULL, panic only if AFS is not shutting
161 * down. No point in crashing when we are already shutting down
164 if (!afs_shuttingdown)
165 osi_Panic("osi_Read called with null param");
171 afile->offset = offset;
173 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
175 #ifdef AFS_64BIT_KERNEL
177 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
178 &afile->offset, AFS_UIOSYS, NULL, &resid);
181 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
182 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
186 code = asize - resid;
187 afile->offset += code;
188 osi_DisableAtimes(afile->vnode);
190 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
191 ICL_TYPE_INT32, code);
193 * To handle periodic low-level EFAULT failures that we've seen with the
194 * Weitek chip; in all observed failed cases a second read succeeded.
196 if ((code == EFAULT) && (cnt1++ < 5)) {
197 afs_stats_cmperf.osiread_efaults++;
206 /* Generic write interface */
208 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
211 afs_ucred_t *oldCred;
213 register afs_int32 code;
214 AFS_STATCNT(osi_Write);
216 osi_Panic("afs_osi_Write called with null param");
218 afile->offset = offset;
219 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
221 #ifdef AFS_64BIT_KERNEL
223 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
224 &afile->offset, AFS_UIOSYS, NULL, &resid);
227 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
228 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
233 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32,
234 asize, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
235 code = asize - resid;
236 afile->offset += code;
238 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, asize,
239 ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
242 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
247 (*afile->proc) (afile, code);
253 /* This work should be handled by physstrat in ca/machdep.c.
254 This routine written from the RT NFS port strategy routine.
255 It has been generalized a bit, but should still be pretty clear. */
257 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
259 afs_int32 returnCode;
261 AFS_STATCNT(osi_MapStrategy);
262 returnCode = (*aproc) (bp);
270 shutdown_osifile(void)
272 AFS_STATCNT(shutdown_osifile);
273 if (afs_cold_shutdown) {
274 afs_osicred_initialized = 0;