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((char *)&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;
59 afile->inum = ainode->ufs; /* for hint validity checking */
64 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
66 register afs_int32 code;
68 AFS_STATCNT(osi_Stat);
69 MObtainWriteLock(&afs_xosi, 320);
71 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
74 astat->size = tvattr.va_size;
75 astat->mtime = tvattr.va_mtime.tv_sec;
76 astat->atime = tvattr.va_atime.tv_sec;
78 MReleaseWriteLock(&afs_xosi);
83 osi_UFSClose(register struct osi_file *afile)
85 AFS_STATCNT(osi_Close);
87 /* AIX writes entire data regions at a time when dumping core. We've
88 * seen a 26M write go through the system. When this happens, we run
89 * out of available pages. So, we'll flush the vnode's vm if we're short
94 if (afile->vnode->v_gnode->gn_seg) {
95 /* 524287 is the max number of pages for a file. See test in
98 code = vm_writep(afile->vnode->v_gnode->gn_seg, 0, 524287);
101 AFS_RELE(afile->vnode);
104 osi_FreeSmallSpace(afile);
109 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
111 afs_ucred_t *oldCred;
113 register afs_int32 code;
114 struct osi_stat tstat;
115 afs_int32 mode = FWRITE | FSYNC;
116 AFS_STATCNT(osi_Truncate);
118 /* This routine only shrinks files, and most systems
119 * have very slow truncates, even when the file is already
120 * small enough. Check now and save some time.
122 code = afs_osi_Stat(afile, &tstat);
123 if (code || tstat.size <= asize)
125 MObtainWriteLock(&afs_xosi, 321);
127 * If we're truncating an unopened file to a non-zero length,
128 * we need to bind it to a vm segment
129 * Note that that the binding will actually happen inside
130 * jfs by xix_ftrunc; setting mode to 0 will enable that.
132 if (asize && !VTOGP(afile->vnode)->gn_seg)
135 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t) 0, &afs_osi_cred);
137 MReleaseWriteLock(&afs_xosi);
142 osi_DisableAtimes(struct vnode *avp)
144 struct inode *ip = VTOIP(avp);
149 /* Generic read interface */
151 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
154 afs_ucred_t *oldCred;
156 register afs_int32 code;
157 register afs_int32 cnt1 = 0;
158 AFS_STATCNT(osi_Read);
161 * If the osi_file passed in is NULL, panic only if AFS is not shutting
162 * down. No point in crashing when we are already shutting down
165 if (!afs_shuttingdown)
166 osi_Panic("osi_Read called with null param");
172 afile->offset = offset;
174 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
176 #ifdef AFS_64BIT_KERNEL
178 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
179 &afile->offset, AFS_UIOSYS, NULL, &resid);
182 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
183 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
187 code = asize - resid;
188 afile->offset += code;
189 osi_DisableAtimes(afile->vnode);
191 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
192 ICL_TYPE_INT32, code);
194 * To handle periodic low-level EFAULT failures that we've seen with the
195 * Weitek chip; in all observed failed cases a second read succeeded.
197 if ((code == EFAULT) && (cnt1++ < 5)) {
198 afs_stats_cmperf.osiread_efaults++;
207 /* Generic write interface */
209 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
212 afs_ucred_t *oldCred;
214 register afs_int32 code;
215 AFS_STATCNT(osi_Write);
217 osi_Panic("afs_osi_Write called with null param");
219 afile->offset = offset;
220 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
222 #ifdef AFS_64BIT_KERNEL
224 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
225 &afile->offset, AFS_UIOSYS, NULL, &resid);
228 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
229 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
234 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32,
235 asize, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
236 code = asize - resid;
237 afile->offset += code;
239 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, asize,
240 ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
243 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
248 (*afile->proc) (afile, code);
254 /* This work should be handled by physstrat in ca/machdep.c.
255 This routine written from the RT NFS port strategy routine.
256 It has been generalized a bit, but should still be pretty clear. */
258 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
260 afs_int32 returnCode;
262 AFS_STATCNT(osi_MapStrategy);
263 returnCode = (*aproc) (bp);
271 shutdown_osifile(void)
273 AFS_STATCNT(shutdown_osifile);
274 if (afs_cold_shutdown) {
275 afs_osicred_initialized = 0;