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 extern struct osi_dev cacheDev;
22 extern struct vfs *afs_cacheVfsp;
26 osi_UFSOpen(afs_dcache_id_t *ainode)
29 struct osi_file *afile = NULL;
30 struct vnode *vp = NULL;
31 extern int cacheDiskType;
34 AFS_STATCNT(osi_UFSOpen);
35 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
36 osi_Panic("UFSOpen called for non-UFS cache\n");
38 if (!afs_osicred_initialized) {
39 /* valid for SunOS, Ultrix */
40 memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
41 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
42 afs_osicred_initialized = 1;
44 afile = osi_AllocSmallSpace(sizeof(struct osi_file));
47 ip = (struct inode *)igetinode((dev_t) cacheDev.dev, afs_cacheVfsp,
48 (ino_t) ainode->ufs, &vp, &dummy);
51 osi_FreeSmallSpace(afile);
52 osi_Panic("UFSOpen: igetinode failed");
54 afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */
55 afile->size = VTOI(afile->vnode)->i_size;
57 afile->proc = (int (*)())0;
62 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
66 AFS_STATCNT(osi_Stat);
68 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
71 astat->size = tvattr.va_size;
72 astat->mtime = tvattr.va_mtime.tv_sec;
73 astat->atime = tvattr.va_atime.tv_sec;
79 osi_UFSClose(struct osi_file *afile)
81 AFS_STATCNT(osi_Close);
83 /* AIX writes entire data regions at a time when dumping core. We've
84 * seen a 26M write go through the system. When this happens, we run
85 * out of available pages. So, we'll flush the vnode's vm if we're short
90 if (afile->vnode->v_gnode->gn_seg) {
91 /* 524287 is the max number of pages for a file. See test in
94 code = vm_writep(afile->vnode->v_gnode->gn_seg, 0, 524287);
97 AFS_RELE(afile->vnode);
100 osi_FreeSmallSpace(afile);
105 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
107 afs_ucred_t *oldCred;
110 struct osi_stat tstat;
111 afs_int32 mode = FWRITE | FSYNC;
112 AFS_STATCNT(osi_Truncate);
114 /* This routine only shrinks files, and most systems
115 * have very slow truncates, even when the file is already
116 * small enough. Check now and save some time.
118 code = afs_osi_Stat(afile, &tstat);
119 if (code || tstat.size <= asize)
122 * If we're truncating an unopened file to a non-zero length,
123 * we need to bind it to a vm segment
124 * Note that that the binding will actually happen inside
125 * jfs by xix_ftrunc; setting mode to 0 will enable that.
127 if (asize && !VTOGP(afile->vnode)->gn_seg)
130 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t) 0, &afs_osi_cred);
136 osi_DisableAtimes(struct vnode *avp)
138 struct inode *ip = VTOIP(avp);
143 /* Generic read interface */
145 afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
148 afs_ucred_t *oldCred;
152 AFS_STATCNT(osi_Read);
155 * If the osi_file passed in is NULL, panic only if AFS is not shutting
156 * down. No point in crashing when we are already shutting down
159 if (afs_shuttingdown == AFS_RUNNING)
160 osi_Panic("osi_Read called with null param");
166 afile->offset = offset;
168 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
170 #ifdef AFS_64BIT_KERNEL
172 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
173 &afile->offset, AFS_UIOSYS, NULL, &resid);
176 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
177 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
181 code = asize - resid;
182 afile->offset += code;
183 osi_DisableAtimes(afile->vnode);
185 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
186 ICL_TYPE_INT32, code);
188 * To handle periodic low-level EFAULT failures that we've seen with the
189 * Weitek chip; in all observed failed cases a second read succeeded.
191 if ((code == EFAULT) && (cnt1++ < 5)) {
192 afs_stats_cmperf.osiread_efaults++;
203 /* Generic write interface */
205 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
208 afs_ucred_t *oldCred;
211 AFS_STATCNT(osi_Write);
213 osi_Panic("afs_osi_Write called with null param");
215 afile->offset = offset;
216 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
218 #ifdef AFS_64BIT_KERNEL
220 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
221 &afile->offset, AFS_UIOSYS, NULL, &resid);
224 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
225 (off_t) & afile->offset, AFS_UIOSYS, NULL, &resid);
230 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32,
231 asize, ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
232 code = asize - resid;
233 afile->offset += code;
235 afs_Trace3(afs_iclSetp, CM_TRACE_WRITEFAILED, ICL_TYPE_INT32, asize,
236 ICL_TYPE_INT32, resid, ICL_TYPE_INT32, code);
245 (*afile->proc) (afile, code);
251 /* This work should be handled by physstrat in ca/machdep.c.
252 This routine written from the RT NFS port strategy routine.
253 It has been generalized a bit, but should still be pretty clear. */
255 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
257 afs_int32 returnCode;
259 AFS_STATCNT(osi_MapStrategy);
260 returnCode = (*aproc) (bp);
268 shutdown_osifile(void)
270 AFS_STATCNT(shutdown_osifile);
271 if (afs_cold_shutdown) {
272 afs_osicred_initialized = 0;