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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
16 int afs_osicred_initialized=0;
17 struct AFS_UCRED afs_osi_cred;
18 afs_lock_t afs_xosi; /* lock is for tvattr */
19 extern struct osi_dev cacheDev;
20 extern struct vfs *afs_cacheVfsp;
23 void *osi_UFSOpen(ainode)
27 register struct osi_file *afile = NULL;
28 extern struct vfs *rootvfs;
29 struct vnode *vp = (struct vnode *)0;
30 extern int cacheDiskType;
33 AFS_STATCNT(osi_UFSOpen);
34 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
35 osi_Panic("UFSOpen called for non-UFS cache\n");
37 if (!afs_osicred_initialized) {
38 /* valid for alpha_osf, SunOS, Ultrix */
39 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
40 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
41 afs_osicred_initialized = 1;
43 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
46 ip = (struct inode *) igetinode((dev_t) cacheDev.dev, rootvfs, (ino_t)ainode, &vp,&dummy);
49 osi_FreeSmallSpace(afile);
50 osi_Panic("UFSOpen: igetinode failed");
52 afile->vnode = vp; /* Save the vnode pointer for the inode ip; also ip is already prele'ed in igetinode */
53 afile->size = VTOI(afile->vnode)->i_size;
55 afile->proc = (int (*)()) 0;
56 afile->inum = ainode; /* for hint validity checking */
60 afs_osi_Stat(afile, astat)
61 register struct osi_file *afile;
62 register struct osi_stat *astat; {
63 register afs_int32 code;
65 AFS_STATCNT(osi_Stat);
66 MObtainWriteLock(&afs_xosi,320);
68 code = VNOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred);
71 astat->size = tvattr.va_size;
72 astat->blksize = tvattr.va_blocksize;
73 astat->mtime = tvattr.va_mtime.tv_sec;
74 astat->atime = tvattr.va_atime.tv_sec;
76 MReleaseWriteLock(&afs_xosi);
81 register struct osi_file *afile;
83 AFS_STATCNT(osi_Close);
85 /* AIX writes entire data regions at a time when dumping core. We've
86 * seen a 26M write go through the system. When this happens, we run
87 * out of available pages. So, we'll flush the vnode's vm if we're short
92 if (afile->vnode->v_gnode->gn_seg) {
93 /* 524287 is the max number of pages for a file. See test in
96 code = vm_writep(afile->vnode->v_gnode->gn_seg, 0, 524287);
99 AFS_RELE(afile->vnode);
102 osi_FreeSmallSpace(afile);
106 osi_UFSTruncate(afile, asize)
107 register struct osi_file *afile;
109 struct AFS_UCRED *oldCred;
111 register afs_int32 code;
112 struct osi_stat tstat;
113 afs_int32 mode=FWRITE|FSYNC;
114 AFS_STATCNT(osi_Truncate);
116 /* This routine only shrinks files, and most systems
117 * have very slow truncates, even when the file is already
118 * small enough. Check now and save some time.
120 code = afs_osi_Stat(afile, &tstat);
121 if (code || tstat.size <= asize) return code;
122 MObtainWriteLock(&afs_xosi,321);
124 * If we're truncating an unopened file to a non-zero length,
125 * we need to bind it to a vm segment
126 * Note that that the binding will actually happen inside
127 * jfs by xix_ftrunc; setting mode to 0 will enable that.
129 if (asize && !VTOGP(afile->vnode)->gn_seg)
132 code = VNOP_FTRUNC(afile->vnode, mode, asize, (caddr_t)0, &afs_osi_cred);
134 MReleaseWriteLock(&afs_xosi);
138 void osi_DisableAtimes(avp)
141 struct inode *ip = VTOIP(avp);
146 /* Generic read interface */
147 afs_osi_Read(afile, offset, aptr, asize)
148 register struct osi_file *afile;
152 struct AFS_UCRED *oldCred;
154 register afs_int32 code;
155 register afs_int32 cnt1=0;
156 AFS_STATCNT(osi_Read);
159 * If the osi_file passed in is NULL, panic only if AFS is not shutting
160 * down. No point in crashing when we are already shutting down
163 if ( !afs_shuttingdown )
164 osi_Panic("osi_Read called with null param");
169 if (offset != -1) afile->offset = offset;
171 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
173 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize,
174 (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid);
177 code = asize - resid;
178 afile->offset += code;
179 osi_DisableAtimes(afile->vnode);
182 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
183 ICL_TYPE_INT32, code);
185 * To handle periodic low-level EFAULT failures that we've seen with the
186 * Weitek chip; in all observed failed cases a second read succeeded.
188 if ((code == EFAULT) && (cnt1++ < 5)) {
189 afs_stats_cmperf.osiread_efaults++;
198 /* Generic write interface */
199 afs_osi_Write(afile, offset, aptr, asize)
200 register struct osi_file *afile;
204 struct AFS_UCRED *oldCred;
206 register afs_int32 code;
207 AFS_STATCNT(osi_Write);
209 osi_Panic("afs_osi_Write called with null param");
210 if (offset != -1) afile->offset = offset;
211 /* Note the difference in the way the afile->offset is passed (see comments in gop_rdwr() in afs_aix_subr.c for comments) */
213 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
214 (off_t)&afile->offset, AFS_UIOSYS, NULL, &resid);
217 code = asize - resid;
218 afile->offset += code;
221 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
226 (*afile->proc)(afile, code);
232 /* This work should be handled by physstrat in ca/machdep.c.
233 This routine written from the RT NFS port strategy routine.
234 It has been generalized a bit, but should still be pretty clear. */
235 int afs_osi_MapStrategy(aproc, bp)
237 register struct buf *bp;
239 afs_int32 returnCode;
241 AFS_STATCNT(osi_MapStrategy);
242 returnCode = (*aproc) (bp);
252 extern int afs_cold_shutdown;
254 AFS_STATCNT(shutdown_osifile);
255 if (afs_cold_shutdown) {
256 afs_osicred_initialized = 0;