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->f.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->f.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->f.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->f.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->f.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->f.m.Length < uio->uio_offset) {
643 ObtainWriteLock(&avc->lock, 235);
644 avc->f.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->f.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->f.m.Length));
672 if (rw == UIO_WRITE && error == 0 && (avc->f.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
688 #else /* AFS_SGI61_ENV */
689 if ((ioflag & IO_SYNC) && (rw == UIO_WRITE) && !AFS_NFSXLATORREQ(cr)) {
690 error = afs_fsync(avc, 0, cr);
692 #endif /* AFS_SGI61_ENV */
695 ObtainWriteLock(&avc->lock, 236);
696 afs_FakeClose(avc, cr); /* XXXX For nfs trans XXXX */
697 ReleaseWriteLock(&avc->lock);
699 afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc,
700 ICL_TYPE_INT32, ioflag, ICL_TYPE_INT32, rw, ICL_TYPE_INT32,
707 afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv)
716 int bsize; /* server's block size in bytes */
722 off = offset % bsize; /* offset into block */
723 bmv->bn = BTOBBT(offset - off);
724 bmv->offset = bmv->bn;
726 rem = avc->f.m.Length - offset;
730 cnt = MIN(bsize - off, rem);
733 * It is benign to ignore *nbmv > 1, since it is only for requesting
738 * Don't map more than up to next page if at end of file
739 * See comment in afsrwvp
741 osi_Assert((off + cnt) <= bsize);
742 bsize = ctob(btoc(off + cnt));
743 bmv->pbsize = MIN(cnt, count);
747 bmv->pbdev = avc->v.v_rdev;
750 bmv->length = BTOBBT(bsize);
756 * called out of chunkread from afs_xread & clusterwrite to push dirty
757 * pages back - this routine
758 * actually does the reading/writing by calling afs_read/afs_write
759 * bp points to a set of pages that have been inserted into
760 * the page cache hashed on afs vp.
763 afs_strategy(OSI_VC_ARG(avc), bp)
773 vnode_t *vp = (vnode_t *) avc;
776 * We can't afford DELWRI buffers for 2 reasons:
777 * 1) Since we can call underlying EFS, we can require a
778 * buffer to flush a buffer. This leads to 2 potential
779 * recursions/deadlocks
780 * a) if all buffers are DELWRI afs buffers, then
781 * ngeteblk -> bwrite -> afs_strategy -> afs_write ->
782 * UFS_Write -> efs_write -> ngeteblk .... could
783 * recurse a long ways!
784 * b) brelse -> chunkhold which can call dchunkpush
785 * will look for any DELWRI buffers and call strategy
786 * on them. This can then end up via UFS_Write
789 * a) We never do bdwrite(s) on AFS buffers.
790 * b) We call pdflush with B_ASYNC
791 * c) in chunkhold where it can set a buffer DELWRI
792 * we immediatly do a clusterwrite for AFS vp's
793 * XXX Alas, 'c' got dropped in 5.1 so its possible to get DELWRI
794 * buffers if someone has mmaped the file and dirtied it then
795 * reads/faults it again.
796 * Instead - wherever we call chunkread/getchunk we check for a
797 * returned bp with DELWRI set, and write it out immediately
799 if (CheckLock(&avc->lock) && VN_GET_DBUF(vp)) {
800 printf("WARN: afs_strategy vp=%x, v_dbuf=%x bp=%x\n", vp,
801 VN_GET_DBUF(vp), bp);
803 bp->b_flags |= B_ERROR;
807 if (bp->b_error != 0)
808 printf("WARNING: afs_strategy3 vp=%x, bp=%x, err=%x\n", vp, bp,
812 * To get credentials somewhat correct (we may be called from bdflush/
813 * sync) we use saved credentials in Vcache.
814 * We must hold them since someone else could change them
816 ObtainReadLock(&avc->lock);
817 if (bp->b_flags & B_READ) {
818 if (BBTOB(bp->b_blkno) >= avc->f.m.Length) {
819 /* we are responsible for zero'ing the page */
822 memset(c, 0, bp->b_bcount);
824 ReleaseReadLock(&avc->lock);
827 } else if ((avc->f.states & CWritingUFS) && (bp->b_flags & B_DELWRI)) {
829 ReleaseReadLock(&avc->lock);
836 ReleaseReadLock(&avc->lock);
838 aiovec.iov_base = bp_mapin(bp);
839 uio->uio_iov = &aiovec;
841 uio->uio_resid = aiovec.iov_len = bp->b_bcount;
842 uio->uio_offset = BBTOB(bp->b_blkno);
843 uio->uio_segflg = UIO_SYSSPACE;
844 uio->uio_limit = RLIM_INFINITY; /* we checked the limit earlier */
849 if (bp->b_flags & B_READ) {
850 uio->uio_fmode = FREAD;
851 error = afs_read(vp, uio, cr, 0, 0, 0);
853 uio->uio_fmode = FWRITE;
854 error = afs_write(vp, uio, 0, cr, 0);
859 if (acchk && error) {
860 cmn_err(CE_WARN, "vp 0x%x has error %d\n", vp, error);
867 bp->b_flags |= B_ERROR;
868 if ((uio->uio_fmode == FWRITE) && !avc->vc_error)
869 avc->vc_error = error;
877 afs_seek(OSI_VC_ARG(avc), ooff, noffp)
882 return *noffp < 0 ? EINVAL : 0;
885 #if !defined(AFS_SGI65_ENV)
886 /* Irix 6.5 uses addmap/delmap only for devices. */
889 afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, cr)
900 struct vnode *vp = AFSTOV(avc);
902 if (vp->v_flag & VNOMAP)
906 AFS_RWLOCK(vp, VRWLOCK_WRITE);
907 if (avc->mapcnt == 0) {
908 /* on first mapping add a open reference */
909 ObtainWriteLock(&avc->lock, 237);
910 avc->execsOrWriters++;
912 ReleaseWriteLock(&avc->lock);
914 avc->mapcnt += btoc(len);
915 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
919 /*ARGSUSED*/ static int
920 afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot, flags, acred)
931 struct vnode *vp = AFSTOV(avc);
932 register struct brequest *tb;
933 struct vrequest treq;
936 if (vp->v_flag & VNOMAP)
940 AFS_RWLOCK(vp, VRWLOCK_WRITE);
941 osi_Assert(avc->mapcnt > 0);
942 avc->mapcnt -= btoc(len);
943 osi_Assert(avc->mapcnt >= 0);
944 if (avc->mapcnt == 0) {
945 /* on last mapping push back and remove our reference */
946 osi_Assert(avc->execsOrWriters > 0);
947 osi_Assert(avc->opens > 0);
948 if (avc->f.m.LinkCount == 0) {
949 ObtainWriteLock(&avc->lock, 238);
951 PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG);
953 ReleaseWriteLock(&avc->lock);
958 afs_InitReq(&treq, acred);
960 /* do it yourself if daemons are all busy */
961 ObtainWriteLock(&avc->lock, 239);
962 code = afs_StoreOnLastReference(avc, &treq);
963 ReleaseWriteLock(&avc->lock);
964 /* BStore does CheckCode so we should also */
965 /* VNOVNODE is "acceptable" error code from close, since
966 * may happen when deleting a file on another machine while
967 * it is open here. */
968 if (code == VNOVNODE)
971 afs_StoreWarn(code, avc->f.fid.Fid.Volume, /* /dev/console */
974 code = afs_CheckCode(code, &treq, 52);
975 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
977 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
978 /* at least one daemon is idle, so ask it to do the store.
979 * Also, note that we don't lock it any more... */
980 tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred,
981 (afs_size_t) acred->cr_uid, 0L, (void *)0);
982 /* sleep waiting for the store to start, then retrieve error code */
983 while ((tb->flags & BUVALID) == 0) {
991 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
995 #endif /* ! AFS_SGI65_ENV */
1000 * Note - if mapping in an ELF interpreter, one can get called without vp
1001 * ever having been 'opened'
1003 #ifdef AFS_SGI65_ENV
1005 afs_map(OSI_VC_ARG(avc), off, len, prot, flags, cr, vpp)
1015 afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot, flags, cr)
1018 struct pregion *prp;
1021 u_int prot, maxprot;
1026 OSI_VC_CONVERT(avc);
1027 struct vnode *vp = AFSTOV(avc);
1028 struct vrequest treq;
1031 /* get a validated vcache entry */
1032 afs_InitReq(&treq, cr);
1033 error = afs_VerifyVCache(avc, &treq);
1035 return afs_CheckCode(error, &treq, 53);
1037 osi_FlushPages(avc, cr); /* ensure old pages are gone */
1038 #ifdef AFS_SGI65_ENV
1039 /* If the vnode is currently opened for write, there's the potential
1040 * that this mapping might (now or in the future) have PROT_WRITE.
1041 * So assume it does and we'll have to call afs_StoreOnLastReference.
1043 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1044 ObtainWriteLock(&avc->lock, 501);
1045 if (avc->execsOrWriters > 0) {
1046 avc->execsOrWriters++;
1048 avc->mapcnt++; /* count eow's due to mappings. */
1050 ReleaseWriteLock(&avc->lock);
1051 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1053 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1056 fs_map_subr(vp, (off_t) avc->f.m.Length, (u_int) avc->f.m.Mode, off, prp,
1057 *addrp, len, prot, maxprot, flags, cr);
1059 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1060 #endif /* AFS_SGI65_ENV */
1061 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vp,
1062 #ifdef AFS_SGI65_ENV
1063 ICL_TYPE_POINTER, NULL,
1065 ICL_TYPE_POINTER, *addrp,
1067 ICL_TYPE_INT32, len, ICL_TYPE_INT32, off);
1072 extern afs_rwlock_t afs_xvcache;
1073 extern afs_lock_t afs_xdcache;
1074 #ifdef AFS_SGI64_ENV
1079 afs_xinactive(OSI_VC_ARG(avc), acred)
1081 struct ucred *acred;
1084 OSI_VC_CONVERT(avc);
1085 vnode_t *vp = (vnode_t *) avc;
1086 int mapcnt = avc->mapcnt; /* We just clear off this many. */
1088 AFS_STATCNT(afs_inactive);
1091 if (!(vp->v_flag & VINACT) || (vp->v_count > 0)) {
1092 /* inactive was already done, or someone did a VN_HOLD; just return */
1093 vp->v_flag &= ~VINACT;
1095 #ifdef AFS_SGI64_ENV
1096 return VN_INACTIVE_CACHE;
1101 osi_Assert((vp->v_flag & VSHARE) == 0);
1102 vp->v_flag &= ~VINACT;
1103 /* Removed broadcast to waiters, since no one ever will. Only for vnodes
1108 #ifdef AFS_SGI65_ENV
1109 /* In Irix 6.5, the last unmap of a dirty mmap'd file does not
1110 * get an explicit vnode op. Instead we only find out at VOP_INACTIVE.
1112 if (!afs_rwlock_nowait((vnode_t *) avc, VRWLOCK_WRITE)) {
1113 return VN_INACTIVE_CACHE;
1115 if (NBObtainWriteLock(&avc->lock, 502)) {
1116 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1117 return VN_INACTIVE_CACHE;
1119 if (avc->f.states & CUnlinked) {
1120 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1121 avc->f.states |= CUnlinkedDel;
1122 ReleaseWriteLock(&avc->lock);
1123 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1125 ReleaseWriteLock(&avc->lock);
1126 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1127 afs_remunlink(avc, 1); /* ignore any return code */
1129 return VN_INACTIVE_CACHE;
1131 if ((avc->f.states & CDirty) || (avc->execsOrWriters > 0)) {
1132 /* File either already has dirty chunks (CDirty) or was mapped at
1133 * time in its life with the potential for being written into.
1134 * Note that afs_close defers storebacks if the vnode's ref count
1138 struct vrequest treq;
1139 if (!afs_InitReq(&treq, acred)) {
1143 avc->execsOrWriters -= mapcnt - 1;
1144 avc->opens -= mapcnt - 1;
1145 avc->mapcnt -= mapcnt;
1146 code = afs_StoreOnLastReference(avc, &treq);
1147 /* The following behavior mimics the behavior in afs_close. */
1148 if (code == VNOVNODE || code == ENOENT)
1153 "AFS: Failed to store FID (%x:%lu.%lu.%lu) in VOP_INACTIVE, error = %d\n",
1154 (int)(avc->f.fid.Cell) & 0xffffffff,
1155 avc->f.fid.Fid.Volume, avc->f.fid.Fid.Vnode,
1156 avc->f.fid.Fid.Unique, code);
1158 afs_InvalidateAllSegments(avc);
1162 code = (vp->v_count == 0);
1164 /* If the vnode is now in use by someone else, return early. */
1166 ReleaseWriteLock(&avc->lock);
1167 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1168 return VN_INACTIVE_CACHE;
1174 osi_Assert((avc->f.states & (CCore | CMAPPED)) == 0);
1180 ReleaseWriteLock(&avc->lock);
1181 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1184 * If someone unlinked a file and this is the last hurrah -
1185 * nuke all the pages.
1187 if (avc->f.m.LinkCount == 0) {
1189 PTOSSVP(vp, (off_t) 0, (off_t) MAXLONG);
1192 #ifndef AFS_SGI65_ENV
1193 osi_Assert(avc->mapcnt == 0);
1194 afs_chkpgoob(&avc->v, btoc(avc->f.m.Length));
1196 avc->f.states &= ~CDirty; /* Give up on store-backs */
1197 if (avc->f.states & CUnlinked) {
1198 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1199 avc->f.states |= CUnlinkedDel;
1201 afs_remunlink(avc, 1); /* ignore any return code */
1205 #ifdef AFS_SGI64_ENV
1206 return VN_INACTIVE_CACHE;
1211 afs_reclaim(OSI_VC_DECL(avc), int flag)
1213 #ifdef AFS_SGI64_ENV
1214 /* Get's called via VOP_RELCAIM in afs_FlushVCache to clear repl_vnodeops */
1217 panic("afs_reclaim");
1222 afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1225 struct vcache *avc = VTOAFS(vp);
1227 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1228 avc->vc_locktrips++;
1232 psema(&avc->vc_rwlock, PINOD);
1234 avc->vc_rwlockid = OSI_GET_LOCKID();
1238 afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1241 struct vcache *avc = VTOAFS(vp);
1244 osi_Assert(OSI_GET_LOCKID() == avc->vc_rwlockid);
1245 if (avc->vc_locktrips > 0) {
1246 --avc->vc_locktrips;
1249 avc->vc_rwlockid = OSI_NO_LOCKID;
1250 vsema(&avc->vc_rwlock);
1254 /* The flag argument is for symmetry with the afs_rwlock and afs_rwunlock
1255 * calls. SGI currently only uses the flag to assert if the unlock flag
1256 * does not match the corresponding lock flag. But they may start using this
1257 * flag for a real rw lock at some time.
1260 afs_rwlock_nowait(vnode_t * vp, AFS_RWLOCK_T flag)
1262 struct vcache *avc = VTOAFS(vp);
1265 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1266 avc->vc_locktrips++;
1269 if (cpsema(&avc->vc_rwlock)) {
1270 avc->vc_rwlockid = OSI_GET_LOCKID();
1276 #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR)
1278 afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1281 afs_fid2_t *afid = (afs_fid2_t *) fidp;
1282 OSI_VC_CONVERT(avc);
1284 osi_Assert(sizeof(fid_t) >= sizeof(afs_fid2_t));
1285 afid->af_len = sizeof(afs_fid2_t) - sizeof(afid->af_len);
1287 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1288 afid->af_cell = tcell->cellIndex & 0xffff;
1289 afs_PutCell(tcell, READ_LOCK);
1291 afid->af_volid = avc->f.fid.Fid.Volume;
1292 afid->af_vno = avc->f.fid.Fid.Vnode;
1293 afid->af_uniq = avc->f.fid.Fid.Unique;
1298 /* Only use so far is in checkpoint/restart for IRIX 6.4. In ckpt_fid, a
1299 * return of ENOSYS would make the code fail over to VOP_FID. We can't let
1300 * that happen, since we do a VN_HOLD there in the expectation that
1301 * posthandle will be called to release the vnode.
1303 * afs_fid2 is used to support the R5000 workarounds (_R5000_CVT_WAR)
1306 afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1308 #if defined(_R5000_CVT_WAR)
1309 extern int R5000_cvt_war;
1319 #endif /* AFS_SGI64_ENV && CKPT */
1323 * check for any pages hashed that shouldn't be!
1324 * Only valid if PGCACHEDEBUG is set in os/page.c
1325 * Drop the global lock here, since we may not actually do the call.
1328 afs_chkpgoob(vnode_t * vp, pgno_t pgno)
1333 pfindanyoob(vp, pgno);
1341 #ifdef AFS_SGI64_ENV
1342 #define AFS_MP_VC_ARG(A) bhv_desc_t A
1344 #define AFS_MP_VC_ARG(A) vnode_t A
1347 #ifdef AFS_SGI64_ENV
1349 mp_afs_open(bhv_desc_t * bhp, vnode_t ** a, mode_t b, struct cred *c)
1352 mp_afs_open(vnode_t ** a, mode_t b, struct cred *c)
1357 #ifdef AFS_SGI64_ENV
1358 rv = afs_lockedvnodeops.vop_open(bhp, a, b, c);
1360 rv = afs_lockedvnodeops.vop_open(a, b, c);
1366 #if defined(AFS_SGI64_ENV)
1367 #if defined(AFS_SGI65_ENV)
1369 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, struct cred *d)
1372 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e,
1377 mp_afs_close(AFS_MP_VC_ARG(*a), int b, lastclose_t c, off_t d, struct cred *e)
1382 rv = afs_lockedvnodeops.vop_close(a, b, c, d
1383 #if !defined(AFS_SGI65_ENV)
1385 #if defined(AFS_SGI64_ENV)
1395 #ifdef AFS_SGI64_ENV
1397 mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1401 mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1406 #ifdef AFS_SGI64_ENV
1407 rv = afs_lockedvnodeops.vop_read(a, b, c, d, f);
1409 rv = afs_lockedvnodeops.vop_read(a, b, c, d);
1416 #ifdef AFS_SGI64_ENV
1418 mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1422 mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1427 #ifdef AFS_SGI64_ENV
1428 rv = afs_lockedvnodeops.vop_write(a, b, c, d, f);
1430 rv = afs_lockedvnodeops.vop_write(a, b, c, d);
1437 mp_afs_ioctl(AFS_MP_VC_ARG(*a), int b, void *c, int d, struct cred *e, int *f
1438 #ifdef AFS_SGI65_ENV
1439 , struct vopbd *vbds
1445 rv = afs_lockedvnodeops.vop_ioctl(a, b, c, d, e, f
1446 #ifdef AFS_SGI65_ENV
1455 mp_fs_setfl(AFS_MP_VC_ARG(*a), int b, int c, struct cred *d)
1459 rv = afs_lockedvnodeops.vop_setfl(a, b, c, d);
1465 mp_afs_getattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1469 rv = afs_lockedvnodeops.vop_getattr(a, b, c, d);
1475 mp_afs_setattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1479 rv = afs_lockedvnodeops.vop_setattr(a, b, c, d);
1485 mp_afs_access(AFS_MP_VC_ARG(*a), int b,
1486 #ifndef AFS_SGI65_ENV
1493 rv = afs_lockedvnodeops.vop_access(a, b,
1494 #ifndef AFS_SGI65_ENV
1503 mp_afs_lookup(AFS_MP_VC_ARG(*a), char *b, vnode_t ** c, struct pathname *d,
1504 int e, vnode_t * f, struct cred *g)
1508 rv = afs_lockedvnodeops.vop_lookup(a, b, c, d, e, f, g);
1513 #ifdef AFS_SGI64_ENV
1515 mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, int d, int e,
1516 vnode_t ** f, struct cred *g)
1519 mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, enum vcexcl d,
1520 int e, vnode_t ** f, struct cred *g)
1525 rv = afs_lockedvnodeops.vop_create(a, b, c, d, e, f, g);
1531 mp_afs_remove(AFS_MP_VC_ARG(*a), char *b, struct cred *c)
1535 rv = afs_lockedvnodeops.vop_remove(a, b, c);
1541 mp_afs_link(AFS_MP_VC_ARG(*a), vnode_t * b, char *c, struct cred *d)
1545 rv = afs_lockedvnodeops.vop_link(a, b, c, d);
1551 mp_afs_rename(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, char *d,
1552 struct pathname *e, struct cred *f)
1556 rv = afs_lockedvnodeops.vop_rename(a, b, c, d, e, f);
1562 mp_afs_mkdir(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, vnode_t ** d,
1567 rv = afs_lockedvnodeops.vop_mkdir(a, b, c, d, e);
1573 mp_afs_rmdir(AFS_MP_VC_ARG(*a), char *b, vnode_t * c, struct cred *d)
1577 rv = afs_lockedvnodeops.vop_rmdir(a, b, c, d);
1583 mp_afs_readdir(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c, int *d)
1587 rv = afs_lockedvnodeops.vop_readdir(a, b, c, d);
1593 mp_afs_symlink(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, char *d,
1598 rv = afs_lockedvnodeops.vop_symlink(a, b, c, d, e);
1604 mp_afs_readlink(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c)
1608 rv = afs_lockedvnodeops.vop_readlink(a, b, c);
1614 mp_afs_fsync(AFS_MP_VC_ARG(*a), int b, struct cred *c
1615 #ifdef AFS_SGI65_ENV
1616 , off_t start, off_t stop
1622 rv = afs_lockedvnodeops.vop_fsync(a, b, c
1623 #ifdef AFS_SGI65_ENV
1632 mp_afs_inactive(AFS_MP_VC_ARG(*a), struct cred *b)
1635 afs_lockedvnodeops.vop_inactive(a, b);
1641 mp_afs_fid(AFS_MP_VC_ARG(*a), struct fid **b)
1645 rv = afs_lockedvnodeops.vop_fid(a, b);
1651 mp_afs_fid2(AFS_MP_VC_ARG(*a), struct fid *b)
1655 rv = afs_lockedvnodeops.vop_fid2(a, b);
1661 mp_afs_rwlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1664 afs_rwlock(a, VRWLOCK_WRITE);
1669 mp_afs_rwunlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1672 afs_rwunlock(a, VRWLOCK_WRITE);
1677 mp_afs_seek(AFS_MP_VC_ARG(*a), off_t b, off_t * c)
1681 rv = afs_lockedvnodeops.vop_seek(a, b, c);
1687 mp_fs_cmp(AFS_MP_VC_ARG(*a), vnode_t * b)
1691 rv = afs_lockedvnodeops.vop_cmp(a, b);
1697 mp_afs_frlock(AFS_MP_VC_ARG(*a), int b, struct flock *c, int d, off_t e,
1698 #ifdef AFS_SGI65_ENV
1705 rv = afs_lockedvnodeops.vop_frlock(a, b, c, d, e,
1706 #ifdef AFS_SGI65_ENV
1715 mp_afs_realvp(AFS_MP_VC_ARG(*a), vnode_t ** b)
1719 rv = afs_lockedvnodeops.vop_realvp(a, b);
1725 mp_afs_bmap(AFS_MP_VC_ARG(*a), off_t b, ssize_t c, int d, struct cred *e,
1726 struct bmapval *f, int *g)
1730 rv = afs_lockedvnodeops.vop_bmap(a, b, c, d, e, f, g);
1736 mp_afs_strategy(AFS_MP_VC_ARG(*a), struct buf *b)
1740 afs_lockedvnodeops.vop_strategy(a, b);
1745 #ifdef AFS_SGI65_ENV
1747 mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, size_t c, mprot_t d, u_int e,
1748 struct cred *f, vnode_t ** g)
1751 mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, char **d, size_t e,
1752 u_int f, u_int g, u_int h, struct cred *i)
1757 rv = afs_lockedvnodeops.vop_map(a, b, c, d, e, f, g
1758 #ifndef AFS_SGI65_ENV
1767 #ifndef AFS_SGI65_ENV
1768 /* As of Irix 6.5, addmap and delmap are only for devices */
1770 mp_afs_addmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1771 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1775 rv = afs_lockedvnodeops.vop_addmap(a, b, c, d, e, f, g, h, i);
1781 mp_afs_delmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1782 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1786 rv = afs_lockedvnodeops.vop_delmap(a, b, c, d, e, f, g, h, i);
1790 #endif /* ! AFS_SGI65_ENV */
1793 mp_fs_poll(AFS_MP_VC_ARG(*a), short b, int c, short *d, struct pollhead **e
1794 #ifdef AFS_SGI65_ENV
1801 rv = afs_lockedvnodeops.vop_poll(a, b, c, d, e
1802 #ifdef AFS_SGI65_ENV
1811 struct vnodeops Afs_vnodeops = {
1812 #ifdef AFS_SGI64_ENV
1813 #ifdef AFS_SGI65_ENV
1814 BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE),
1816 VNODE_POSITION_BASE,
1847 fs_nosys, /* realvp */
1851 #ifdef AFS_SGI65_ENV
1852 fs_noerr, /* addmap - devices only */
1853 fs_noerr, /* delmap - devices only */
1858 mp_fs_poll, /* poll */
1859 fs_nosys, /* dump */
1861 fs_nosys, /* allocstore */
1862 fs_nosys, /* fcntl */
1863 afs_reclaim, /* reclaim */
1864 fs_nosys, /* attr_get */
1865 fs_nosys, /* attr_set */
1866 fs_nosys, /* attr_remove */
1867 fs_nosys, /* attr_list */
1868 #ifdef AFS_SGI64_ENV
1869 #ifdef AFS_SGI65_ENV
1871 (vop_link_removed_t) fs_noval,
1874 fs_flushinval_pages,
1878 (vop_commit_t) fs_nosys,
1879 (vop_readbuf_t) fs_nosys,
1887 struct vnodeops *afs_ops = &Afs_vnodeops;
1891 #if defined(AFS_SGI62_ENV) && defined(AFS_SGI_DUAL_FS_CACHE)
1892 /* Support for EFS and XFS caches. The assumption here is that the size of
1893 * a cache file also does not exceed 32 bits.
1896 /* Initialized in osi_InitCacheFSType(). Used to determine inode type. */
1897 int afs_CacheFSType = -1;
1898 vnodeops_t *afs_efs_vnodeopsp;
1899 vnodeops_t *afs_xfs_vnodeopsp;
1900 vnode_t *(*afs_IGetVnode) (ino_t);
1902 extern vnode_t *afs_EFSIGetVnode(ino_t); /* defined in osi_file.c */
1903 extern vnode_t *afs_XFSIGetVnode(ino_t); /* defined in osi_file.c */
1905 extern afs_lock_t afs_xosi; /* lock is for tvattr */
1907 /* Initialize the cache operations. Called while initializing cache files. */
1909 afs_InitDualFSCacheOps(struct vnode *vp)
1911 static int inited = 0;
1919 swp = vfs_getvfssw("xfs");
1921 afs_xfs_vnodeopsp = swp->vsw_vnodeops;
1923 if (vp && vp->v_op == afs_xfs_vnodeopsp) {
1924 afs_CacheFSType = AFS_SGI_XFS_CACHE;
1925 afs_IGetVnode = afs_XFSIGetVnode;
1932 osi_Panic("osi_InitCacheFSType: Can't find fstype for vnode 0x%llx\n",
1937 VnodeToIno(vnode_t * vp)
1942 MObtainWriteLock(&afs_xosi, 579);
1943 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
1945 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1948 osi_Panic("VnodeToIno");
1950 MReleaseWriteLock(&afs_xosi);
1951 return vattr.va_nodeid;
1955 VnodeToDev(vnode_t * vp)
1960 MObtainWriteLock(&afs_xosi, 580);
1961 vattr.va_mask = AT_FSID | AT_NODEID; /* quick return using this mask. */
1963 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1966 osi_Panic("VnodeToDev");
1968 MReleaseWriteLock(&afs_xosi);
1969 return (dev_t) vattr.va_fsid;
1973 VnodeToSize(vnode_t * vp)
1978 MObtainWriteLock(&afs_xosi, 581);
1979 vattr.va_mask = AT_SIZE;
1981 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1984 osi_Panic("VnodeToSize");
1986 MReleaseWriteLock(&afs_xosi);
1987 return vattr.va_size;
1989 #endif /* 6.2 and dual fs cache */
1990 #endif /* AFS_SGI62_ENV */