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 */
14 #include "../afs/osi_inode.h" /* igetinode() */
17 int afs_osicred_initialized=0;
18 struct AFS_UCRED afs_osi_cred;
19 afs_lock_t afs_xosi; /* lock is for tvattr */
20 extern struct osi_dev cacheDev;
21 extern struct vfs *afs_cacheVfsp;
24 void *osi_UFSOpen(ainode)
28 register struct osi_file *afile = NULL;
29 extern int cacheDiskType;
32 AFS_STATCNT(osi_UFSOpen);
33 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
34 osi_Panic("UFSOpen called for non-UFS cache\n");
36 if (!afs_osicred_initialized) {
37 /* valid for alpha_osf, SunOS, Ultrix */
38 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
39 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
40 afs_osicred_initialized = 1;
42 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
45 ip = (struct inode *) igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode,&dummy);
48 osi_FreeSmallSpace(afile);
49 osi_Panic("UFSOpen: igetinode failed");
52 afile->vnode = ITOV(ip);
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 = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, VSYNC);
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 AFS_RELE(afile->vnode);
88 osi_FreeSmallSpace(afile);
92 osi_UFSTruncate(afile, asize)
93 register struct osi_file *afile;
95 struct AFS_UCRED *oldCred;
97 register afs_int32 code;
98 struct osi_stat tstat;
99 AFS_STATCNT(osi_Truncate);
101 /* This routine only shrinks files, and most systems
102 * have very slow truncates, even when the file is already
103 * small enough. Check now and save some time.
105 code = afs_osi_Stat(afile, &tstat);
106 if (code || tstat.size <= asize) return code;
107 MObtainWriteLock(&afs_xosi,321);
109 /* note that this credential swapping stuff is only necessary because
110 of ufs's references directly to u.u_cred instead of to
111 credentials parameter. Probably should fix ufs some day. */
112 oldCred = p_cred(u.u_procp);
113 set_p_cred(u.u_procp, &afs_osi_cred);
114 tvattr.va_size = asize;
116 code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, 0);
118 set_p_cred(u.u_procp, oldCred); /* restore */
119 MReleaseWriteLock(&afs_xosi);
123 void osi_DisableAtimes(avp)
126 struct inode *ip = VTOI(avp);
131 /* Generic read interface */
132 afs_osi_Read(afile, offset, aptr, asize)
133 register struct osi_file *afile;
137 struct AFS_UCRED *oldCred;
139 register afs_int32 code;
140 register afs_int32 cnt1=0;
141 AFS_STATCNT(osi_Read);
144 * If the osi_file passed in is NULL, panic only if AFS is not shutting
145 * down. No point in crashing when we are already shutting down
148 if ( !afs_shuttingdown )
149 osi_Panic("osi_Read called with null param");
154 if (offset != -1) afile->offset = offset;
157 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
158 AFS_UIOSYS, IO_UNIT, &resid);
161 code = asize - resid;
162 afile->offset += code;
163 osi_DisableAtimes(afile->vnode);
166 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, (afs_int32) resid,
167 ICL_TYPE_INT32, code);
169 * To handle periodic low-level EFAULT failures that we've seen with the
170 * Weitek chip; in all observed failed cases a second read succeeded.
172 if ((code == EFAULT) && (cnt1++ < 5)) {
173 afs_stats_cmperf.osiread_efaults++;
182 /* Generic write interface */
183 afs_osi_Write(afile, offset, aptr, asize)
184 register struct osi_file *afile;
188 struct AFS_UCRED *oldCred;
190 register afs_int32 code;
191 AFS_STATCNT(osi_Write);
193 osi_Panic("afs_osi_Write called with null param");
194 if (offset != -1) afile->offset = offset;
196 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
197 AFS_UIOSYS, IO_UNIT, &resid);
200 code = asize - resid;
201 afile->offset += code;
204 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
209 (*afile->proc)(afile, code);
218 extern int afs_cold_shutdown;
220 AFS_STATCNT(shutdown_osifile);
221 if (afs_cold_shutdown) {
222 afs_osicred_initialized = 0;