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 */
19 #include "afs/osi_inode.h"
22 int afs_osicred_initialized = 0;
23 struct AFS_UCRED afs_osi_cred;
24 afs_lock_t afs_xosi; /* lock is for tvattr */
25 extern struct osi_dev cacheDev;
26 extern struct vfs *afs_cacheVfsp;
31 /* Support for UFS and VXFS caches. The assumption here is that the size of
32 * a cache file also does not exceed 32 bits.
35 /* Initialized in osi_InitCacheFSType(). Used to determine inode type. */
36 int afs_CacheFSType = -1;
38 /* pointer to VXFS routine to access vnodes by inode number */
39 int (*vxfs_vx_vp_byino) ();
41 /* Initialize the cache operations. Called while initializing cache files. */
43 afs_InitDualFSCacheOps(struct vnode *vp)
46 static int inited = 0;
49 struct statvfs64 vfst;
50 #else /* AFS_SUN56_ENV */
52 #endif /* AFS_SUN56_ENV */
63 osi_Panic("afs_InitDualFSCacheOps: vp->v_vfsp is NULL");
64 code = VFS_STATVFS(vfsp, &vfst);
66 osi_Panic("afs_InitDualFSCacheOps: statvfs failed");
68 if (strcmp(vfst.f_basetype, "vxfs") == 0) {
69 vxfs_vx_vp_byino = (int (*)())modlookup("vxfs", "vx_vp_byino");
70 if (vxfs_vx_vp_byino == NULL)
72 ("afs_InitDualFSCacheOps: modlookup(vx_vp_byino) failed");
74 afs_CacheFSType = AFS_SUN_VXFS_CACHE;
78 afs_CacheFSType = AFS_SUN_UFS_CACHE;
83 VnodeToIno(vnode_t * vp)
88 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
90 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred, NULL);
92 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
95 osi_Panic("VnodeToIno");
97 return vattr.va_nodeid;
101 VnodeToDev(vnode_t * vp)
106 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
108 #ifdef AFS_SUN511_ENV
109 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred, NULL);
111 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
115 osi_Panic("VnodeToDev");
117 return (dev_t) vattr.va_fsid;
121 VnodeToSize(vnode_t * vp)
127 * We lock xosi in osi_Stat, so we probably should
128 * lock it here too - RWH.
130 MObtainWriteLock(&afs_xosi, 578);
131 vattr.va_mask = AT_SIZE;
133 #ifdef AFS_SUN511_ENV
134 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred, NULL);
136 code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
140 osi_Panic("VnodeToSize");
142 MReleaseWriteLock(&afs_xosi);
143 return (afs_int32) (vattr.va_size);
147 osi_VxfsOpen(afs_int32 ainode)
150 register struct osi_file *afile = NULL;
153 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
155 code = (*vxfs_vx_vp_byino) (afs_cacheVfsp, &vp, (unsigned int)ainode);
158 osi_FreeSmallSpace(afile);
159 osi_Panic("VxfsOpen: vx_vp_byino failed");
162 afile->size = VnodeToSize(afile->vnode);
164 afile->proc = (int (*)())0;
165 afile->inum = ainode; /* for hint validity checking */
166 return (void *)afile;
168 #endif /* AFS_HAVE_VXFS */
170 #if defined(AFS_SUN57_64BIT_ENV)
172 osi_UfsOpen(ino_t ainode)
175 osi_UfsOpen(afs_int32 ainode)
179 register struct osi_file *afile = NULL;
182 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
185 igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
189 osi_FreeSmallSpace(afile);
190 osi_Panic("UfsOpen: igetinode failed");
192 afile->vnode = ITOV(ip);
193 afile->size = VTOI(afile->vnode)->i_size;
195 afile->proc = (int (*)())0;
196 afile->inum = ainode; /* for hint validity checking */
197 return (void *)afile;
201 * In Solaris 7 we use 64 bit inode numbers
203 #if defined(AFS_SUN57_64BIT_ENV)
205 osi_UFSOpen(ino_t ainode)
208 osi_UFSOpen(afs_int32 ainode)
211 extern int cacheDiskType;
212 AFS_STATCNT(osi_UFSOpen);
213 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
214 osi_Panic("UFSOpen called for non-UFS cache\n");
216 if (!afs_osicred_initialized) {
217 /* valid for alpha_osf, SunOS, Ultrix */
218 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
219 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
220 afs_osicred_initialized = 1;
223 if (afs_CacheFSType == AFS_SUN_VXFS_CACHE)
224 return osi_VxfsOpen(ainode);
226 return osi_UfsOpen(ainode);
230 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
232 register afs_int32 code;
234 AFS_STATCNT(osi_Stat);
235 MObtainWriteLock(&afs_xosi, 320);
236 /* Ufs doesn't seem to care about the flags so we pass 0 for now */
237 tvattr.va_mask = AT_ALL;
239 #ifdef AFS_SUN511_ENV
240 code = VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, NULL);
242 code = VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
246 astat->size = tvattr.va_size;
247 astat->mtime = tvattr.va_mtime.tv_sec;
248 astat->atime = tvattr.va_atime.tv_sec;
250 MReleaseWriteLock(&afs_xosi);
255 osi_UFSClose(register struct osi_file *afile)
257 AFS_STATCNT(osi_Close);
259 AFS_RELE(afile->vnode);
262 osi_FreeSmallSpace(afile);
267 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
269 struct AFS_UCRED *oldCred;
271 register afs_int32 code;
272 struct osi_stat tstat;
273 AFS_STATCNT(osi_Truncate);
275 /* This routine only shrinks files, and most systems
276 * have very slow truncates, even when the file is already
277 * small enough. Check now and save some time.
279 code = afs_osi_Stat(afile, &tstat);
280 if (code || tstat.size <= asize)
282 MObtainWriteLock(&afs_xosi, 321);
283 tvattr.va_mask = AT_SIZE;
284 tvattr.va_size = asize;
286 * The only time a flag is used (ATTR_UTIME) is when we're changing the time
289 #ifdef AFS_SUN510_ENV
293 code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, &ct);
296 code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
299 MReleaseWriteLock(&afs_xosi);
304 osi_DisableAtimes(struct vnode *avp)
306 if (afs_CacheFSType == AFS_SUN_UFS_CACHE) {
307 struct inode *ip = VTOI(avp);
308 rw_enter(&ip->i_contents, RW_READER);
309 mutex_enter(&ip->i_tlock);
311 mutex_exit(&ip->i_tlock);
312 rw_exit(&ip->i_contents);
317 /* Generic read interface */
319 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
322 struct AFS_UCRED *oldCred;
323 #if defined(AFS_SUN57_ENV)
328 register afs_int32 code;
329 register afs_int32 cnt1 = 0;
330 AFS_STATCNT(osi_Read);
333 * If the osi_file passed in is NULL, panic only if AFS is not shutting
334 * down. No point in crashing when we are already shutting down
337 if (!afs_shuttingdown)
338 osi_Panic("osi_Read called with null param");
344 afile->offset = offset;
347 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
348 AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid);
351 code = asize - resid;
352 afile->offset += code;
353 osi_DisableAtimes(afile->vnode);
355 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
356 ICL_TYPE_INT32, code);
362 /* Generic write interface */
364 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
367 struct AFS_UCRED *oldCred;
368 #if defined(AFS_SUN57_ENV)
373 register afs_int32 code;
374 AFS_STATCNT(osi_Write);
376 osi_Panic("afs_osi_Write called with null param");
378 afile->offset = offset;
381 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
382 afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, &afs_osi_cred,
386 code = asize - resid;
387 afile->offset += code;
392 (*afile->proc) (afile, code);
398 /* This work should be handled by physstrat in ca/machdep.c.
399 This routine written from the RT NFS port strategy routine.
400 It has been generalized a bit, but should still be pretty clear. */
402 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
404 afs_int32 returnCode;
406 AFS_STATCNT(osi_MapStrategy);
407 returnCode = (*aproc) (bp);
415 shutdown_osifile(void)
417 AFS_STATCNT(shutdown_osifile);
418 if (afs_cold_shutdown) {
419 afs_osicred_initialized = 0;