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"
19 #include "../afs/sysincludes.h" /* Standard vendor system headers */
20 #include "../afs/afsincludes.h" /* Afs-based standard headers */
21 #include "../afs/afs_stats.h" /* statistics */
22 #include "../sys/flock.h"
23 #include "../afs/nfsclient.h"
25 /* AFSBSIZE must be at least the size of a page, else the client will hang.
26 * For 64 bit platforms, the page size is more than 8K.
28 #define AFSBSIZE _PAGESZ
29 extern struct afs_exporter *root_exported;
30 extern void afs_chkpgoob(vnode_t *, pgno_t);
32 static void afs_strategy();
33 static int afs_xread(), afs_xwrite();
34 static int afs_xbmap(), afs_map(), afs_reclaim();
36 static int afs_addmap(), afs_delmap();
38 extern int afs_open(), afs_close(), afs_ioctl(), afs_getattr(), afs_setattr();
39 extern int afs_access(), afs_lookup();
40 extern int afs_create(), afs_remove(), afs_link(), afs_rename();
41 extern int afs_mkdir(), afs_rmdir(), afs_readdir();
42 extern int afs_symlink(), afs_readlink(), afs_fsync(), afs_fid(), afs_frlock();
43 static int afs_seek(OSI_VC_DECL(a), off_t b, off_t *c);
45 extern int afs_xinactive();
47 extern void afs_xinactive();
50 extern void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b);
51 extern void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T b);
53 extern int afs_fid2();
55 static int afsrwvp(register struct vcache *avc,
56 register struct uio *uio,
66 static void mp_afs_rwlock(OSI_VN_DECL(a), AFS_RWLOCK_T b);
67 static void mp_afs_rwunlock(OSI_VN_DECL(a), AFS_RWLOCK_T b);
68 struct vnodeops afs_lockedvnodeops =
70 struct vnodeops Afs_vnodeops =
75 BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE),
108 fs_nosys, /* realvp */
113 fs_noerr, /* addmap - devices only */
114 fs_noerr, /* delmap - devices only */
122 fs_nosys, /* allocstore */
123 fs_nosys, /* fcntl */
124 afs_reclaim, /* reclaim */
125 fs_nosys, /* attr_get */
126 fs_nosys, /* attr_set */
127 fs_nosys, /* attr_remove */
128 fs_nosys, /* attr_list */
132 (vop_link_removed_t)fs_noval,
139 (vop_commit_t)fs_nosys,
140 (vop_readbuf_t)fs_nosys,
149 struct vnodeops *afs_ops = &Afs_vnodeops;
152 int afs_frlock(OSI_VN_DECL(vp), int cmd, struct flock *lfp, int flag,
164 get_current_flid(&flid);
169 * Since AFS doesn't support byte-wise locks (and simply
170 * says yes! we handle byte locking locally only.
171 * This makes lots of things work much better
172 * XXX This doesn't properly handle moving from a
173 * byte-wise lock up to a full file lock (we should
174 * remove the byte locks ..) Of course neither did the
175 * regular AFS way ...
177 * For GETLK we do a bit more - we first check any byte-wise
178 * locks - if none then check for full AFS file locks
180 if (cmd == F_GETLK || lfp->l_whence != 0 || lfp->l_start != 0 ||
181 (lfp->l_len != MAXEND && lfp->l_len != 0)) {
182 AFS_RWLOCK(vp, VRWLOCK_WRITE);
185 error = fs_frlock(OSI_VN_ARG(vp), cmd, lfp, flag, offset,
188 error = fs_frlock(vp, cmd, lfp, flag, offset, cr);
191 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
192 if (error || cmd != F_GETLK)
194 if (lfp->l_type != F_UNLCK)
195 /* found some blocking lock */
197 /* fall through to check for full AFS file locks */
200 /* map BSD style to plain - we don't call reclock()
201 * and its only there that the difference is important
225 error = convoff(vp, lfp, 0, offset
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....
266 static int afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr, flp)
269 static int afs_xread(OSI_VC_ARG(avc), uiop, ioflag, cr)
279 osi_Assert(avc->v.v_count > 0);
280 if (avc->v.v_type != VREG)
285 if (!(ioflag & IO_ISLOCKED))
286 AFS_RWLOCK((vnode_t*)avc, VRWLOCK_READ);
288 code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr, flp);
290 if (!(ioflag & IO_ISLOCKED))
291 AFS_RWUNLOCK((vnode_t*)avc, VRWLOCK_READ);
294 code = afsrwvp(avc, uiop, UIO_READ, ioflag, cr);
301 static int afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr, flp)
304 static int afs_xwrite(OSI_VC_ARG(avc), uiop, ioflag, cr)
314 osi_Assert(avc->v.v_count > 0);
315 if (avc->v.v_type != VREG)
318 if (ioflag & IO_APPEND)
319 uiop->uio_offset = avc->m.Length;
322 if (!(ioflag & IO_ISLOCKED))
323 AFS_RWLOCK(((vnode_t*)avc), VRWLOCK_WRITE);
325 code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr, flp);
327 if (!(ioflag & IO_ISLOCKED))
328 AFS_RWUNLOCK((vnode_t*)avc, VRWLOCK_WRITE);
331 code = afsrwvp(avc, uiop, UIO_WRITE, ioflag, cr);
337 static int prnra = 0;
338 static int acchk = 0;
339 static int acdrop = 0;
341 static int afsrwvp(register struct vcache *avc,
342 register struct uio *uio,
352 register struct vnode *vp = AFSTOV(avc);
357 ssize_t bsize, rem, len;
359 struct bmapval bmv[2];
360 int nmaps, didFakeOpen = 0;
361 struct vrequest treq;
365 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
366 (OSI_GET_LOCKID() == avc->vc_rwlockid));
369 newoff = uio->uio_resid + uio->uio_offset;
370 if (uio->uio_resid <= 0) {
373 if (uio->uio_offset < 0
374 || (signed long)newoff < 0) {
377 if (ioflag & IO_DIRECT)
380 if (rw == UIO_WRITE && vp->v_type == VREG
381 && newoff > uio->uio_limit) {
385 afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc,
386 ICL_TYPE_INT32, ioflag,
387 ICL_TYPE_INT32, rw, ICL_TYPE_INT32, 0);
389 /* get a validated vcache entry */
390 afs_InitReq(&treq, cr);
391 error = afs_VerifyVCache(avc, &treq);
392 if (error) 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) {
401 if (!afs_AccessOK(avc, PRSFS_READ, &treq,
402 CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ))
406 * To handle anonymous calls to VOP_STRATEGY from afs_sync/sync/bdflush
407 * we need better than the callers credentials. So we squirrel away
408 * the last writers credentials
410 if (rw == UIO_WRITE || (rw == UIO_READ && avc->cred == NULL)) {
411 ObtainWriteLock(&avc->lock,92);
416 ReleaseWriteLock(&avc->lock);
420 * We have to bump the open/exwriters field here
421 * courtesy of the nfs xlator
422 * because there're no open/close nfs rpc's to call our afs_open/close.
424 if (root_exported && rw == UIO_WRITE) {
425 ObtainWriteLock(&avc->lock,234);
430 ReleaseWriteLock(&avc->lock);
434 if (rw == UIO_WRITE) {
435 ObtainWriteLock(&avc->lock,330);
436 avc->states |= CDirty;
437 ReleaseWriteLock(&avc->lock);
443 /* If v_dpages is set SGI 5.3 will convert those pages to
444 * B_DELWRI in chunkread and getchunk. Write the pages out
445 * before we trigger that behavior. For 6.1, dirty pages stay
446 * around too long and we should get rid of them as quickly
449 while (VN_GET_DPAGES(vp))
453 error = avc->vc_error;
456 bsize = AFSBSIZE; /* why not?? */
457 off = uio->uio_offset % bsize;
458 bn = BTOBBT(uio->uio_offset - off);
460 * decrease bsize - otherwise we will
461 * get 'extra' pages in the cache for this
462 * vnode that we would need to flush when
463 * calling e.g. ptossvp.
464 * So we can use Length in ptossvp,
465 * we make sure we never go more than to the file size
466 * rounded up to a page boundary.
467 * That doesn't quite work, since we may get a page hashed to
468 * the vnode w/o updating the length. Thus we always use
469 * MAXLONG in ptossvp to be safe.
471 if (rw == UIO_READ) {
473 * read/paging in a normal file
475 rem = avc->m.Length - (afs_int32)uio->uio_offset;
480 * compute minimum of rest of block and rest of file
482 cnt = MIN(bsize - off, rem);
483 osi_Assert((off + cnt) <= bsize);
484 bsize = ctob(btoc(off + cnt));
487 bmv[0].bn = bmv[0].offset = bn;
489 bmv[0].bsize = bsize;
491 bmv[0].pbsize = MIN(cnt, uio->uio_resid);
494 bmv[0].pbdev = vp->v_rdev;
495 bmv[0].pmp = uio->uio_pmp;
499 * initiate read-ahead if it looks like
500 * we are reading sequentially OR they want
501 * more than one 'bsize' (==AFSBSIZE) worth
502 * XXXHack - to avoid DELWRI buffers we can't
503 * do read-ahead on any file that has potentially
506 if ((avc->lastr + BTOBB(AFSBSIZE) == bn ||
507 uio->uio_resid > AFSBSIZE)
509 && (!AFS_VN_MAPPED(vp))
510 #else /* AFS_SGI61_ENV */
511 && ((vp->v_flag & VWASMAP) == 0)
512 #endif /* AFS_SGI61_ENV */
517 bmv[1].bn = bmv[1].offset = bn + len;
518 osi_Assert((BBTOB(bn + len) % bsize) == 0);
519 acnt = MIN(bsize, rem);
520 bsize = ctob(btoc(acnt));
525 bmv[1].bsize = bsize;
527 bmv[1].pbsize = acnt;
529 bmv[1].pmp = uio->uio_pmp;
530 bmv[1].pbdev = vp->v_rdev;
536 printf("NRA:vp 0x%x lastr %d bn %d len %d cnt %d bsize %d rem %d resid %d\n",
538 len, cnt, bsize, rem,
543 bp = chunkread(vp, bmv, nmaps, cr);
545 * If at a chunk boundary, start prefetch of next chunk.
547 if (counter == 0 || AFS_CHUNKOFFSET(off) == 0) {
549 ObtainWriteLock(&avc->lock,562);
550 tdc = afs_FindDCache(avc, off);
552 if (!(tdc->mflags & DFNextStarted))
553 afs_PrefetchChunk(avc, tdc, cr, &treq);
556 ReleaseWriteLock(&avc->lock);
562 * writing a normal file
565 * Purge dirty chunks of file if there are too many dirty chunks.
566 * Inside the write loop, we only do this at a chunk boundary.
567 * Clean up partial chunk if necessary at end of loop.
569 if (counter > 0 && AFS_CHUNKOFFSET(uio->uio_offset) == 0) {
571 ObtainWriteLock(&avc->lock,90);
572 error = afs_DoPartialWrite(avc, &treq);
574 avc->states |= CDirty;
575 ReleaseWriteLock(&avc->lock);
581 cnt = MIN(bsize - off, uio->uio_resid);
582 bsize = ctob(btoc(off + cnt));
588 bmv[0].bsize = bsize;
592 bmv[0].pmp = uio->uio_pmp;
596 bp = getchunk(vp, bmv, cr);
598 bp = chunkread(vp, bmv, 1, cr);
600 avc->m.Date = osi_Time(); /* Set file date (for ranlib) */
602 if (bp->b_flags & B_ERROR) {
604 * Since we compile -signed, b_error is a signed
605 * char when it should ba an unsigned char.
606 * This can cause some errors codes to be interpreted
609 error = (unsigned char)(bp->b_error);
613 if (acchk && error) {
614 cmn_err(CE_WARN, "bp 0x%x has error %d\n", bp, error);
623 osi_Assert(bp->b_error == 0);
625 if (uio->uio_segflg != UIO_NOSPACE)
627 AFS_UIOMOVE(bp->b_un.b_addr + bmv[0].pboff, cnt, rw, uio, error);
628 if (rw == UIO_READ || error) {
629 if (bp->b_flags & B_DELWRI) {
635 * m.Length is the maximum number of bytes known to be in the file.
636 * Make sure it is at least as high as the last byte we just wrote
639 if (avc->m.Length < (afs_int32)uio->uio_offset) {
641 ObtainWriteLock(&avc->lock,235);
642 avc->m.Length = uio->uio_offset;
643 ReleaseWriteLock(&avc->lock);
646 if (uio->uio_fmode & FSYNC) {
648 } else if (off + cnt < bsize) {
649 bawrite(bp); /* was bdwrite */
651 bp->b_flags |= B_AGE;
655 * Since EIO on an unlinked file is non-intuitive - give some
659 if (avc->m.LinkCount == 0)
660 cmn_err(CE_WARN,"AFS: Process pid %d write error %d writing to unlinked file.",
661 OSI_GET_CURRENT_PID(), error);
664 } while (!error && uio->uio_resid > 0);
665 afs_chkpgoob(&avc->v, btoc(avc->m.Length));
669 if (rw == UIO_WRITE && error == 0 && (avc->states & CDirty)) {
670 ObtainWriteLock(&avc->lock, 405);
671 error = afs_DoPartialWrite(avc, &treq);
672 ReleaseWriteLock(&avc->lock);
677 if (((ioflag & IO_SYNC) || (ioflag & IO_DSYNC)) && (rw == UIO_WRITE) &&
678 !AFS_NFSXLATORREQ(cr)) {
679 error = afs_fsync(avc, 0, cr);
681 #else /* AFS_SGI61_ENV */
682 if ((ioflag & IO_SYNC) && (rw == UIO_WRITE) && !AFS_NFSXLATORREQ(cr)) {
683 error = afs_fsync(avc, 0, cr);
685 #endif /* AFS_SGI61_ENV */
688 ObtainWriteLock(&avc->lock,236);
689 afs_FakeClose(avc, cr); /* XXXX For nfs trans XXXX */
690 ReleaseWriteLock(&avc->lock);
692 afs_Trace4(afs_iclSetp, CM_TRACE_GRDWR, ICL_TYPE_POINTER, avc,
693 ICL_TYPE_INT32, ioflag,
694 ICL_TYPE_INT32, rw, ICL_TYPE_INT32, error);
699 int afs_xbmap(OSI_VC_ARG(avc), offset, count, flag, cr, bmv, nbmv)
708 int bsize; /* server's block size in bytes */
714 off = offset % bsize; /* offset into block */
715 bmv->bn = BTOBBT(offset - off);
716 bmv->offset = bmv->bn;
718 rem = avc->m.Length - offset;
722 cnt = MIN(bsize - off, rem);
725 * It is benign to ignore *nbmv > 1, since it is only for requesting
730 * Don't map more than up to next page if at end of file
731 * See comment in afsrwvp
733 osi_Assert((off + cnt) <= bsize);
734 bsize = ctob(btoc(off + cnt));
735 bmv->pbsize = MIN(cnt, count);
739 bmv->pbdev = avc->v.v_rdev;
742 bmv->length = BTOBBT(bsize);
748 * called out of chunkread from afs_xread & clusterwrite to push dirty
749 * pages back - this routine
750 * actually does the reading/writing by calling afs_read/afs_write
751 * bp points to a set of pages that have been inserted into
752 * the page cache hashed on afs vp.
755 afs_strategy(OSI_VC_ARG(avc), bp)
765 vnode_t *vp = (vnode_t *)avc;
768 * We can't afford DELWRI buffers for 2 reasons:
769 * 1) Since we can call underlying EFS, we can require a
770 * buffer to flush a buffer. This leads to 2 potential
771 * recursions/deadlocks
772 * a) if all buffers are DELWRI afs buffers, then
773 * ngeteblk -> bwrite -> afs_strategy -> afs_write ->
774 * UFS_Write -> efs_write -> ngeteblk .... could
775 * recurse a long ways!
776 * b) brelse -> chunkhold which can call dchunkpush
777 * will look for any DELWRI buffers and call strategy
778 * on them. This can then end up via UFS_Write
781 * a) We never do bdwrite(s) on AFS buffers.
782 * b) We call pdflush with B_ASYNC
783 * c) in chunkhold where it can set a buffer DELWRI
784 * we immediatly do a clusterwrite for AFS vp's
785 * XXX Alas, 'c' got dropped in 5.1 so its possible to get DELWRI
786 * buffers if someone has mmaped the file and dirtied it then
787 * reads/faults it again.
788 * Instead - wherever we call chunkread/getchunk we check for a
789 * returned bp with DELWRI set, and write it out immediately
791 if (CheckLock(&avc->lock) && VN_GET_DBUF(vp)) {
792 printf("WARN: afs_strategy vp=%x, v_dbuf=%x bp=%x\n", vp,
793 VN_GET_DBUF(vp), bp);
795 bp->b_flags |= B_ERROR;
799 if (bp->b_error != 0)
800 printf("WARNING: afs_strategy3 vp=%x, bp=%x, err=%x\n", vp, bp, bp->b_error);
803 * To get credentials somewhat correct (we may be called from bdflush/
804 * sync) we use saved credentials in Vcache.
805 * We must hold them since someone else could change them
807 ObtainReadLock(&avc->lock);
808 if (bp->b_flags & B_READ) {
809 if (BBTOB(bp->b_blkno) >= avc->m.Length) {
810 /* we are responsible for zero'ing the page */
813 memset(c, 0, bp->b_bcount);
815 ReleaseReadLock(&avc->lock);
818 } else if ((avc->states & CWritingUFS) && (bp->b_flags & B_DELWRI)) {
820 ReleaseReadLock(&avc->lock);
827 ReleaseReadLock(&avc->lock);
829 aiovec.iov_base = bp_mapin(bp);
830 uio->uio_iov = &aiovec;
832 uio->uio_resid = aiovec.iov_len = bp->b_bcount;
833 uio->uio_offset = BBTOB(bp->b_blkno);
834 uio->uio_segflg = UIO_SYSSPACE;
835 uio->uio_limit = RLIM_INFINITY; /* we checked the limit earlier */
840 if (bp->b_flags & B_READ) {
841 uio->uio_fmode = FREAD;
842 error = afs_read(vp, uio, cr, 0, 0, 0);
844 uio->uio_fmode = FWRITE;
845 error = afs_write(vp, uio, 0, cr, 0);
850 if (acchk && error) {
851 cmn_err(CE_WARN, "vp 0x%x has error %d\n", vp, error);
858 bp->b_flags |= B_ERROR;
859 if ((uio->uio_fmode == FWRITE) && !avc->vc_error)
860 avc->vc_error = error;
867 static int afs_seek(OSI_VC_ARG(avc), ooff, noffp)
872 return *noffp < 0 ? EINVAL : 0;
875 #if !defined(AFS_SGI65_ENV)
876 /* Irix 6.5 uses addmap/delmap only for devices. */
878 static int afs_addmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot,
890 struct vnode *vp = AFSTOV(avc);
892 if (vp->v_flag & VNOMAP)
896 AFS_RWLOCK(vp, VRWLOCK_WRITE);
897 if (avc->mapcnt == 0) {
898 /* on first mapping add a open reference */
899 ObtainWriteLock(&avc->lock,237);
900 avc->execsOrWriters++;
902 ReleaseWriteLock(&avc->lock);
904 avc->mapcnt += btoc(len);
905 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
910 static int afs_delmap(OSI_VC_ARG(avc), off, prp, addr, len, prot, maxprot,
922 struct vnode *vp = AFSTOV(avc);
923 register struct brequest *tb;
924 struct vrequest treq;
927 if (vp->v_flag & VNOMAP)
931 AFS_RWLOCK(vp, VRWLOCK_WRITE);
932 osi_Assert(avc->mapcnt > 0);
933 avc->mapcnt -= btoc(len);
934 osi_Assert(avc->mapcnt >= 0);
935 if (avc->mapcnt == 0) {
936 /* on last mapping push back and remove our reference */
937 osi_Assert(avc->execsOrWriters > 0);
938 osi_Assert(avc->opens > 0);
939 if (avc->m.LinkCount == 0) {
940 ObtainWriteLock(&avc->lock,238);
942 PTOSSVP(vp, (off_t)0, (off_t)MAXLONG);
944 ReleaseWriteLock(&avc->lock);
949 afs_InitReq(&treq, acred);
951 /* do it yourself if daemons are all busy */
952 ObtainWriteLock(&avc->lock,239);
953 code = afs_StoreOnLastReference(avc, &treq);
954 ReleaseWriteLock(&avc->lock);
955 /* BStore does CheckCode so we should also */
956 /* VNOVNODE is "acceptable" error code from close, since
957 may happen when deleting a file on another machine while
959 if (code == VNOVNODE)
962 afs_StoreWarn(code, avc->fid.Fid.Volume, /* /dev/console */ 1);
964 code = afs_CheckCode(code, &treq, 52);
965 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
967 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
968 /* at least one daemon is idle, so ask it to do the store.
969 * Also, note that we don't lock it any more... */
970 tb = afs_BQueue(BOP_STORE, avc, 0, 1, acred,
971 (afs_size_t) acred->cr_uid, 0L, (void *) 0);
972 /* sleep waiting for the store to start, then retrieve error code */
973 while ((tb->flags & BUVALID) == 0) {
981 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
985 #endif /* ! AFS_SGI65_ENV */
990 * Note - if mapping in an ELF interpreter, one can get called without vp
991 * ever having been 'opened'
994 static int afs_map(OSI_VC_ARG(avc), off, len, prot, flags, cr, vpp)
1003 static int afs_map(OSI_VC_ARG(avc), off, prp, addrp, len, prot, maxprot,
1007 struct pregion *prp;
1010 u_int prot, maxprot;
1016 struct vnode *vp = AFSTOV(avc);
1017 struct vrequest treq;
1020 /* get a validated vcache entry */
1021 afs_InitReq(&treq, cr);
1022 error = afs_VerifyVCache(avc, &treq);
1023 if (error) return afs_CheckCode(error, &treq, 53);
1025 osi_FlushPages(avc, cr); /* ensure old pages are gone */
1026 #ifdef AFS_SGI65_ENV
1027 /* If the vnode is currently opened for write, there's the potential
1028 * that this mapping might (now or in the future) have PROT_WRITE.
1029 * So assume it does and we'll have to call afs_StoreOnLastReference.
1031 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1032 ObtainWriteLock(&avc->lock, 501);
1033 if (avc->execsOrWriters > 0) {
1034 avc->execsOrWriters ++;
1036 avc->mapcnt ++; /* count eow's due to mappings. */
1038 ReleaseWriteLock(&avc->lock);
1039 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1041 AFS_RWLOCK(vp, VRWLOCK_WRITE);
1043 error = fs_map_subr(vp, (off_t) avc->m.Length, (u_int)avc->m.Mode, off, prp,
1044 *addrp, len, prot, maxprot, flags, cr);
1046 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1047 #endif /* AFS_SGI65_ENV */
1048 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vp,
1049 #ifdef AFS_SGI65_ENV
1050 ICL_TYPE_POINTER, NULL,
1052 ICL_TYPE_POINTER, *addrp,
1054 ICL_TYPE_INT32, len, ICL_TYPE_INT32, off);
1059 extern afs_rwlock_t afs_xvcache;
1060 extern afs_lock_t afs_xdcache;
1061 #ifdef AFS_SGI64_ENV
1066 afs_xinactive(OSI_VC_ARG(avc), acred)
1068 struct ucred *acred;
1072 vnode_t *vp = (vnode_t *)avc;
1073 int mapcnt = avc->mapcnt; /* We just clear off this many. */
1075 AFS_STATCNT(afs_inactive);
1078 if (!(vp->v_flag & VINACT) || (vp->v_count > 0)) {
1079 /* inactive was already done, or someone did a VN_HOLD; just return */
1080 vp->v_flag &= ~VINACT;
1082 #ifdef AFS_SGI64_ENV
1083 return VN_INACTIVE_CACHE;
1088 osi_Assert((vp->v_flag & VSHARE) == 0);
1089 vp->v_flag &= ~VINACT;
1090 /* Removed broadcast to waiters, since no one ever will. Only for vnodes
1095 #ifdef AFS_SGI65_ENV
1096 /* In Irix 6.5, the last unmap of a dirty mmap'd file does not
1097 * get an explicit vnode op. Instead we only find out at VOP_INACTIVE.
1099 if (!afs_rwlock_nowait((vnode_t*)avc, VRWLOCK_WRITE)) {
1100 return VN_INACTIVE_CACHE;
1102 if (NBObtainWriteLock(&avc->lock, 502)) {
1103 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1104 return VN_INACTIVE_CACHE;
1106 if (avc->states & CUnlinked) {
1107 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1108 avc->states |= CUnlinkedDel;
1109 ReleaseWriteLock(&avc->lock);
1110 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1112 ReleaseWriteLock(&avc->lock);
1113 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1114 afs_remunlink(avc, 1); /* ignore any return code */
1116 return VN_INACTIVE_CACHE;
1118 if ((avc->states & CDirty) || (avc->execsOrWriters > 0)) {
1119 /* File either already has dirty chunks (CDirty) or was mapped at
1120 * time in its life with the potential for being written into.
1121 * Note that afs_close defers storebacks if the vnode's ref count
1125 struct vrequest treq;
1126 if (!afs_InitReq(&treq, acred)) {
1130 avc->execsOrWriters -= mapcnt - 1;
1131 avc->opens -= mapcnt - 1;
1132 avc->mapcnt -= mapcnt;
1133 code = afs_StoreOnLastReference(avc, &treq);
1134 /* The following behavior mimics the behavior in afs_close. */
1135 if (code == VNOVNODE || code == ENOENT)
1139 cmn_err(CE_WARN, "AFS: Failed to store FID (%x:%lu.%lu.%lu) in VOP_INACTIVE, error = %d\n",
1140 (int)(avc->fid.Cell) & 0xffffffff,
1141 avc->fid.Fid.Volume,
1142 avc->fid.Fid.Vnode, avc->fid.Fid.Unique,
1145 afs_InvalidateAllSegments(avc);
1149 code = (vp->v_count == 0);
1151 /* If the vnode is now in use by someone else, return early. */
1153 ReleaseWriteLock(&avc->lock);
1154 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1155 return VN_INACTIVE_CACHE;
1161 osi_Assert((avc->states & (CCore|CMAPPED)) == 0);
1167 ReleaseWriteLock(&avc->lock);
1168 AFS_RWUNLOCK(vp, VRWLOCK_WRITE);
1171 * If someone unlinked a file and this is the last hurrah -
1172 * nuke all the pages.
1174 if (avc->m.LinkCount == 0) {
1176 PTOSSVP(vp, (off_t)0, (off_t)MAXLONG);
1180 #ifndef AFS_SGI65_ENV
1181 osi_Assert(avc->mapcnt == 0);
1182 afs_chkpgoob(&avc->v, btoc(avc->m.Length));
1184 avc->states &= ~CDirty; /* Give up on store-backs */
1185 if (avc->states & CUnlinked) {
1186 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
1187 avc->states |= CUnlinkedDel;
1189 afs_remunlink(avc, 1); /* ignore any return code */
1193 #ifdef AFS_SGI64_ENV
1194 return VN_INACTIVE_CACHE;
1199 afs_reclaim(OSI_VC_DECL(avc), int flag)
1201 #ifdef AFS_SGI64_ENV
1202 /* Get's called via VOP_RELCAIM in afs_FlushVCache to clear repl_vnodeops*/
1205 panic("afs_reclaim");
1209 void afs_rwlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1212 struct vcache *avc = VTOAFS(vp);
1214 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1215 avc->vc_locktrips++;
1219 psema(&avc->vc_rwlock, PINOD);
1221 avc->vc_rwlockid = OSI_GET_LOCKID();
1224 void afs_rwunlock(OSI_VN_DECL(vp), AFS_RWLOCK_T flag)
1227 struct vcache *avc = VTOAFS(vp);
1230 osi_Assert(OSI_GET_LOCKID() == avc->vc_rwlockid);
1231 if (avc->vc_locktrips > 0) {
1232 --avc->vc_locktrips;
1235 avc->vc_rwlockid = OSI_NO_LOCKID;
1236 vsema(&avc->vc_rwlock);
1240 /* The flag argument is for symmetry with the afs_rwlock and afs_rwunlock
1241 * calls. SGI currently only uses the flag to assert if the unlock flag
1242 * does not match the corresponding lock flag. But they may start using this
1243 * flag for a real rw lock at some time.
1245 int afs_rwlock_nowait(vnode_t *vp, AFS_RWLOCK_T flag)
1247 struct vcache *avc = VTOAFS(vp);
1250 if (OSI_GET_LOCKID() == avc->vc_rwlockid) {
1251 avc->vc_locktrips++;
1254 if (cpsema(&avc->vc_rwlock)) {
1255 avc->vc_rwlockid = OSI_GET_LOCKID();
1261 #if defined(AFS_SGI64_ENV) && defined(CKPT) && !defined(_R5000_CVT_WAR)
1262 int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1265 afs_fid2_t *afid = (afs_fid2_t*)fidp;
1268 osi_Assert(sizeof(fid_t) >= sizeof(afs_fid2_t));
1269 afid->af_len = sizeof(afs_fid2_t) - sizeof(afid->af_len);
1271 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1272 afid->af_cell = tcell->cellIndex & 0xffff;
1273 afs_PutCell(tcell, READ_LOCK);
1275 afid->af_volid = avc->fid.Fid.Volume;
1276 afid->af_vno = avc->fid.Fid.Vnode;
1277 afid->af_uniq = avc->fid.Fid.Unique;
1282 /* Only use so far is in checkpoint/restart for IRIX 6.4. In ckpt_fid, a
1283 * return of ENOSYS would make the code fail over to VOP_FID. We can't let
1284 * that happen, since we do a VN_HOLD there in the expectation that
1285 * posthandle will be called to release the vnode.
1287 * afs_fid2 is used to support the R5000 workarounds (_R5000_CVT_WAR)
1289 int afs_fid2(OSI_VC_DECL(avc), struct fid *fidp)
1291 #if defined(_R5000_CVT_WAR)
1292 extern int R5000_cvt_war;
1302 #endif /* AFS_SGI64_ENV && CKPT */
1306 * check for any pages hashed that shouldn't be!
1307 * Only valid if PGCACHEDEBUG is set in os/page.c
1308 * Drop the global lock here, since we may not actually do the call.
1311 afs_chkpgoob(vnode_t *vp, pgno_t pgno)
1316 pfindanyoob(vp, pgno);
1324 #ifdef AFS_SGI64_ENV
1325 #define AFS_MP_VC_ARG(A) bhv_desc_t A
1327 #define AFS_MP_VC_ARG(A) vnode_t A
1330 #ifdef AFS_SGI64_ENV
1331 int mp_afs_open(bhv_desc_t *bhp, vnode_t **a, mode_t b, struct cred *c)
1333 int mp_afs_open(vnode_t **a, mode_t b, struct cred *c)
1338 #ifdef AFS_SGI64_ENV
1339 rv = afs_lockedvnodeops.vop_open(bhp, a, b, c);
1341 rv = afs_lockedvnodeops.vop_open(a, b, c);
1347 #if defined(AFS_SGI64_ENV)
1348 #if defined(AFS_SGI65_ENV)
1349 int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, struct cred *d)
1351 int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, off_t d,
1352 struct cred *e, struct flid *f)
1355 int mp_afs_close(AFS_MP_VC_ARG (*a), int b, lastclose_t c, off_t d,
1361 rv = afs_lockedvnodeops.vop_close(a, b, c, d
1362 #if !defined(AFS_SGI65_ENV)
1364 #if defined(AFS_SGI64_ENV)
1374 #ifdef AFS_SGI64_ENV
1375 int mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1378 int mp_afs_read(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1383 #ifdef AFS_SGI64_ENV
1384 rv = afs_lockedvnodeops.vop_read(a, b, c, d, f);
1386 rv = afs_lockedvnodeops.vop_read(a, b, c, d);
1393 #ifdef AFS_SGI64_ENV
1394 int mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d,
1397 int mp_afs_write(AFS_MP_VC_ARG(*a), struct uio *b, int c, struct cred *d)
1402 #ifdef AFS_SGI64_ENV
1403 rv = afs_lockedvnodeops.vop_write(a, b, c, d, f);
1405 rv = afs_lockedvnodeops.vop_write(a, b, c, d);
1411 int mp_afs_ioctl(AFS_MP_VC_ARG(*a), int b, void *c, int d, struct cred *e,
1413 #ifdef AFS_SGI65_ENV
1414 , struct vopbd *vbds
1420 rv = afs_lockedvnodeops.vop_ioctl(a, b, c, d, e, f
1421 #ifdef AFS_SGI65_ENV
1429 int mp_fs_setfl(AFS_MP_VC_ARG(*a), int b, int c, struct cred *d)
1433 rv = afs_lockedvnodeops.vop_setfl(a, b, c, d);
1437 int mp_afs_getattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1441 rv = afs_lockedvnodeops.vop_getattr(a, b, c, d);
1445 int mp_afs_setattr(AFS_MP_VC_ARG(*a), struct vattr *b, int c, struct cred *d)
1449 rv = afs_lockedvnodeops.vop_setattr(a, b, c, d);
1454 int mp_afs_access(AFS_MP_VC_ARG(*a), int b,
1455 #ifndef AFS_SGI65_ENV
1462 rv = afs_lockedvnodeops.vop_access(a, b,
1463 #ifndef AFS_SGI65_ENV
1471 int mp_afs_lookup(AFS_MP_VC_ARG(*a), char *b, vnode_t **c, struct pathname *d,
1472 int e, vnode_t *f, struct cred *g)
1476 rv = afs_lockedvnodeops.vop_lookup(a, b, c, d, e, f, g);
1480 #ifdef AFS_SGI64_ENV
1481 int mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, int d, int e,
1482 vnode_t **f, struct cred *g)
1484 int mp_afs_create(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, enum vcexcl d,
1485 int e, vnode_t **f, struct cred *g)
1490 rv = afs_lockedvnodeops.vop_create(a, b, c, d, e, f, g);
1494 int mp_afs_remove(AFS_MP_VC_ARG(*a), char *b, struct cred *c)
1498 rv = afs_lockedvnodeops.vop_remove(a, b, c);
1502 int mp_afs_link(AFS_MP_VC_ARG(*a), vnode_t *b, char *c, struct cred *d)
1506 rv = afs_lockedvnodeops.vop_link(a, b, c, d);
1510 int mp_afs_rename(AFS_MP_VC_ARG(*a), char *b, vnode_t *c, char *d,
1511 struct pathname *e, struct cred *f)
1515 rv = afs_lockedvnodeops.vop_rename(a, b, c, d, e, f);
1519 int mp_afs_mkdir(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, vnode_t **d,
1524 rv = afs_lockedvnodeops.vop_mkdir(a, b, c, d, e);
1528 int mp_afs_rmdir(AFS_MP_VC_ARG(*a), char *b, vnode_t *c, struct cred *d)
1532 rv = afs_lockedvnodeops.vop_rmdir(a, b, c, d);
1536 int mp_afs_readdir(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c, int *d)
1540 rv = afs_lockedvnodeops.vop_readdir(a, b, c, d);
1544 int mp_afs_symlink(AFS_MP_VC_ARG(*a), char *b, struct vattr *c, char *d,
1549 rv = afs_lockedvnodeops.vop_symlink(a, b, c, d, e);
1553 int mp_afs_readlink(AFS_MP_VC_ARG(*a), struct uio *b, struct cred *c)
1557 rv = afs_lockedvnodeops.vop_readlink(a, b, c);
1562 int mp_afs_fsync(AFS_MP_VC_ARG(*a), int b, struct cred *c
1563 #ifdef AFS_SGI65_ENV
1564 , off_t start, off_t stop
1570 rv = afs_lockedvnodeops.vop_fsync(a, b, c
1571 #ifdef AFS_SGI65_ENV
1579 void mp_afs_inactive(AFS_MP_VC_ARG(*a), struct cred *b)
1582 afs_lockedvnodeops.vop_inactive(a, b);
1586 int mp_afs_fid(AFS_MP_VC_ARG(*a), struct fid **b)
1590 rv = afs_lockedvnodeops.vop_fid(a, b);
1594 int mp_afs_fid2(AFS_MP_VC_ARG(*a), struct fid *b)
1598 rv = afs_lockedvnodeops.vop_fid2(a, b);
1602 void mp_afs_rwlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1605 afs_rwlock(a, VRWLOCK_WRITE);
1608 void mp_afs_rwunlock(AFS_MP_VC_ARG(*a), AFS_RWLOCK_T b)
1611 afs_rwunlock(a, VRWLOCK_WRITE);
1614 int mp_afs_seek(AFS_MP_VC_ARG(*a), off_t b, off_t*c)
1618 rv = afs_lockedvnodeops.vop_seek(a, b, c);
1622 int mp_fs_cmp(AFS_MP_VC_ARG(*a), vnode_t *b)
1626 rv = afs_lockedvnodeops.vop_cmp(a, b);
1631 int mp_afs_frlock(AFS_MP_VC_ARG(*a), int b, struct flock *c, int d, off_t e,
1632 #ifdef AFS_SGI65_ENV
1639 rv = afs_lockedvnodeops.vop_frlock(a, b, c, d, e,
1640 #ifdef AFS_SGI65_ENV
1648 int mp_afs_realvp(AFS_MP_VC_ARG(*a), vnode_t **b)
1652 rv = afs_lockedvnodeops.vop_realvp(a, b);
1656 int mp_afs_bmap(AFS_MP_VC_ARG(*a), off_t b, ssize_t c, int d, struct cred *e,
1657 struct bmapval *f, int *g)
1661 rv = afs_lockedvnodeops.vop_bmap(a, b, c, d, e, f, g);
1666 void mp_afs_strategy(AFS_MP_VC_ARG(*a), struct buf *b)
1670 afs_lockedvnodeops.vop_strategy(a, b);
1675 #ifdef AFS_SGI65_ENV
1676 int mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, size_t c, mprot_t d,
1677 u_int e, struct cred *f, vnode_t **g)
1679 int mp_afs_map(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, char ** d,
1680 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1685 rv = afs_lockedvnodeops.vop_map(a, b, c, d, e, f, g
1686 #ifndef AFS_SGI65_ENV
1695 #ifndef AFS_SGI65_ENV
1696 /* As of Irix 6.5, addmap and delmap are only for devices */
1697 int mp_afs_addmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1698 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1702 rv = afs_lockedvnodeops.vop_addmap(a, b, c, d, e, f, g, h, i);
1707 int mp_afs_delmap(AFS_MP_VC_ARG(*a), off_t b, struct pregion *c, addr_t d,
1708 size_t e, u_int f, u_int g, u_int h, struct cred *i)
1712 rv = afs_lockedvnodeops.vop_delmap(a, b, c, d, e, f, g, h, i);
1716 #endif /* ! AFS_SGI65_ENV */
1718 int mp_fs_poll(AFS_MP_VC_ARG(*a), short b, int c, short *d,
1720 #ifdef AFS_SGI65_ENV
1727 rv = afs_lockedvnodeops.vop_poll(a, b, c, d, e
1728 #ifdef AFS_SGI65_ENV
1737 struct vnodeops Afs_vnodeops = {
1738 #ifdef AFS_SGI64_ENV
1739 #ifdef AFS_SGI65_ENV
1740 BHV_IDENTITY_INIT_POSITION(VNODE_POSITION_BASE),
1742 VNODE_POSITION_BASE,
1773 fs_nosys, /* realvp */
1777 #ifdef AFS_SGI65_ENV
1778 fs_noerr, /* addmap - devices only */
1779 fs_noerr, /* delmap - devices only */
1784 mp_fs_poll, /* poll */
1785 fs_nosys, /* dump */
1787 fs_nosys, /* allocstore */
1788 fs_nosys, /* fcntl */
1789 afs_reclaim, /* reclaim */
1790 fs_nosys, /* attr_get */
1791 fs_nosys, /* attr_set */
1792 fs_nosys, /* attr_remove */
1793 fs_nosys, /* attr_list */
1794 #ifdef AFS_SGI64_ENV
1795 #ifdef AFS_SGI65_ENV
1797 (vop_link_removed_t)fs_noval,
1800 fs_flushinval_pages,
1804 (vop_commit_t)fs_nosys,
1805 (vop_readbuf_t)fs_nosys,
1813 struct vnodeops *afs_ops = &Afs_vnodeops;
1817 #if defined(AFS_SGI62_ENV) && defined(AFS_SGI_DUAL_FS_CACHE)
1818 /* Support for EFS and XFS caches. The assumption here is that the size of
1819 * a cache file also does not exceed 32 bits.
1822 /* Initialized in osi_InitCacheFSType(). Used to determine inode type. */
1823 int afs_CacheFSType = -1;
1824 vnodeops_t *afs_efs_vnodeopsp;
1825 vnodeops_t *afs_xfs_vnodeopsp;
1826 vnode_t * (*afs_IGetVnode)(ino_t);
1828 extern vnode_t *afs_EFSIGetVnode(ino_t); /* defined in osi_file.c */
1829 extern vnode_t *afs_XFSIGetVnode(ino_t); /* defined in osi_file.c */
1831 extern afs_lock_t afs_xosi; /* lock is for tvattr */
1833 /* Initialize the cache operations. Called while initializing cache files. */
1834 void afs_InitDualFSCacheOps(struct vnode *vp)
1836 static int inited = 0;
1845 #ifdef AFS_SGI_EFS_IOPS_ENV
1846 swp = vfs_getvfssw("efs");
1848 afs_efs_vnodeopsp = swp->vsw_vnodeops;
1849 if(vp && vp->v_op == afs_efs_vnodeopsp) {
1850 afs_CacheFSType = AFS_SGI_EFS_CACHE;
1851 afs_IGetVnode = afs_EFSIGetVnode;
1855 #endif /* AFS_SGI_EFS_IOPS_ENV */
1857 swp = vfs_getvfssw("xfs");
1859 afs_xfs_vnodeopsp = swp->vsw_vnodeops;
1861 if (vp &&vp->v_op == afs_xfs_vnodeopsp) {
1862 afs_CacheFSType = AFS_SGI_XFS_CACHE;
1863 afs_IGetVnode = afs_XFSIGetVnode;
1870 osi_Panic("osi_InitCacheFSType: Can't find fstype for vnode 0x%llx\n",
1874 ino_t VnodeToIno(vnode_t *vp)
1879 MObtainWriteLock(&afs_xosi,579);
1880 vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */
1882 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1885 osi_Panic("VnodeToIno");
1887 MReleaseWriteLock(&afs_xosi);
1888 return vattr.va_nodeid;
1891 dev_t VnodeToDev(vnode_t *vp)
1896 MObtainWriteLock(&afs_xosi,580);
1897 vattr.va_mask = AT_FSID|AT_NODEID; /* quick return using this mask. */
1899 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1902 osi_Panic("VnodeToDev");
1904 MReleaseWriteLock(&afs_xosi);
1905 return (dev_t)vattr.va_fsid;
1908 off_t VnodeToSize(vnode_t *vp)
1913 MObtainWriteLock(&afs_xosi,581);
1914 vattr.va_mask = AT_SIZE;
1916 AFS_VOP_GETATTR(vp, &vattr, 0, OSI_GET_CURRENT_CRED(), code);
1919 osi_Panic("VnodeToSize");
1921 MReleaseWriteLock(&afs_xosi);
1922 return vattr.va_size;
1924 #endif /* 6.2 and dual fs cache */
1925 #endif /* AFS_SGI62_ENV */