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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
21 int afs_osicred_initialized = 0;
22 struct AFS_UCRED afs_osi_cred;
23 afs_lock_t afs_xosi; /* lock is for tvattr */
24 extern struct osi_dev cacheDev;
25 extern struct vfs *afs_cacheVfsp;
29 osi_UFSOpen(afs_dcache_id_t *ainode)
32 register struct osi_file *afile = NULL;
33 struct vnode *vp = NULL;
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, afs_cacheVfsp,
51 (ino_t) ainode->ufs, &vp, &dummy);
54 osi_FreeSmallSpace(afile);
55 osi_Panic("UFSOpen: igetinode failed");
57 afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */
58 afile->size = VTOI(afile->vnode)->i_size;
60 afile->proc = (int (*)())0;
61 afile->inum = ainode->ufs; /* for hint validity checking */
66 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
68 register afs_int32 code;
70 AFS_STATCNT(osi_Stat);
71 MObtainWriteLock(&afs_xosi, 320);
73 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
76 astat->size = tvattr.va_size;
77 astat->mtime = tvattr.va_mtime.tv_sec;
78 astat->atime = tvattr.va_atime.tv_sec;
80 MReleaseWriteLock(&afs_xosi);
85 osi_UFSClose(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);
111 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
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)
127 MObtainWriteLock(&afs_xosi, 321);
129 * If we're truncating an unopened file to a non-zero length,
130 * we need to bind it to a vm segment
131 * Note that that the binding will actually happen inside
132 * jfs by xix_ftrunc; setting mode to 0 will enable that.
134 if (asize && !VTOGP(afile->vnode)->gn_seg)
137 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t) 0, &afs_osi_cred);
139 MReleaseWriteLock(&afs_xosi);
144 osi_DisableAtimes(struct vnode *avp)
146 struct inode *ip = VTOIP(avp);
151 /* Generic read interface */
153 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
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");
174 afile->offset = offset;
176 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
178 #ifdef AFS_64BIT_KERNEL
180 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
181 &afile->offset, AFS_UIOSYS, NULL, &resid);
184 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
185 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
189 code = asize - resid;
190 afile->offset += code;
191 osi_DisableAtimes(afile->vnode);
193 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
194 ICL_TYPE_INT32, code);
196 * To handle periodic low-level EFAULT failures that we've seen with the
197 * Weitek chip; in all observed failed cases a second read succeeded.
199 if ((code == EFAULT) && (cnt1++ < 5)) {
200 afs_stats_cmperf.osiread_efaults++;
209 /* Generic write interface */
211 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
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");
221 afile->offset = offset;
222 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
224 #ifdef AFS_64BIT_KERNEL
226 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
227 &afile->offset, AFS_UIOSYS, NULL, &resid);
230 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
231 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
236 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32,
237 asize, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
238 code = asize - resid;
239 afile->offset += code;
241 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, asize,
242 ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
245 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
250 (*afile->proc) (afile, code);
256 /* This work should be handled by physstrat in ca/machdep.c.
257 This routine written from the RT NFS port strategy routine.
258 It has been generalized a bit, but should still be pretty clear. */
260 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
262 afs_int32 returnCode;
264 AFS_STATCNT(osi_MapStrategy);
265 returnCode = (*aproc) (bp);
273 shutdown_osifile(void)
275 AFS_STATCNT(shutdown_osifile);
276 if (afs_cold_shutdown) {
277 afs_osicred_initialized = 0;