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
11 * SGI specific vnodeops + other misc interface glue
13 #include <afsconfig.h>
14 #include "afs/param.h"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
21 #include "afsincludes.h" /* Afs-based standard headers */
22 #include "afs/afs_stats.h" /* statistics */
23 #include "sys/flock.h"
24 #include "afs/nfsclient.h"
26 /* AFSBSIZE must be at least the size of a page, else the client will hang.
27 * For 64 bit platforms, the page size is more than 8K.
29 #define AFSBSIZE _PAGESZ
30 extern struct afs_exporter *root_exported;
31 extern void afs_chkpgoob(vnode_t *, pgno_t);
33 static void afs_strategy();
34 static int afs_xread(), afs_xwrite();
35 static int afs_xbmap(), afs_map(), afs_reclaim();
37 static int afs_addmap(), afs_delmap();
39 extern int afs_open(), afs_close(), afs_ioctl(), afs_getattr(), afs_setattr();
40 extern int afs_access(), afs_lookup();
41 extern int afs_create(), afs_remove(), afs_link(), afs_rename();
42 extern int afs_mkdir(), afs_rmdir(), afs_readdir();
43 extern int afs_symlink(), afs_readlink(), afs_fsync(), afs_fid(),
45 static int afs_seek(OSI_VC_DECL(a), off_t b, off_t * c);
47 extern int afs_xinactive();
49 extern void afs_xinactive();
52 extern void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b);
53 extern void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b);
55 extern int afs_fid2();
57 static int afsrwvp(register struct vcache *avc, register struct uio *uio,
58 enum uio_rw rw, int ioflag,
60 struct cred *cr, struct flid *flp);
65 static void mp_afs_rwlock(OSI_VN_DECL(a), AFS_RWLOCK_T b);
66 static void mp_afs_rwunlock(OSI_VN_DECL(a), AFS_RWLOCK_T b);
67 struct vnodeops afs_lockedvnodeops =
69 struct vnodeops Afs_vnodeops =
74 BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE),
107 fs_nosys, /* realvp */
112 fs_noerr, /* addmap - devices only */
113 fs_noerr, /* delmap - devices only */
121 fs_nosys, /* allocstore */
122 fs_nosys, /* fcntl */
123 afs_reclaim, /* reclaim */
124 fs_nosys, /* attr_get */
125 fs_nosys, /* attr_set */
126 fs_nosys, /* attr_remove */
127 fs_nosys, /* attr_list */
131 (vop_link_removed_t) fs_noval,
138 (vop_commit_t) fs_nosys,
139 (vop_readbuf_t) fs_nosys,
149 struct vnodeops *afs_ops = &Afs_vnodeops;
153 afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag,
165 get_current_flid(&flid);
170 * Since AFS doesn't support byte-wise locks (and simply
171 * says yes! we handle byte locking locally only.
172 * This makes lots of things work much better
173 * XXX This doesn't properly handle moving from a
174 * byte-wise lock up to a full file lock (we should
175 * remove the byte locks ..) Of course neither did the
176 * regular AFS way ...
178 * For GETLK we do a bit more - we first check any byte-wise
179 * locks - if none then check for full AFS file locks
181 if (cmd == F_GETLK || lfp->l_whence != 0 || lfp->l_start != 0
182 || (lfp->l_len != MAXEND && lfp->l_len != 0)) {
183 AFS_RWLOCK(vp, VRWLOCK_WRITE);
187 fs_frlock(OSI_VN_ARG(vp), cmd, lfp, flag, offset, vrwlock, cr);
189 error = fs_frlock(vp, cmd, lfp, flag, offset, cr);
192 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
193 if (error || cmd != F_GETLK)
195 if (lfp->l_type != F_UNLCK)
196 /* found some blocking lock */
198 /* fall through to check for full AFS file locks */
201 /* map BSD style to plain - we don't call reclock()
202 * and its only there that the difference is important
226 error = convoff(vp, lfp, 0, offset, SEEKLIMIT
228 , OSI_GET_CURRENT_CRED()
229 #endif /* AFS_SGI64_ENV */
235 error = afs_lockctl(vp, lfp, cmd, cr, pid);
237 error = afs_lockctl(vp, lfp, cmd, cr, OSI_GET_CURRENT_PID());
245 * We need to get the cache hierarchy right.
246 * First comes the page cache - pages are hashed based on afs
247 * vnode and offset. It is important to have things hashed here
248 * for the VM/paging system to work.
249 * Note that the paging system calls VOP_READ with the UIO_NOSPACE -
250 * it simply requires that somehow the page is hashed
251 * upon successful return.
252 * This means in afs_read we
253 * must call the 'chunk' code that handles page insertion. In order
254 * to actually get the data, 'chunk' calls the VOP_STRATEGY routine.
255 * This is basically the std afs_read routine - validating and
256 * getting the info into the Dcache, then calling VOP_READ.
257 * The only bad thing here is that by calling VOP_READ (and VOP_WRITE
258 * to fill the cache) we will get 2 copies of these pages into the
259 * page cache - one hashed on afs vnode and one on efs vnode. THis
260 * is wasteful but does no harm. A potential solution involves
261 * causing an ASYNC flush of the newly fetched cache data and
262 * doing direct I/O on the read side....
267 afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr, flp)
271 afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr)
281 osi_Assert(avc->v.v_count > 0);
282 if (avc->v.v_type != VREG)
287 if (!(ioflag & IO_ISLOCKED))
288 AFS_RWLOCK((vnode_t *) avc, VRWLOCK_READ);
290 code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr, flp);
292 if (!(ioflag & IO_ISLOCKED))
293 AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_READ);
296 code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr);
304 afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr, flp)
308 afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr)
318 osi_Assert(avc->v.v_count > 0);
319 if (avc->v.v_type != VREG)
322 if (ioflag & IO_APPEND)
323 uiop->uio_offset = avc->m.Length;
326 if (!(ioflag & IO_ISLOCKED))
327 AFS_RWLOCK(((vnode_t *) avc), VRWLOCK_WRITE);
329 code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr, flp);
331 if (!(ioflag & IO_ISLOCKED))
332 AFS_RWUNLOCK((vnode_t *) avc, VRWLOCK_WRITE);
335 code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr);
341 static int prnra = 0;
342 static int acchk = 0;
343 static int acdrop = 0;
346 afsrwvp(register struct vcache *avc, register struct uio *uio, enum uio_rw rw,
349 struct cred *cr, struct flid *flp)
354 register struct vnode *vp = AFSTOV(avc);
359 off_t bsize, rem, len;
361 struct bmapval bmv[2];
362 int nmaps, didFakeOpen = 0;
363 struct vrequest treq;
367 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
368 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
371 newoff = uio->uio_resid + uio->uio_offset;
372 if (uio->uio_resid <= 0) {
375 if (uio->uio_offset < 0 || newoff < 0) {
378 if (ioflag & IO_DIRECT)
381 if (rw == UIO_WRITE && vp->v_type == VREG && newoff > uio->uio_limit) {
385 afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc,
386 ICL_TYPE_INT32, ioflag, ICL_TYPE_INT32, rw, ICL_TYPE_INT32, 0);
388 /* get a validated vcache entry */
389 afs_InitReq(&treq, cr);
390 error = afs_VerifyVCache(avc, &treq);
392 return afs_CheckCode(error, &treq, 51);
395 * flush any stale pages - this will unmap
396 * and invalidate all pages for vp (NOT writing them back!)
398 osi_FlushPages(avc, cr);
400 if (cr && AFS_NFSXLATORREQ(cr) && rw == UIO_READ) {
402 (avc, PRSFS_READ, &treq,
403 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ))
407 * To handle anonymous calls to VOP_STRATEGY from afs_sync/sync/bdflush
408 * we need better than the callers credentials. So we squirrel away
409 * the last writers credentials
411 if (rw == UIO_WRITE || (rw == UIO_READ && avc->cred == NULL)) {
412 ObtainWriteLock(&avc->lock, 92);
417 ReleaseWriteLock(&avc->lock);
421 * We have to bump the open/exwriters field here
422 * courtesy of the nfs xlator
423 * because there're no open/close nfs rpc's to call our afs_open/close.
425 if (root_exported && rw == UIO_WRITE) {
426 ObtainWriteLock(&avc->lock, 234);
431 ReleaseWriteLock(&avc->lock);
435 if (rw == UIO_WRITE) {
436 ObtainWriteLock(&avc->lock, 330);
437 avc->states |= CDirty;
438 ReleaseWriteLock(&avc->lock);
444 /* If v_dpages is set SGI 5.3 will convert those pages to
445 * B_DELWRI in chunkread and getchunk. Write the pages out
446 * before we trigger that behavior. For 6.1, dirty pages stay
447 * around too long and we should get rid of them as quickly
450 while (VN_GET_DPAGES(vp))
454 error = avc->vc_error;
457 bsize = AFSBSIZE; /* why not?? */
458 off = uio->uio_offset % bsize;
459 bn = BTOBBT(uio->uio_offset - off);
461 * decrease bsize - otherwise we will
462 * get 'extra' pages in the cache for this
463 * vnode that we would need to flush when
464 * calling e.g. ptossvp.
465 * So we can use Length in ptossvp,
466 * we make sure we never go more than to the file size
467 * rounded up to a page boundary.
468 * That doesn't quite work, since we may get a page hashed to
469 * the vnode w/o updating the length. Thus we always use
470 * MAXLONG in ptossvp to be safe.
472 if (rw == UIO_READ) {
474 * read/paging in a normal file
476 rem = avc->m.Length - uio->uio_offset;
481 * compute minimum of rest of block and rest of file
483 cnt = MIN(bsize - off, rem);
484 osi_Assert((off + cnt) <= bsize);
485 bsize = ctob(btoc(off + cnt));
488 bmv[0].bn = bmv[0].offset = bn;
490 bmv[0].bsize = bsize;
492 bmv[0].pbsize = MIN(cnt, uio->uio_resid);
495 bmv[0].pbdev = vp->v_rdev;
496 bmv[0].pmp = uio->uio_pmp;
500 * initiate read-ahead if it looks like
501 * we are reading sequentially OR they want
502 * more than one 'bsize' (==AFSBSIZE) worth
503 * XXXHack - to avoid DELWRI buffers we can't
504 * do read-ahead on any file that has potentially
507 if ((avc->lastr + BTOBB(AFSBSIZE) == bn
508 || uio->uio_resid > AFSBSIZE)
510 && (!AFS_VN_MAPPED(vp))
511 #else /* AFS_SGI61_ENV */
512 && ((vp->v_flag & VWASMAP) == 0)
513 #endif /* AFS_SGI61_ENV */
518 bmv[1].bn = bmv[1].offset = bn + len;
519 osi_Assert((BBTOB(bn + len) % bsize) == 0);
520 acnt = MIN(bsize, rem);
521 bsize = ctob(btoc(acnt));
526 bmv[1].bsize = bsize;
528 bmv[1].pbsize = acnt;
530 bmv[1].pmp = uio->uio_pmp;
531 bmv[1].pbdev = vp->v_rdev;
538 ("NRA:vp 0x%x lastr %d bn %d len %d cnt %d bsize %d rem %d resid %d\n",
539 vp, avc->lastr, bn, len, cnt, bsize, rem,
544 bp = chunkread(vp, bmv, nmaps, cr);
546 * If at a chunk boundary, start prefetch of next chunk.
548 if (counter == 0 || AFS_CHUNKOFFSET(off) == 0) {
550 ObtainWriteLock(&avc->lock, 562);
551 tdc = afs_FindDCache(avc, off);
553 if (!(tdc->mflags & DFNextStarted))
554 afs_PrefetchChunk(avc, tdc, cr, &treq);
557 ReleaseWriteLock(&avc->lock);
563 * writing a normal file
566 * Purge dirty chunks of file if there are too many dirty chunks.
567 * Inside the write loop, we only do this at a chunk boundary.
568 * Clean up partial chunk if necessary at end of loop.
570 if (counter > 0 && AFS_CHUNKOFFSET(uio->uio_offset) == 0) {
572 ObtainWriteLock(&avc->lock, 90);
573 error = afs_DoPartialWrite(avc, &treq);
575 avc->states |= CDirty;
576 ReleaseWriteLock(&avc->lock);
583 cnt = MIN(bsize - off, uio->uio_resid);
584 bsize = ctob(btoc(off + cnt));
590 bmv[0].bsize = bsize;
594 bmv[0].pmp = uio->uio_pmp;
598 bp = getchunk(vp, bmv, cr);
600 bp = chunkread(vp, bmv, 1, cr);
602 avc->m.Date = osi_Time(); /* Set file date (for ranlib) */
604 if (bp->b_flags & B_ERROR) {
606 * Since we compile -signed, b_error is a signed
607 * char when it should be an unsigned char.
608 * This can cause some errors codes to be interpreted
611 error = (unsigned char)(bp->b_error);
615 if (acchk && error) {
616 cmn_err(CE_WARN, "bp 0x%x has error %d\n", bp, error);
625 osi_Assert(bp->b_error == 0);
627 if (uio->uio_segflg != UIO_NOSPACE)
629 AFS_UIOMOVE(bp->b_un.b_addr + bmv[0].pboff, cnt, rw, uio, error);
630 if (rw == UIO_READ || error) {
631 if (bp->b_flags & B_DELWRI) {
637 * m.Length is the maximum number of bytes known to be in the file.
638 * Make sure it is at least as high as the last byte we just wrote
641 if (avc->m.Length < uio->uio_offset) {
643 ObtainWriteLock(&avc->lock, 235);
644 avc->m.Length = uio->uio_offset;
645 ReleaseWriteLock(&avc->lock);
648 if (uio->uio_fmode & FSYNC) {
650 } else if (off + cnt < bsize) {
651 bawrite(bp); /* was bdwrite */
653 bp->b_flags |= B_AGE;
657 * Since EIO on an unlinked file is non-intuitive - give some
661 if (avc->m.LinkCount == 0)
663 "AFS: Process pid %d write error %d writing to unlinked file.",
664 OSI_GET_CURRENT_PID(), error);
667 } while (!error && uio->uio_resid > 0);
668 afs_chkpgoob(&avc->v, btoc(avc->m.Length));
672 if (rw == UIO_WRITE && error == 0 && (avc->states & CDirty)) {
673 ObtainWriteLock(&avc->lock, 405);
674 error = afs_DoPartialWrite(avc, &treq);
675 ReleaseWriteLock(&avc->lock);
680 if (((ioflag & IO_SYNC) || (ioflag & IO_DSYNC)) && (rw == UIO_WRITE)
681 && !AFS_NFSXLATORREQ(cr)) {
682 error = afs_fsync(avc, 0, cr);
684 #else /* AFS_SGI61_ENV */
685 if ((ioflag & IO_SYNC) && (rw == UIO_WRITE) && !AFS_NFSXLATORREQ(cr)) {
686 error = afs_fsync(avc, 0, cr);
688 #endif /* AFS_SGI61_ENV */
691 ObtainWriteLock(&avc->lock, 236);
692 afs_FakeClose(avc, cr); /* XXXX For nfs trans XXXX */
693 ReleaseWriteLock(&avc->lock);
695 afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc,
696 ICL_TYPE_INT32, ioflag, ICL_TYPE_INT32, rw, ICL_TYPE_INT32,
703 afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv)
712 int bsize; /* server's block size in bytes */
718 off = offset % bsize; /* offset into block */
719 bmv->bn = BTOBBT(offset - off);
720 bmv->offset = bmv->bn;
722 rem = avc->m.Length - offset;
726 cnt = MIN(bsize - off, rem);
729 * It is benign to ignore *nbmv > 1, since it is only for requesting
734 * Don't map more than up to next page if at end of file
735 * See comment in afsrwvp
737 osi_Assert((off + cnt) <= bsize);
738 bsize = ctob(btoc(off + cnt));
739 bmv->pbsize = MIN(cnt, count);
743 bmv->pbdev = avc->v.v_rdev;
746 bmv->length = BTOBBT(bsize);
752 * called out of chunkread from afs_xread & clusterwrite to push dirty
753 * pages back - this routine
754 * actually does the reading/writing by calling afs_read/afs_write
755 * bp points to a set of pages that have been inserted into
756 * the page cache hashed on afs vp.
759 afs_strategy(OSI_VC_ARG(avc), bp)
769 vnode_t *vp = (vnode_t *) avc;
772 * We can't afford DELWRI buffers for 2 reasons:
773 * 1) Since we can call underlying EFS, we can require a
774 * buffer to flush a buffer. This leads to 2 potential
775 * recursions/deadlocks
776 * a) if all buffers are DELWRI afs buffers, then
777 * ngeteblk -> bwrite -> afs_strategy -> afs_write ->
778 * UFS_Write -> efs_write -> ngeteblk .... could
779 * recurse a long ways!
780 * b) brelse -> chunkhold which can call dchunkpush
781 * will look for any DELWRI buffers and call strategy
782 * on them. This can then end up via UFS_Write
785 * a) We never do bdwrite(s) on AFS buffers.
786 * b) We call pdflush with B_ASYNC
787 * c) in chunkhold where it can set a buffer DELWRI
788 * we immediatly do a clusterwrite for AFS vp's
789 * XXX Alas, 'c' got dropped in 5.1 so its possible to get DELWRI
790 * buffers if someone has mmaped the file and dirtied it then
791 * reads/faults it again.
792 * Instead - wherever we call chunkread/getchunk we check for a
793 * returned bp with DELWRI set, and write it out immediately
795 if (CheckLock(&avc->lock) && VN_GET_DBUF(vp)) {
796 printf("WARN: afs_strategy vp=%x, v_dbuf=%x bp=%x\n", vp,
797 VN_GET_DBUF(vp), bp);
799 bp->b_flags |= B_ERROR;
803 if (bp->b_error != 0)
804 printf("WARNING: afs_strategy3 vp=%x, bp=%x, err=%x\n", vp, bp,
808 * To get credentials somewhat correct (we may be called from bdflush/
809 * sync) we use saved credentials in Vcache.
810 * We must hold them since someone else could change them
812 ObtainReadLock(&avc->lock);
813 if (bp->b_flags & B_READ) {
814 if (BBTOB(bp->b_blkno) >= avc->m.Length) {
815 /* we are responsible for zero'ing the page */
818 memset(c, 0, bp->b_bcount);
820 ReleaseReadLock(&avc->lock);
823 } else if ((avc->states & CWritingUFS) && (bp->b_flags & B_DELWRI)) {
825 ReleaseReadLock(&avc->lock);
832 ReleaseReadLock(&avc->lock);
834 aiovec.iov_base = bp_mapin(bp);
835 uio->uio_iov = &aiovec;
837 uio->uio_resid = aiovec.iov_len = bp->b_bcount;
838 uio->uio_offset = BBTOB(bp->b_blkno);
839 uio->uio_segflg = UIO_SYSSPACE;
840 uio->uio_limit = RLIM_INFINITY; /* we checked the limit earlier */
845 if (bp->b_flags & B_READ) {
846 uio->uio_fmode = FREAD;
847 error = afs_read(vp, uio, cr, 0, 0, 0);
849 uio->uio_fmode = FWRITE;
850 error = afs_write(vp, uio, 0, cr, 0);
855 if (acchk && error) {
856 cmn_err(CE_WARN, "vp 0x%x has error %d\n", vp, error);
863 bp->b_flags |= B_ERROR;
864 if ((uio->uio_fmode == FWRITE) && !avc->vc_error)
865 avc->vc_error = error;
873 afs_seek(OSI_VC_ARG(avc), ooff, noffp)
878 return *noffp < 0 ? EINVAL : 0;
881 #if !defined(AFS_SGI65_ENV)
882 /* Irix 6.5 uses addmap/delmap only for devices. */
885 afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, cr)
896 struct vnode *vp = AFSTOV(avc);
898 if (vp->v_flag & VNOMAP)
902 AFS_RWLOCK(vp, VRWLOCK_WRITE);
903 if (avc->mapcnt == 0) {
904 /* on first mapping add a open reference */
905 ObtainWriteLock(&avc->lock, 237);
906 avc->execsOrWriters++;
908 ReleaseWriteLock(&avc->lock);
910 avc->mapcnt += btoc(len);
911 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
915 /*ARGSUSED*/ static int
916 afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, acred)
927 struct vnode *vp = AFSTOV(avc);
928 register struct brequest *tb;
929 struct vrequest treq;
932 if (vp->v_flag & VNOMAP)
936 AFS_RWLOCK(vp, VRWLOCK_WRITE);
937 osi_Assert(avc->mapcnt > 0);
938 avc->mapcnt -= btoc(len);
939 osi_Assert(avc->mapcnt >= 0);
940 if (avc->mapcnt == 0) {
941 /* on last mapping push back and remove our reference */
942 osi_Assert(avc->execsOrWriters > 0);
943 osi_Assert(avc->opens > 0);
944 if (avc->m.LinkCount == 0) {
945 ObtainWriteLock(&avc->lock, 238);
947 PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG);
949 ReleaseWriteLock(&avc->lock);
954 afs_InitReq(&treq, acred);
956 /* do it yourself if daemons are all busy */
957 ObtainWriteLock(&avc->lock, 239);
958 code = afs_StoreOnLastReference(avc, &treq);
959 ReleaseWriteLock(&avc->lock);
960 /* BStore does CheckCode so we should also */
961 /* VNOVNODE is "acceptable" error code from close, since
962 * may happen when deleting a file on another machine while
963 * it is open here. */
964 if (code == VNOVNODE)
967 afs_StoreWarn(code, avc->fid.Fid.Volume, /* /dev/console */
970 code = afs_CheckCode(code, &treq, 52);
971 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
973 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
974 /* at least one daemon is idle, so ask it to do the store.
975 * Also, note that we don't lock it any more... */
976 tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred,
977 (afs_size_t) acred->cr_uid, 0L, (void *)0);
978 /* sleep waiting for the store to start, then retrieve error code */
979 while ((tb->flags & BUVALID) == 0) {
987 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
991 #endif /* ! AFS_SGI65_ENV */
996 * Note - if mapping in an ELF interpreter, one can get called without vp
997 * ever having been 'opened'
1001 afs_map(OSI_VC_ARG(avc), off, len, prot, flags, cr, vpp)
1011 afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, flags, cr)
1014 struct pregion *prp;
1017 u_int prot, maxprot;
1022 OSI_VC_CONVERT(avc);
1023 struct vnode *vp = AFSTOV(avc);
1024 struct vrequest treq;
1027 /* get a validated vcache entry */
1028 afs_InitReq(&treq, cr);
1029 error = afs_VerifyVCache(avc, &treq);
1031 return afs_CheckCode(error, &treq, 53);
1033 osi_FlushPages(avc, cr); /* ensure old pages are gone */
1034 #ifdef AFS_SGI65_ENV
1035 /* If the vnode is currently opened for write, there's the potential
1036 * that this mapping might (now or in the future) have PROT_WRITE.
1037 * So assume it does and we'll have to call afs_StoreOnLastReference.
1039 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1040 ObtainWriteLock(&avc->lock, 501);
1041 if (avc->execsOrWriters > 0) {
1042 avc->execsOrWriters++;
1044 avc->mapcnt++; /* count eow's due to mappings. */
1046 ReleaseWriteLock(&avc->lock);
1047 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1049 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1052 fs_map_subr(vp, (off_t) avc->m.Length, (u_int) avc->m.Mode, off, prp,
1053 *addrp, len, prot, maxprot, flags, cr);
1055 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1056 #endif /* AFS_SGI65_ENV */
1057 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vp,
1058 #ifdef AFS_SGI65_ENV
1059 ICL_TYPE_POINTER, NULL,
1061 ICL_TYPE_POINTER, *addrp,
1063 ICL_TYPE_INT32, len, ICL_TYPE_INT32, off);
1068 extern afs_rwlock_t afs_xvcache;
1069 extern afs_lock_t afs_xdcache;
1070 #ifdef AFS_SGI64_ENV
1075 afs_xinactive(OSI_VC_ARG(avc), acred)
1077 struct ucred *acred;
1080 OSI_VC_CONVERT(avc);
1081 vnode_t *vp = (vnode_t *) avc;
1082 int mapcnt = avc->mapcnt; /* We just clear off this many. */
1084 AFS_STATCNT(afs_inactive);
1087 if (!(vp->v_flag & VINACT) || (vp->v_count > 0)) {
1088 /* inactive was already done, or someone did a VN_HOLD; just return */
1089 vp->v_flag &= ~VINACT;
1091 #ifdef AFS_SGI64_ENV
1092 return VN_INACTIVE_CACHE;
1097 osi_Assert((vp->v_flag & VSHARE) == 0);
1098 vp->v_flag &= ~VINACT;
1099 /* Removed broadcast to waiters, since no one ever will. Only for vnodes
1104 #ifdef AFS_SGI65_ENV
1105 /* In Irix 6.5, the last unmap of a dirty mmap'd file does not
1106 * get an explicit vnode op. Instead we only find out at VOP_INACTIVE.
1108 if (!afs_rwlock_nowait((vnode_t *) avc, VRWLOCK_WRITE)) {
1109 return VN_INACTIVE_CACHE;
1111 if (NBObtainWriteLock(&avc->lock, 502)) {
1112 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1113 return VN_INACTIVE_CACHE;
1115 if (avc->states & CUnlinked) {
1116 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1117 avc->states |= CUnlinkedDel;
1118 ReleaseWriteLock(&avc->lock);
1119 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1121 ReleaseWriteLock(&avc->lock);
1122 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1123 afs_remunlink(avc, 1); /* ignore any return code */
1125 return VN_INACTIVE_CACHE;
1127 if ((avc->states & CDirty) || (avc->execsOrWriters > 0)) {
1128 /* File either already has dirty chunks (CDirty) or was mapped at
1129 * time in its life with the potential for being written into.
1130 * Note that afs_close defers storebacks if the vnode's ref count
1134 struct vrequest treq;
1135 if (!afs_InitReq(&treq, acred)) {
1139 avc->execsOrWriters -= mapcnt - 1;
1140 avc->opens -= mapcnt - 1;
1141 avc->mapcnt -= mapcnt;
1142 code = afs_StoreOnLastReference(avc, &treq);
1143 /* The following behavior mimics the behavior in afs_close. */
1144 if (code == VNOVNODE || code == ENOENT)
1149 "AFS: Failed to store FID (%x:%lu.%lu.%lu) in VOP_INACTIVE, error = %d\n",
1150 (int)(avc->fid.Cell) & 0xffffffff,
1151 avc->fid.Fid.Volume, avc->fid.Fid.Vnode,
1152 avc->fid.Fid.Unique, code);
1154 afs_InvalidateAllSegments(avc);
1158 code = (vp->v_count == 0);
1160 /* If the vnode is now in use by someone else, return early. */
1162 ReleaseWriteLock(&avc->lock);
1163 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1164 return VN_INACTIVE_CACHE;
1170 osi_Assert((avc->states & (CCore | CMAPPED)) == 0);
1176 ReleaseWriteLock(&avc->lock);
1177 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1180 * If someone unlinked a file and this is the last hurrah -
1181 * nuke all the pages.
1183 if (avc->m.LinkCount == 0) {
1185 PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG);
1188 #ifndef AFS_SGI65_ENV
1189 osi_Assert(avc->mapcnt == 0);
1190 afs_chkpgoob(&avc->v, btoc(avc->m.Length));
1192 avc->states &= ~CDirty; /* Give up on store-backs */
1193 if (avc->states & CUnlinked) {
1194 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1195 avc->states |= CUnlinkedDel;
1197 afs_remunlink(avc, 1); /* ignore any return code */
1201 #ifdef AFS_SGI64_ENV
1202 return VN_INACTIVE_CACHE;
1207 afs_reclaim(OSI_VC_DECL(avc), int flag)
1209 #ifdef AFS_SGI64_ENV
1210 /* Get's called via VOP_RELCAIM in afs_FlushVCache to clear repl_vnodeops */
1213 panic("afs_reclaim");
1218 afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1221 struct vcache *avc = VTOAFS(vp);
1223 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1224 avc->vc_locktrips++;
1228 psema(&avc->vc_rwlock, PINOD);
1230 avc->vc_rwlockid = OSI_GET_LOCKID();
1234 afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1237 struct vcache *avc = VTOAFS(vp);
1240 osi_Assert(OSI_GET_LOCKID() == avc->vc_rwlockid);
1241 if (avc->vc_locktrips > 0) {
1242 --avc->vc_locktrips;
1245 avc->vc_rwlockid = OSI_NO_LOCKID;
1246 vsema(&avc->vc_rwlock);
1250 /* The flag argument is for symmetry with the afs_rwlock and afs_rwunlock
1251 * calls. SGI currently only uses the flag to assert if the unlock flag
1252 * does not match the corresponding lock flag. But they may start using this
1253 * flag for a real rw lock at some time.
1256 afs_rwlock_nowait(vnode_t * vp, AFS_RWLOCK_T flag)
1258 struct vcache *avc = VTOAFS(vp);
1261 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1262 avc->vc_locktrips++;
1265 if (cpsema(&avc->vc_rwlock)) {
1266 avc->vc_rwlockid = OSI_GET_LOCKID();
1272 #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR)
1274 afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1277 afs_fid2_t *afid = (afs_fid2_t *) fidp;
1278 OSI_VC_CONVERT(avc);
1280 osi_Assert(sizeof(fid_t) >= sizeof(afs_fid2_t));
1281 afid->af_len = sizeof(afs_fid2_t) - sizeof(afid->af_len);
1283 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1284 afid->af_cell = tcell->cellIndex & 0xffff;
1285 afs_PutCell(tcell, READ_LOCK);
1287 afid->af_volid = avc->fid.Fid.Volume;
1288 afid->af_vno = avc->fid.Fid.Vnode;
1289 afid->af_uniq = avc->fid.Fid.Unique;
1294 /* Only use so far is in checkpoint/restart for IRIX 6.4. In ckpt_fid, a
1295 * return of ENOSYS would make the code fail over to VOP_FID. We can't let
1296 * that happen, since we do a VN_HOLD there in the expectation that
1297 * posthandle will be called to release the vnode.
1299 * afs_fid2 is used to support the R5000 workarounds (_R5000_CVT_WAR)
1302 afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1304 #if defined(_R5000_CVT_WAR)
1305 extern int R5000_cvt_war;
1315 #endif /* AFS_SGI64_ENV && CKPT */
1319 * check for any pages hashed that shouldn't be!
1320 * Only valid if PGCACHEDEBUG is set in os/page.c
1321 * Drop the global lock here, since we may not actually do the call.
1324 afs_chkpgoob(vnode_t * vp, pgno_t pgno)
1329 pfindanyoob(vp, pgno);
1337 #ifdef AFS_SGI64_ENV
1338 #define AFS_MP_VC_ARG(A) bhv_desc_t A
1340 #define AFS_MP_VC_ARG(A) vnode_t A
1343 #ifdef AFS_SGI64_ENV
1345 mp_afs_open(bhv_desc_t * bhp, vnode_t ** a, mode_t b, struct cred *c)
1348 mp_afs_open(vnode_t ** a, mode_t b, struct cred *c)
1353 #ifdef AFS_SGI64_ENV
1354 rv = afs_lockedvnodeops.vop_open(bhp, a, b, c);
1356 rv = afs_lockedvnodeops.vop_open(a, b, c);
1362 #if defined(AFS_SGI64_ENV)
1363 #if defined(AFS_SGI65_ENV)
1365 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, struct cred *d)
1368 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e,
1373 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e)
1378 rv = afs_lockedvnodeops.vop_close(a, b, c, d
1379 #if !defined(AFS_SGI65_ENV)
1381 #if defined(AFS_SGI64_ENV)
1391 #ifdef AFS_SGI64_ENV
1393 mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1397 mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1402 #ifdef AFS_SGI64_ENV
1403 rv = afs_lockedvnodeops.vop_read(a, b, c, d, f);
1405 rv = afs_lockedvnodeops.vop_read(a, b, c, d);
1412 #ifdef AFS_SGI64_ENV
1414 mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1418 mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1423 #ifdef AFS_SGI64_ENV
1424 rv = afs_lockedvnodeops.vop_write(a, b, c, d, f);
1426 rv = afs_lockedvnodeops.vop_write(a, b, c, d);
1433 mp_afs_ioctl(AFS_MP_VC_ARG(*a), int b, void *c, int d, struct cred *e, int *f
1434 #ifdef AFS_SGI65_ENV
1435 , struct vopbd *vbds
1441 rv = afs_lockedvnodeops.vop_ioctl(a, b, c, d, e, f
1442 #ifdef AFS_SGI65_ENV
1451 mp_fs_setfl(AFS_MP_VC_ARG(*a), int b, int c, struct cred *d)
1455 rv = afs_lockedvnodeops.vop_setfl(a, b, c, d);
1461 mp_afs_getattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1465 rv = afs_lockedvnodeops.vop_getattr(a, b, c, d);
1471 mp_afs_setattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1475 rv = afs_lockedvnodeops.vop_setattr(a, b, c, d);
1481 mp_afs_access(AFS_MP_VC_ARG(*a), int b,
1482 #ifndef AFS_SGI65_ENV
1489 rv = afs_lockedvnodeops.vop_access(a, b,
1490 #ifndef AFS_SGI65_ENV
1499 mp_afs_lookup(AFS_MP_VC_ARG(*a), char *b, vnode_t ** c, struct pathname *d,
1500 int e, vnode_t * f, struct cred *g)
1504 rv = afs_lockedvnodeops.vop_lookup(a, b, c, d, e, f, g);
1509 #ifdef AFS_SGI64_ENV
1511 mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, int d, int e,
1512 vnode_t ** f, struct cred *g)
1515 mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, enum vcexcl d,
1516 int e, vnode_t ** f, struct cred *g)
1521 rv = afs_lockedvnodeops.vop_create(a, b, c, d, e, f, g);
1527 mp_afs_remove(AFS_MP_VC_ARG(*a), char *b, struct cred *c)
1531 rv = afs_lockedvnodeops.vop_remove(a, b, c);
1537 mp_afs_link(AFS_MP_VC_ARG(*a), vnode_t * b, char *c, struct cred *d)
1541 rv = afs_lockedvnodeops.vop_link(a, b, c, d);
1547 mp_afs_rename(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, char *d,
1548 struct pathname *e, struct cred *f)
1552 rv = afs_lockedvnodeops.vop_rename(a, b, c, d, e, f);
1558 mp_afs_mkdir(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, vnode_t ** d,
1563 rv = afs_lockedvnodeops.vop_mkdir(a, b, c, d, e);
1569 mp_afs_rmdir(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, struct cred *d)
1573 rv = afs_lockedvnodeops.vop_rmdir(a, b, c, d);
1579 mp_afs_readdir(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c, int *d)
1583 rv = afs_lockedvnodeops.vop_readdir(a, b, c, d);
1589 mp_afs_symlink(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, char *d,
1594 rv = afs_lockedvnodeops.vop_symlink(a, b, c, d, e);
1600 mp_afs_readlink(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c)
1604 rv = afs_lockedvnodeops.vop_readlink(a, b, c);
1610 mp_afs_fsync(AFS_MP_VC_ARG(*a), int b, struct cred *c
1611 #ifdef AFS_SGI65_ENV
1612 , off_t start, off_t stop
1618 rv = afs_lockedvnodeops.vop_fsync(a, b, c
1619 #ifdef AFS_SGI65_ENV
1628 mp_afs_inactive(AFS_MP_VC_ARG(*a), struct cred *b)
1631 afs_lockedvnodeops.vop_inactive(a, b);
1637 mp_afs_fid(AFS_MP_VC_ARG(*a), struct fid **b)
1641 rv = afs_lockedvnodeops.vop_fid(a, b);
1647 mp_afs_fid2(AFS_MP_VC_ARG(*a), struct fid *b)
1651 rv = afs_lockedvnodeops.vop_fid2(a, b);
1657 mp_afs_rwlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1660 afs_rwlock(a, VRWLOCK_WRITE);
1665 mp_afs_rwunlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1668 afs_rwunlock(a, VRWLOCK_WRITE);
1673 mp_afs_seek(AFS_MP_VC_ARG(*a), off_t b, off_t * c)
1677 rv = afs_lockedvnodeops.vop_seek(a, b, c);
1683 mp_fs_cmp(AFS_MP_VC_ARG(*a), vnode_t * b)
1687 rv = afs_lockedvnodeops.vop_cmp(a, b);
1693 mp_afs_frlock(AFS_MP_VC_ARG(*a), int b, struct flock *c, int d, off_t e,
1694 #ifdef AFS_SGI65_ENV
1701 rv = afs_lockedvnodeops.vop_frlock(a, b, c, d, e,
1702 #ifdef AFS_SGI65_ENV
1711 mp_afs_realvp(AFS_MP_VC_ARG(*a), vnode_t ** b)
1715 rv = afs_lockedvnodeops.vop_realvp(a, b);
1721 mp_afs_bmap(AFS_MP_VC_ARG(*a), off_t b, ssize_t c, int d, struct cred *e,
1722 struct bmapval *f, int *g)
1726 rv = afs_lockedvnodeops.vop_bmap(a, b, c, d, e, f, g);
1732 mp_afs_strategy(AFS_MP_VC_ARG(*a), struct buf *b)
1736 afs_lockedvnodeops.vop_strategy(a, b);
1741 #ifdef AFS_SGI65_ENV
1743 mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, size_t c, mprot_t d, u_int e,
1744 struct cred *f, vnode_t ** g)
1747 mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, char **d, size_t e,
1748 u_int f, u_int g, u_int h, struct cred *i)
1753 rv = afs_lockedvnodeops.vop_map(a, b, c, d, e, f, g
1754 #ifndef AFS_SGI65_ENV
1763 #ifndef AFS_SGI65_ENV
1764 /* As of Irix 6.5, addmap and delmap are only for devices */
1766 mp_afs_addmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1767 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1771 rv = afs_lockedvnodeops.vop_addmap(a, b, c, d, e, f, g, h, i);
1777 mp_afs_delmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1778 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1782 rv = afs_lockedvnodeops.vop_delmap(a, b, c, d, e, f, g, h, i);
1786 #endif /* ! AFS_SGI65_ENV */
1789 mp_fs_poll(AFS_MP_VC_ARG(*a), short b, int c, short *d, struct pollhead **e
1790 #ifdef AFS_SGI65_ENV
1797 rv = afs_lockedvnodeops.vop_poll(a, b, c, d, e
1798 #ifdef AFS_SGI65_ENV
1807 struct vnodeops Afs_vnodeops = {
1808 #ifdef AFS_SGI64_ENV
1809 #ifdef AFS_SGI65_ENV
1810 BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE),
1812 VNODE_POSITION_BASE,
1843 fs_nosys, /* realvp */
1847 #ifdef AFS_SGI65_ENV
1848 fs_noerr, /* addmap - devices only */
1849 fs_noerr, /* delmap - devices only */
1854 mp_fs_poll, /* poll */
1855 fs_nosys, /* dump */
1857 fs_nosys, /* allocstore */
1858 fs_nosys, /* fcntl */
1859 afs_reclaim, /* reclaim */
1860 fs_nosys, /* attr_get */
1861 fs_nosys, /* attr_set */
1862 fs_nosys, /* attr_remove */
1863 fs_nosys, /* attr_list */
1864 #ifdef AFS_SGI64_ENV
1865 #ifdef AFS_SGI65_ENV
1867 (vop_link_removed_t) fs_noval,
1870 fs_flushinval_pages,
1874 (vop_commit_t) fs_nosys,
1875 (vop_readbuf_t) fs_nosys,
1883 struct vnodeops *afs_ops = &Afs_vnodeops;
1887 #if defined(AFS_SGI62_ENV) && defined(AFS_SGI_DUAL_FS_CACHE)
1888 /* Support for EFS and XFS caches. The assumption here is that the size of
1889 * a cache file also does not exceed 32 bits.
1892 /* Initialized in osi_InitCacheFSType(). Used to determine inode type. */
1893 int afs_CacheFSType = -1;
1894 vnodeops_t *afs_efs_vnodeopsp;
1895 vnodeops_t *afs_xfs_vnodeopsp;
1896 vnode_t *(*afs_IGetVnode) (ino_t);
1898 extern vnode_t *afs_EFSIGetVnode(ino_t); /* defined in osi_file.c */
1899 extern vnode_t *afs_XFSIGetVnode(ino_t); /* defined in osi_file.c */
1901 extern afs_lock_t afs_xosi; /* lock is for tvattr */
1903 /* Initialize the cache operations. Called while initializing cache files. */
1905 afs_InitDualFSCacheOps(struct vnode *vp)
1907 static int inited = 0;
1915 swp = vfs_getvfssw("xfs");
1917 afs_xfs_vnodeopsp = swp->vsw_vnodeops;
1919 if (vp && vp->v_op == afs_xfs_vnodeopsp) {
1920 afs_CacheFSType = AFS_SGI_XFS_CACHE;
1921 afs_IGetVnode = afs_XFSIGetVnode;
1928 osi_Panic("osi_InitCacheFSType: Can't find fstype for vnode 0x%llx\n",
1933 VnodeToIno(vnode_t * vp)
1938 MObtainWriteLock(&afs_xosi, 579);
1939 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
1941 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1944 osi_Panic("VnodeToIno");
1946 MReleaseWriteLock(&afs_xosi);
1947 return vattr.va_nodeid;
1951 VnodeToDev(vnode_t * vp)
1956 MObtainWriteLock(&afs_xosi, 580);
1957 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
1959 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1962 osi_Panic("VnodeToDev");
1964 MReleaseWriteLock(&afs_xosi);
1965 return (dev_t) vattr.va_fsid;
1969 VnodeToSize(vnode_t * vp)
1974 MObtainWriteLock(&afs_xosi, 581);
1975 vattr.va_mask = AT_SIZE;
1977 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1980 osi_Panic("VnodeToSize");
1982 MReleaseWriteLock(&afs_xosi);
1983 return vattr.va_size;
1985 #endif /* 6.2 and dual fs cache */
1986 #endif /* AFS_SGI62_ENV */