2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
17 * SOLARIS/osi_vnodeops.c
21 * Functions: AFS_TRYUP, _init, _info, _fini, afs_addmap, afs_delmap,
22 * afs_vmread, afs_vmwrite, afs_getpage, afs_GetOnePage, afs_putpage,
23 * afs_putapage, afs_nfsrdwr, afs_map, afs_PageLeft, afs_pathconf/afs_cntl,
24 * afs_ioctl, afs_rwlock, afs_rwunlock, afs_seek, afs_space, afs_dump,
25 * afs_cmp, afs_realvp, afs_pageio, afs_dumpctl, afs_dispose, afs_setsecattr,
26 * afs_getsecattr, gafs_open, gafs_close, gafs_getattr, gafs_setattr,
27 * gafs_access, gafs_lookup, gafs_create, gafs_remove, gafs_link,
28 * gafs_rename, gafs_mkdir, gafs_rmdir, gafs_readdir, gafs_symlink,
29 * gafs_readlink, gafs_fsync, afs_inactive, gafs_inactive, gafs_fid
32 * Variables: Afs_vnodeops
35 #include "afs/sysincludes.h" /* Standard vendor system headers */
36 #include "afsincludes.h" /* Afs-based standard headers */
37 #include "afs/afs_stats.h" /* statistics */
38 #include "afs/nfsclient.h"
47 #include <vm/seg_map.h>
48 #include <vm/seg_vn.h>
50 #include <sys/modctl.h>
51 #include <sys/syscall.h>
52 #include <sys/debug.h>
53 #include <sys/fs_subr.h>
56 * XXX Temporary fix for problems with Solaris rw_tryupgrade() lock.
57 * It isn't very persistent in getting the upgrade when others are
58 * waiting for it and returns 0. So the UpgradeSToW() macro that the
59 * rw_tryupgrade used to map to wasn't good enough and we need to use
60 * the following code instead. Obviously this isn't the proper place
61 * for it but it's only called from here for now
68 if (!rw_tryupgrade(lock)) {
70 rw_enter(lock, RW_WRITER);
76 /* Translate a faultcode_t as returned by some of the vm routines
77 * into a suitable errno value.
80 afs_fc2errno(faultcode_t fc)
82 switch (FC_CODE(fc)) {
95 extern struct as kas; /* kernel addr space */
96 extern unsigned char *afs_indexFlags;
97 extern afs_lock_t afs_xdcache;
99 /* Additional vnodeops for SunOS 4.0.x */
100 int afs_nfsrdwr(), afs_getpage(), afs_putpage(), afs_map();
101 int afs_dump(), afs_cmp(), afs_realvp(), afs_GetOnePage();
106 afs_addmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp)
107 register struct vnode *avp;
111 int length, prot, maxprot, flags;
112 struct AFS_UCRED *credp;
114 /* XXX What should we do here?? XXX */
119 afs_delmap(avp, offset, asp, addr, length, prot, maxprot, flags, credp)
120 register struct vnode *avp;
124 int length, prot, maxprot, flags;
125 struct AFS_UCRED *credp;
127 /* XXX What should we do here?? XXX */
131 #ifdef AFS_SUN510_ENV
133 afs_vmread(avp, auio, ioflag, acred, ct)
134 register struct vnode *avp;
137 struct AFS_UCRED *acred;
138 caller_context_t *ct;
141 afs_vmread(avp, auio, ioflag, acred)
142 register struct vnode *avp;
145 struct AFS_UCRED *acred;
150 if (!RW_READ_HELD(&(VTOAFS(avp))->rwlock))
151 osi_Panic("afs_vmread: !rwlock");
153 code = afs_nfsrdwr(VTOAFS(avp), auio, UIO_READ, ioflag, acred);
159 #ifdef AFS_SUN510_ENV
161 afs_vmwrite(avp, auio, ioflag, acred, ct)
162 register struct vnode *avp;
165 struct AFS_UCRED *acred;
166 caller_context_t *ct;
169 afs_vmwrite(avp, auio, ioflag, acred)
170 register struct vnode *avp;
173 struct AFS_UCRED *acred;
178 if (!RW_WRITE_HELD(&(VTOAFS(avp))->rwlock))
179 osi_Panic("afs_vmwrite: !rwlock");
181 code = afs_nfsrdwr(VTOAFS(avp), auio, UIO_WRITE, ioflag, acred);
187 afs_getpage(vp, off, len, protp, pl, plsz, seg, addr, rw, acred)
197 struct AFS_UCRED *acred;
199 register afs_int32 code = 0;
200 AFS_STATCNT(afs_getpage);
202 if (vp->v_flag & VNOMAP) /* File doesn't allow mapping */
207 #if defined(AFS_SUN56_ENV)
210 afs_GetOnePage(vp, off, len, protp, pl, plsz, seg, addr, rw,
215 afs_GetOnePage(vp, (u_int) off, len, protp, pl, plsz, seg, addr,
219 struct vcache *vcp = VTOAFS(vp);
220 ObtainWriteLock(&vcp->vlock, 548);
222 ReleaseWriteLock(&vcp->vlock);
223 afs_BozonLock(&vcp->pvnLock, vcp);
224 #if defined(AFS_SUN56_ENV)
226 pvn_getpages(afs_GetOnePage, vp, off, len, protp, pl, plsz, seg,
230 pvn_getpages(afs_GetOnePage, vp, (u_int) off, len, protp, pl,
231 plsz, seg, addr, rw, acred);
233 afs_BozonUnlock(&vcp->pvnLock, vcp);
234 ObtainWriteLock(&vcp->vlock, 549);
236 ReleaseWriteLock(&vcp->vlock);
242 /* Return all the pages from [off..off+len) in file */
244 afs_GetOnePage(vp, off, alen, protp, pl, plsz, seg, addr, rw, acred)
247 #if defined(AFS_SUN56_ENV)
258 struct AFS_UCRED *acred;
260 register struct page *page;
261 register afs_int32 code = 0;
265 register struct vcache *avc;
266 register struct dcache *tdc;
269 afs_size_t offset, nlen;
270 struct vrequest treq;
271 afs_int32 mapForRead = 0, Code = 0;
275 osi_Panic("GetOnePage: !acred");
277 avc = VTOAFS(vp); /* cast to afs vnode */
279 if (avc->credp /*&& AFS_NFSXLATORREQ(acred) */
280 && AFS_NFSXLATORREQ(avc->credp)) {
283 if (code = afs_InitReq(&treq, acred))
287 /* This is a read-ahead request, e.g. due to madvise. */
289 ObtainReadLock(&avc->lock);
291 while (plen > 0 && !afs_BBusy()) {
292 /* Obtain a dcache entry at off. 2 means don't fetch data. */
294 afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen,
299 /* Write-lock the dcache entry, if we don't succeed, just go on */
300 if (0 != NBObtainWriteLock(&tdc->lock, 642)) {
305 /* If we aren't already fetching this dcache entry, queue it */
306 if (!(tdc->mflags & DFFetchReq)) {
309 tdc->mflags |= DFFetchReq;
310 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
311 (afs_size_t) off, (afs_size_t) 1, tdc);
313 /* Unable to start background fetch; might as well stop */
314 tdc->mflags &= ~DFFetchReq;
315 ReleaseWriteLock(&tdc->lock);
319 ReleaseWriteLock(&tdc->lock);
321 ReleaseWriteLock(&tdc->lock);
326 /* Adjust our offset and remaining length values */
330 /* If we aren't making progress for some reason, bail out */
335 ReleaseReadLock(&avc->lock);
340 pl[0] = NULL; /* Make sure it's empty */
342 /* first, obtain the proper lock for the VM system */
344 /* if this is a read request, map the page in read-only. This will
345 * allow us to swap out the dcache entry if there are only read-only
346 * pages created for the chunk, which helps a *lot* when dealing
347 * with small caches. Otherwise, we have to invalidate the vm
348 * pages for the range covered by a chunk when we swap out the
351 if (rw == S_READ || rw == S_EXEC)
358 if (rw == S_WRITE || rw == S_CREATE)
359 tdc = afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen, 5);
361 tdc = afs_GetDCache(avc, (afs_offs_t) off, &treq, &offset, &nlen, 1);
364 code = afs_VerifyVCache(avc, &treq);
367 return afs_CheckCode(code, &treq, 44); /* failed to get it */
370 afs_BozonLock(&avc->pvnLock, avc);
371 ObtainReadLock(&avc->lock);
373 afs_Trace4(afs_iclSetp, CM_TRACE_PAGEIN, ICL_TYPE_POINTER, (afs_int32) vp,
374 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(off), ICL_TYPE_LONG, len,
375 ICL_TYPE_LONG, (int)rw);
380 /* Check to see if we're in the middle of a VM purge, and if we are, release
381 * the locks and try again when the VM purge is done. */
382 ObtainWriteLock(&avc->vlock, 550);
384 ReleaseReadLock(&avc->lock);
385 ReleaseWriteLock(&avc->vlock);
386 afs_BozonUnlock(&avc->pvnLock, avc);
388 /* Check activeV again, it may have been turned off
389 * while we were waiting for a lock in afs_PutDCache */
390 ObtainWriteLock(&avc->vlock, 574);
392 avc->vstates |= VRevokeWait;
393 ReleaseWriteLock(&avc->vlock);
394 afs_osi_Sleep(&avc->vstates);
396 ReleaseWriteLock(&avc->vlock);
400 ReleaseWriteLock(&avc->vlock);
402 /* We're about to do stuff with our dcache entry.. Lock it. */
403 ObtainReadLock(&tdc->lock);
405 /* Check to see whether the cache entry is still valid */
406 if (!(avc->states & CStatd)
407 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
408 ReleaseReadLock(&tdc->lock);
409 ReleaseReadLock(&avc->lock);
410 afs_BozonUnlock(&avc->pvnLock, avc);
416 while (1) { /* loop over all pages */
417 /* now, try to find the page in memory (it may already be intransit or laying
418 * around the free list */
420 page_lookup(vp, toffset, (rw == S_CREATE ? SE_EXCL : SE_SHARED));
424 /* if we make it here, we can't find the page in memory. Do a real disk read
425 * from the cache to get the data */
426 Code |= 0x200; /* XXX */
427 #if defined(AFS_SUN54_ENV)
428 /* use PG_EXCL because we know the page does not exist already. If it
429 * actually does exist, we have somehow raced between lookup and create.
430 * As of 4/98, that shouldn't be possible, but we'll be defensive here
431 * in case someone tries to relax all the serialization of read and write
432 * operations with harmless things like stat. */
433 #if defined(AFS_SUN58_ENV)
435 page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL, seg,
439 page_create_va(vp, toffset, PAGESIZE, PG_WAIT | PG_EXCL,
443 page = page_create(vp, toffset, PAGESIZE, PG_WAIT);
449 pagezero(page, alen, PAGESIZE - alen);
451 if (rw == S_CREATE) {
452 /* XXX Don't read from AFS in write only cases XXX */
453 page_io_unlock(page);
456 /* now it is time to start I/O operation */
457 buf = pageio_setup(page, PAGESIZE, vp, B_READ); /* allocate a buf structure */
460 buf->b_blkno = btodb(toffset);
461 bp_mapin(buf); /* map it in to our address space */
464 /* afs_ustrategy will want to lock the dcache entry */
465 ReleaseReadLock(&tdc->lock);
466 code = afs_ustrategy(buf, acred); /* do the I/O */
467 ObtainReadLock(&tdc->lock);
470 /* Before freeing unmap the buffer */
476 page_io_unlock(page);
479 /* come here when we have another page (already held) to enter */
481 /* put page in array and continue */
482 /* The p_selock must be downgraded to a shared lock after the page is read */
483 #if defined(AFS_SUN56_ENV)
484 if ((rw != S_CREATE) && !(PAGE_SHARED(page)))
486 if ((rw != S_CREATE) && !(se_shared_assert(&page->p_selock)))
489 page_downgrade(page);
492 code = page_iolock_assert(page);
498 break; /* done all the pages */
499 } /* while (1) ... */
503 ReleaseReadLock(&tdc->lock);
505 /* Prefetch next chunk if we're at a chunk boundary */
506 if (AFS_CHUNKOFFSET(off) == 0) {
507 if (!(tdc->mflags & DFNextStarted))
508 afs_PrefetchChunk(avc, tdc, acred, &treq);
511 ReleaseReadLock(&avc->lock);
512 ObtainWriteLock(&afs_xdcache, 246);
514 /* track that we have dirty (or dirty-able) pages for this chunk. */
515 afs_indexFlags[tdc->index] |= IFDirtyPages;
517 afs_indexFlags[tdc->index] |= IFAnyPages;
518 ReleaseWriteLock(&afs_xdcache);
519 afs_BozonUnlock(&avc->pvnLock, avc);
521 afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code,
522 ICL_TYPE_LONG, (int)page, ICL_TYPE_LONG, Code);
527 afs_Trace3(afs_iclSetp, CM_TRACE_PAGEINDONE, ICL_TYPE_LONG, code,
528 ICL_TYPE_LONG, (int)page, ICL_TYPE_LONG, Code);
529 /* release all pages, drop locks, return code */
531 pvn_read_done(page, B_ERROR);
532 ReleaseReadLock(&avc->lock);
533 afs_BozonUnlock(&avc->pvnLock, avc);
534 ReleaseReadLock(&tdc->lock);
540 afs_putpage(vp, off, len, flags, cred)
545 struct AFS_UCRED *cred;
550 #if defined(AFS_SUN58_ENV)
556 afs_int32 NPages = 0;
557 #if defined(AFS_SUN56_ENV)
558 u_offset_t toff = off;
564 AFS_STATCNT(afs_putpage);
565 if (vp->v_flag & VNOMAP) /* file doesn't allow mapping */
569 * Putpage (ASYNC) is called every sec to flush out dirty vm pages
572 afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUT, ICL_TYPE_POINTER,
573 (afs_int32) vp, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(off),
574 ICL_TYPE_INT32, (afs_int32) len, ICL_TYPE_LONG, (int)flags);
576 afs_BozonLock(&avc->pvnLock, avc);
577 ObtainSharedLock(&avc->lock, 247);
580 /* Get a list of modified (or whatever) pages */
582 endPos = (afs_offs_t) off + len; /* position we're supposed to write up to */
583 while ((afs_offs_t) toff < endPos
584 && (afs_offs_t) toff < avc->m.Length) {
585 /* If not invalidating pages use page_lookup_nowait to avoid reclaiming
586 * them from the free list
589 if (flags & (B_FREE | B_INVAL))
590 pages = page_lookup(vp, toff, SE_EXCL);
592 pages = page_lookup_nowait(vp, toff, SE_SHARED);
593 if (!pages || !pvn_getdirty(pages, flags))
599 UpgradeSToWLock(&avc->lock, 671);
603 code = afs_putapage(vp, pages, &toff, &tlen, flags, cred);
614 UpgradeSToWLock(&avc->lock, 670);
619 #if defined(AFS_SUN56_ENV)
620 code = pvn_vplist_dirty(vp, toff, afs_putapage, flags, cred);
622 code = pvn_vplist_dirty(vp, (u_int) off, afs_putapage, flags, cred);
627 if (code && !avc->vc_error) {
629 UpgradeSToWLock(&avc->lock, 669);
632 avc->vc_error = code;
636 ReleaseWriteLock(&avc->lock);
638 ReleaseSharedLock(&avc->lock);
639 afs_BozonUnlock(&avc->pvnLock, avc);
640 afs_Trace2(afs_iclSetp, CM_TRACE_PAGEOUTDONE, ICL_TYPE_LONG, code,
641 ICL_TYPE_LONG, NPages);
648 afs_putapage(struct vnode *vp, struct page *pages,
649 #if defined(AFS_SUN56_ENV)
654 #if defined(AFS_SUN58_ENV)
659 int flags, struct AFS_UCRED *credp)
662 struct vcache *avc = VTOAFS(vp);
664 u_int tlen = PAGESIZE;
665 afs_offs_t off = (pages->p_offset / PAGESIZE) * PAGESIZE;
668 * Now we've got the modified pages. All pages are locked and held
669 * XXX Find a kluster that fits in one block (or page). We also
670 * adjust the i/o if the file space is less than a while page. XXX
672 if (off + tlen > avc->m.Length) {
673 tlen = avc->m.Length - off;
675 /* can't call mapout with 0 length buffers (rmfree panics) */
676 if (((tlen >> 24) & 0xff) == 0xff) {
681 * Can't call mapout with 0 length buffers since we'll get rmfree panics
683 tbuf = pageio_setup(pages, tlen, vp, B_WRITE | flags);
688 tbuf->b_blkno = btodb(pages->p_offset);
691 afs_Trace4(afs_iclSetp, CM_TRACE_PAGEOUTONE, ICL_TYPE_LONG, avc,
692 ICL_TYPE_LONG, pages, ICL_TYPE_LONG, tlen, ICL_TYPE_OFFSET,
693 ICL_HANDLE_OFFSET(off));
694 code = afs_ustrategy(tbuf, credp); /* unlocks page */
698 pvn_write_done(pages, ((code) ? B_ERROR : 0) | B_WRITE | flags);
709 afs_nfsrdwr(avc, auio, arw, ioflag, acred)
710 register struct vcache *avc;
714 struct AFS_UCRED *acred;
716 register afs_int32 code;
719 afs_int32 mode, sflags;
721 struct dcache *dcp, *dcp_newpage;
722 afs_size_t fileBase, size;
724 register afs_int32 tsize;
725 register afs_int32 pageOffset, extraResid = 0;
726 register afs_size_t origLength; /* length when reading/writing started */
727 register long appendLength; /* length when this call will finish */
728 int created; /* created pages instead of faulting them */
730 int didFakeOpen, eof;
731 struct vrequest treq;
735 AFS_STATCNT(afs_nfsrdwr);
737 /* can't read or write other things */
738 if (vType(avc) != VREG)
741 if (auio->uio_resid == 0)
744 afs_Trace4(afs_iclSetp, CM_TRACE_VMRW, ICL_TYPE_POINTER, (afs_int32) avc,
745 ICL_TYPE_LONG, (arw == UIO_WRITE ? 1 : 0), ICL_TYPE_OFFSET,
746 ICL_HANDLE_OFFSET(auio->uio_offset), ICL_TYPE_OFFSET,
747 ICL_HANDLE_OFFSET(auio->uio_resid));
749 #ifndef AFS_64BIT_CLIENT
750 if (AfsLargeFileUio(auio)) /* file is larger than 2 GB */
755 osi_Panic("rdwr: !acred");
757 if (code = afs_InitReq(&treq, acred))
760 /* It's not really possible to know if a write cause a growth in the
761 * cache size, we we wait for a cache drain for any write.
763 afs_MaybeWakeupTruncateDaemon();
764 while ((arw == UIO_WRITE)
765 && (afs_blocksUsed > PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks))) {
766 if (afs_blocksUsed - afs_blocksDiscarded >
767 PERCENT(CM_WAITFORDRAINPCT, afs_cacheBlocks)) {
768 afs_WaitForCacheDrain = 1;
769 afs_osi_Sleep(&afs_WaitForCacheDrain);
771 afs_MaybeFreeDiscardedDCache();
772 afs_MaybeWakeupTruncateDaemon();
774 code = afs_VerifyVCache(avc, &treq);
776 return afs_CheckCode(code, &treq, 45);
778 afs_BozonLock(&avc->pvnLock, avc);
779 osi_FlushPages(avc, acred); /* hold bozon lock, but not basic vnode lock */
781 ObtainWriteLock(&avc->lock, 250);
783 /* adjust parameters when appending files */
784 if ((ioflag & IO_APPEND) && arw == UIO_WRITE) {
785 #if defined(AFS_SUN56_ENV)
786 auio->uio_loffset = 0;
788 auio->uio_offset = avc->m.Length; /* write at EOF position */
790 if (auio->uio_offset < 0 || (auio->uio_offset + auio->uio_resid) < 0) {
791 ReleaseWriteLock(&avc->lock);
792 afs_BozonUnlock(&avc->pvnLock, avc);
795 #ifndef AFS_64BIT_CLIENT
796 /* file is larger than 2GB */
797 if (AfsLargeFileSize(auio->uio_offset, auio->uio_resid)) {
798 ReleaseWriteLock(&avc->lock);
799 afs_BozonUnlock(&avc->pvnLock, avc);
804 didFakeOpen = 0; /* keep track of open so we can do close */
805 if (arw == UIO_WRITE) {
806 /* do ulimit processing; shrink resid or fail */
807 #if defined(AFS_SUN56_ENV)
808 if (auio->uio_loffset + auio->afsio_resid > auio->uio_llimit) {
809 if (auio->uio_loffset >= auio->uio_llimit) {
810 ReleaseWriteLock(&avc->lock);
811 afs_BozonUnlock(&avc->pvnLock, avc);
814 /* track # of bytes we should write, but won't because of
815 * ulimit; we must add this into the final resid value
816 * so caller knows we punted some data.
818 extraResid = auio->uio_resid;
819 auio->uio_resid = auio->uio_llimit - auio->uio_loffset;
820 extraResid -= auio->uio_resid;
825 if (auio->afsio_offset + auio->afsio_resid > auio->uio_limit) {
826 if (auio->afsio_offset >= auio->uio_limit) {
827 ReleaseWriteLock(&avc->lock);
828 afs_BozonUnlock(&avc->pvnLock, avc);
831 /* track # of bytes we should write, but won't because of
832 * ulimit; we must add this into the final resid value
833 * so caller knows we punted some data.
835 extraResid = auio->uio_resid;
836 auio->uio_resid = auio->uio_limit - auio->afsio_offset;
837 extraResid -= auio->uio_resid;
842 mode = S_WRITE; /* segment map-in mode */
843 afs_FakeOpen(avc); /* do this for writes, so data gets put back
844 * when we want it to be put back */
845 didFakeOpen = 1; /* we'll be doing a fake open */
846 /* before starting any I/O, we must ensure that the file is big enough
847 * to hold the results (since afs_putpage will be called to force the I/O */
848 size = auio->afsio_resid + auio->afsio_offset; /* new file size */
850 origLength = avc->m.Length;
851 if (size > avc->m.Length) {
852 afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH, ICL_TYPE_STRING,
853 __FILE__, ICL_TYPE_LONG, __LINE__, ICL_TYPE_OFFSET,
854 ICL_HANDLE_OFFSET(avc->m.Length), ICL_TYPE_OFFSET,
855 ICL_HANDLE_OFFSET(size));
856 avc->m.Length = size; /* file grew */
858 avc->states |= CDirty; /* Set the dirty bit */
859 avc->m.Date = osi_Time(); /* Set file date (for ranlib) */
861 mode = S_READ; /* map-in read-only */
862 origLength = avc->m.Length;
865 if (acred && AFS_NFSXLATORREQ(acred)) {
866 if (arw == UIO_READ) {
868 (avc, PRSFS_READ, &treq,
869 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) {
870 ReleaseWriteLock(&avc->lock);
871 afs_BozonUnlock(&avc->pvnLock, avc);
881 counter = 0; /* don't call afs_DoPartialWrite first time through. */
883 /* compute the amount of data to move into this block,
884 * based on auio->afsio_resid. Note that we copy data in units of
885 * MAXBSIZE, not PAGESIZE. This is because segmap_getmap panics if you
886 * call it with an offset based on blocks smaller than MAXBSIZE
887 * (implying that it should be named BSIZE, since it is clearly both a
889 size = auio->afsio_resid; /* transfer size */
890 fileBase = auio->afsio_offset; /* start file position for xfr */
891 pageBase = fileBase & ~(MAXBSIZE - 1); /* file position of the page */
892 pageOffset = fileBase & (MAXBSIZE - 1); /* xfr start's offset within page */
893 tsize = MAXBSIZE - pageOffset; /* how much more fits in this page */
894 /* we'll read tsize bytes, but first must make sure tsize isn't too big */
896 tsize = size; /* don't read past end of request */
897 eof = 0; /* flag telling us if we hit the EOF on the read */
898 if (arw == UIO_READ) { /* we're doing a read operation */
899 /* don't read past EOF */
900 if (fileBase + tsize > origLength) {
901 tsize = origLength - fileBase;
902 eof = 1; /* we did hit the EOF */
904 tsize = 0; /* better safe than sorry */
908 /* Purge dirty chunks of file if there are too many dirty
909 * chunks. Inside the write loop, we only do this at a chunk
910 * boundary. Clean up partial chunk if necessary at end of loop.
912 if (counter > 0 && code == 0 && AFS_CHUNKOFFSET(fileBase) == 0) {
913 code = afs_DoPartialWrite(avc, &treq);
917 /* write case, we ask segmap_release to call putpage. Really, we
918 * don't have to do this on every page mapin, but for now we're
919 * lazy, and don't modify the rest of AFS to scan for modified
920 * pages on a close or other "synchronize with file server"
921 * operation. This makes things a little cleaner, but probably
922 * hurts performance. */
927 break; /* nothing to transfer, we're done */
929 if (arw == UIO_WRITE)
930 avc->states |= CDirty; /* may have been cleared by DoPartialWrite */
932 /* Before dropping lock, hold the chunk (create it if necessary). This
933 * serves two purposes: (1) Ensure Cache Truncate Daemon doesn't try
934 * to purge the chunk's pages while we have them locked. This would
935 * cause deadlock because we might be waiting for the CTD to free up
936 * a chunk. (2) If we're writing past the original EOF, and we're
937 * at the base of the chunk, then make sure it exists online
938 * before we do the uiomove, since the segmap_release will
939 * write out to the chunk, causing it to get fetched if it hasn't
940 * been created yet. The code that would otherwise notice that
941 * we're fetching a chunk past EOF won't work, since we've
942 * already adjusted the file size above.
944 ObtainWriteLock(&avc->vlock, 551);
945 while (avc->vstates & VPageCleaning) {
946 ReleaseWriteLock(&avc->vlock);
947 ReleaseWriteLock(&avc->lock);
948 afs_osi_Sleep(&avc->vstates);
949 ObtainWriteLock(&avc->lock, 334);
950 ObtainWriteLock(&avc->vlock, 552);
952 ReleaseWriteLock(&avc->vlock);
954 afs_size_t toff, tlen;
955 dcp = afs_GetDCache(avc, fileBase, &treq, &toff, &tlen, 2);
961 ReleaseWriteLock(&avc->lock); /* uiomove may page fault */
963 #if defined(AFS_SUN56_ENV)
964 data = segmap_getmap(segkmap, AFSTOV(avc), (u_offset_t) pageBase);
965 raddr = (caddr_t) (((uintptr_t) data + pageOffset) & PAGEMASK);
967 data = segmap_getmap(segkmap, AFSTOV(avc), pageBase);
968 raddr = (caddr_t) (((u_int) data + pageOffset) & PAGEMASK);
971 (((u_int) data + pageOffset + tsize + PAGEOFFSET) & PAGEMASK) -
974 /* if we're doing a write, and we're starting at the rounded
975 * down page base, and we're writing enough data to cover all
976 * created pages, then we must be writing all of the pages
977 * in this MAXBSIZE window that we're creating.
980 if (arw == UIO_WRITE && ((long)raddr == (long)data + pageOffset)
982 /* probably the dcache backing this guy is around, but if
983 * not, we can't do this optimization, since we're creating
984 * writable pages, which must be backed by a chunk.
987 dcp_newpage = afs_FindDCache(avc, pageBase);
989 && hsame(avc->m.DataVersion, dcp_newpage->f.versionNo)) {
990 ObtainWriteLock(&avc->lock, 251);
991 ObtainWriteLock(&avc->vlock, 576);
992 ObtainReadLock(&dcp_newpage->lock);
993 if ((avc->activeV == 0)
994 && hsame(avc->m.DataVersion, dcp_newpage->f.versionNo)
995 && !(dcp_newpage->dflags & (DFFetching))) {
997 segmap_pagecreate(segkmap, raddr, rsize, 1);
999 ObtainWriteLock(&afs_xdcache, 252);
1000 /* Mark the pages as created and dirty */
1001 afs_indexFlags[dcp_newpage->index]
1002 |= (IFAnyPages | IFDirtyPages);
1003 ReleaseWriteLock(&afs_xdcache);
1006 ReleaseReadLock(&dcp_newpage->lock);
1007 afs_PutDCache(dcp_newpage);
1008 ReleaseWriteLock(&avc->vlock);
1009 ReleaseWriteLock(&avc->lock);
1010 } else if (dcp_newpage)
1011 afs_PutDCache(dcp_newpage);
1016 afs_fc2errno(segmap_fault
1017 (kas.a_hat, segkmap, raddr, rsize,
1021 AFS_UIOMOVE(data + pageOffset, tsize, arw, auio, code);
1022 segmap_fault(kas.a_hat, segkmap, raddr, rsize, F_SOFTUNLOCK,
1026 code = segmap_release(segkmap, data, sflags);
1028 (void)segmap_release(segkmap, data, 0);
1031 ObtainWriteLock(&avc->lock, 253);
1039 afs_FakeClose(avc, acred);
1041 if (arw == UIO_WRITE && (avc->states & CDirty)) {
1042 code2 = afs_DoPartialWrite(avc, &treq);
1047 if (!code && avc->vc_error) {
1048 code = avc->vc_error;
1050 ReleaseWriteLock(&avc->lock);
1051 afs_BozonUnlock(&avc->pvnLock, avc);
1053 #ifdef AFS_SUN53_ENV
1054 if ((ioflag & FSYNC) && (arw == UIO_WRITE)
1055 && !AFS_NFSXLATORREQ(acred))
1056 code = afs_fsync(avc, 0, acred);
1058 if ((ioflag & IO_SYNC) && (arw == UIO_WRITE)
1059 && !AFS_NFSXLATORREQ(acred))
1060 code = afs_fsync(avc, acred);
1063 #ifdef AFS_SUN52_ENV
1065 * If things worked, add in as remaining in request any bytes
1066 * we didn't write due to file size ulimit.
1068 if (code == 0 && extraResid > 0)
1069 auio->uio_resid += extraResid;
1071 return afs_CheckCode(code, &treq, 46);
1074 afs_map(vp, off, as, addr, len, prot, maxprot, flags, cred)
1080 u_char prot, maxprot;
1082 struct AFS_UCRED *cred;
1084 struct segvn_crargs crargs;
1085 register afs_int32 code;
1086 struct vrequest treq;
1087 register struct vcache *avc = VTOAFS(vp);
1089 AFS_STATCNT(afs_map);
1092 /* check for reasonableness on segment bounds; apparently len can be < 0 */
1093 if (off < 0 || off + len < 0) {
1096 #ifndef AFS_64BIT_CLIENT
1097 if (AfsLargeFileSize(off, len)) { /* file is larger than 2 GB */
1103 if (vp->v_flag & VNOMAP) /* File isn't allowed to be mapped */
1106 if (vp->v_filocks) /* if locked, disallow mapping */
1110 if (code = afs_InitReq(&treq, cred))
1113 if (vp->v_type != VREG) {
1118 code = afs_VerifyVCache(avc, &treq);
1122 afs_BozonLock(&avc->pvnLock, avc);
1123 osi_FlushPages(avc, cred); /* ensure old pages are gone */
1124 avc->states |= CMAPPED; /* flag cleared at afs_inactive */
1125 afs_BozonUnlock(&avc->pvnLock, avc);
1129 if ((flags & MAP_FIXED) == 0) {
1130 #if defined(AFS_SUN57_ENV)
1131 map_addr(addr, len, off, 1, flags);
1132 #elif defined(AFS_SUN56_ENV)
1133 map_addr(addr, len, off, 1);
1135 map_addr(addr, len, (off_t) off, 1);
1137 if (*addr == NULL) {
1143 (void)as_unmap(as, *addr, len); /* unmap old address space use */
1144 /* setup the create parameter block for the call */
1145 crargs.vp = AFSTOV(avc);
1146 crargs.offset = (u_int) off;
1148 crargs.type = flags & MAP_TYPE;
1150 crargs.maxprot = maxprot;
1151 crargs.amp = (struct anon_map *)0;
1152 crargs.flags = flags & ~MAP_TYPE;
1154 code = as_map(as, *addr, len, segvn_create, (char *)&crargs);
1158 code = afs_CheckCode(code, &treq, 47);
1162 code = afs_CheckCode(code, &treq, 48);
1169 * For Now We use standard local kernel params for AFS system values. Change this
1172 afs_pathconf(vp, cmd, outdatap, credp)
1173 register struct AFS_UCRED *credp;
1178 AFS_STATCNT(afs_cntl);
1181 *outdatap = MAXLINK;
1184 *outdatap = MAXNAMLEN;
1187 *outdatap = MAXPATHLEN;
1189 case _PC_CHOWN_RESTRICTED:
1201 afs_ioctl(vnp, com, arg, flag, credp, rvalp)
1211 afs_rwlock(vnp, wlock)
1215 rw_enter(&(VTOAFS(vnp))->rwlock, (wlock ? RW_WRITER : RW_READER));
1220 afs_rwunlock(vnp, wlock)
1224 rw_exit(&(VTOAFS(vnp))->rwlock);
1229 afs_seek(vnp, ooff, noffp)
1234 register int code = 0;
1236 if ((*noffp < 0 || *noffp > MAXOFF_T))
1242 afs_frlock(vnp, cmd, ap, flag, off,
1243 #ifdef AFS_SUN59_ENV
1249 #if defined(AFS_SUN56_ENV)
1256 #ifdef AFS_SUN59_ENV
1257 struct flk_callback *flkcb;
1259 struct AFS_UCRED *credp;
1261 register afs_int32 code = 0;
1263 * Implement based on afs_lockctl
1266 #ifdef AFS_SUN59_ENV
1268 afs_warn("Don't know how to deal with flk_callback's!\n");
1270 if ((cmd == F_GETLK) || (cmd == F_O_GETLK) || (cmd == F_SETLK)
1271 || (cmd == F_SETLKW)) {
1272 #ifdef AFS_SUN53_ENV
1273 ap->l_pid = ttoproc(curthread)->p_pid;
1276 ap->l_pid = ttoproc(curthread)->p_epid;
1277 ap->l_sysid = ttoproc(curthread)->p_sysid;
1281 #ifdef AFS_SUN56_ENV
1282 code = convoff(vnp, ap, 0, off);
1284 code = convoff(vnp, ap, 0, (off_t) off);
1291 code = afs_lockctl(VTOAFS(vnp), ap, cmd, credp);
1298 afs_space(vnp, cmd, ap, flag, off, credp)
1301 #if defined(AFS_SUN56_ENV)
1308 struct AFS_UCRED *credp;
1310 register afs_int32 code = EINVAL;
1313 if ((cmd == F_FREESP)
1314 #ifdef AFS_SUN56_ENV
1315 && ((code = convoff(vnp, ap, 0, off)) == 0)) {
1317 && ((code = convoff(vnp, ap, 0, (off_t) off)) == 0)) {
1321 vattr.va_mask = AT_SIZE;
1322 vattr.va_size = ap->l_start;
1323 code = afs_setattr(VTOAFS(vnp), &vattr, 0, credp);
1331 afs_dump(vp, addr, i1, i2)
1336 AFS_STATCNT(afs_dump);
1337 afs_warn("AFS_DUMP. MUST IMPLEMENT THIS!!!\n");
1342 /* Nothing fancy here; just compare if vnodes are identical ones */
1344 struct vnode *vp1, *vp2;
1346 AFS_STATCNT(afs_cmp);
1347 return (vp1 == vp2);
1352 afs_realvp(struct vnode *vp, struct vnode **vpp)
1354 AFS_STATCNT(afs_realvp);
1360 afs_pageio(vp, pp, ui1, ui2, i1, credp)
1367 afs_warn("afs_pageio: Not implemented\n");
1373 #ifdef AFS_SUN59_ENV
1379 #ifdef AFS_SUN59_ENV
1383 afs_warn("afs_dumpctl: Not implemented\n");
1387 #ifdef AFS_SUN54_ENV
1389 afs_dispose(vp, p, fl, dn, cr)
1395 fs_dispose(vp, p, fl, dn, cr);
1399 afs_setsecattr(vp, vsecattr, flag, creds)
1401 vsecattr_t *vsecattr;
1409 afs_getsecattr(vp, vsecattr, flag, creds)
1411 vsecattr_t *vsecattr;
1415 return fs_fab_acl(vp, vsecattr, flag, creds);
1419 #ifdef AFS_GLOBAL_SUNLOCK
1420 extern int gafs_open(), gafs_close(), afs_ioctl(), gafs_access();
1421 extern int gafs_getattr(), gafs_setattr(), gafs_lookup(), gafs_create();
1422 extern int gafs_remove(), gafs_link(), gafs_rename(), gafs_mkdir();
1423 extern int gafs_rmdir(), gafs_readdir(), gafs_fsync(), gafs_symlink();
1424 extern int gafs_fid(), gafs_readlink(), fs_setfl(), afs_pathconf();
1425 extern int afs_lockctl();
1426 extern void gafs_inactive();
1428 #ifdef AFS_SUN510_ENV
1429 struct fs_operation_def afs_vnodeops_template[] = {
1430 { VOPNAME_OPEN, gafs_open },
1431 { VOPNAME_CLOSE, gafs_close },
1432 { VOPNAME_READ, afs_vmread },
1433 { VOPNAME_WRITE, afs_vmwrite },
1434 { VOPNAME_IOCTL, afs_ioctl },
1435 { VOPNAME_SETFL, fs_setfl },
1436 { VOPNAME_GETATTR, gafs_getattr },
1437 { VOPNAME_SETATTR, gafs_setattr },
1438 { VOPNAME_ACCESS, gafs_access },
1439 { VOPNAME_LOOKUP, gafs_lookup },
1440 { VOPNAME_CREATE, gafs_create },
1441 { VOPNAME_REMOVE, gafs_remove },
1442 { VOPNAME_LINK, gafs_link },
1443 { VOPNAME_RENAME, gafs_rename },
1444 { VOPNAME_MKDIR, gafs_mkdir },
1445 { VOPNAME_RMDIR, gafs_rmdir },
1446 { VOPNAME_READDIR, gafs_readdir },
1447 { VOPNAME_SYMLINK, gafs_symlink },
1448 { VOPNAME_READLINK, gafs_readlink },
1449 { VOPNAME_FSYNC, gafs_fsync },
1450 { VOPNAME_INACTIVE, gafs_inactive },
1451 { VOPNAME_FID, gafs_fid },
1452 { VOPNAME_RWLOCK, afs_rwlock },
1453 { VOPNAME_RWUNLOCK, afs_rwunlock },
1454 { VOPNAME_SEEK, afs_seek },
1455 { VOPNAME_CMP, afs_cmp },
1456 { VOPNAME_FRLOCK, afs_frlock },
1457 { VOPNAME_SPACE, afs_space },
1458 { VOPNAME_REALVP, afs_realvp },
1459 { VOPNAME_GETPAGE, afs_getpage },
1460 { VOPNAME_PUTPAGE, afs_putpage },
1461 { VOPNAME_MAP, afs_map },
1462 { VOPNAME_ADDMAP, afs_addmap },
1463 { VOPNAME_DELMAP, afs_delmap },
1464 { VOPNAME_POLL, fs_poll },
1465 { VOPNAME_DUMP, afs_dump },
1466 { VOPNAME_PATHCONF, afs_pathconf },
1467 { VOPNAME_PAGEIO, afs_pageio },
1468 { VOPNAME_DUMPCTL, afs_dumpctl },
1469 { VOPNAME_DISPOSE, afs_dispose },
1470 { VOPNAME_GETSECATTR, afs_getsecattr },
1471 { VOPNAME_SETSECATTR, afs_setsecattr },
1472 { VOPNAME_SHRLOCK, fs_shrlock },
1475 struct vnodeops *afs_ops;
1477 struct vnodeops Afs_vnodeops = {
1517 #ifdef AFS_SUN54_ENV
1522 #if defined(AFS_SUN56_ENV)
1526 struct vnodeops *afs_ops = &Afs_vnodeops;
1531 gafs_open(avcp, aflags, acred)
1532 register struct vcache **avcp;
1534 struct AFS_UCRED *acred;
1539 code = afs_open(avcp, aflags, acred);
1545 gafs_close(avc, aflags, count, offset, acred)
1548 register struct vcache *avc;
1550 struct AFS_UCRED *acred;
1555 code = afs_close(avc, aflags, count, offset, acred);
1561 gafs_getattr(avc, attrs, flags, acred)
1563 register struct vcache *avc;
1564 register struct vattr *attrs;
1565 struct AFS_UCRED *acred;
1570 code = afs_getattr(avc, attrs, flags, acred);
1576 gafs_setattr(avc, attrs, flags, acred)
1578 register struct vcache *avc;
1579 register struct vattr *attrs;
1580 struct AFS_UCRED *acred;
1585 code = afs_setattr(avc, attrs, flags, acred);
1591 gafs_access(avc, amode, flags, acred)
1593 register struct vcache *avc;
1594 register afs_int32 amode;
1595 struct AFS_UCRED *acred;
1600 code = afs_access(avc, amode, flags, acred);
1606 gafs_lookup(adp, aname, avcp, pnp, flags, rdir, acred)
1607 struct pathname *pnp;
1610 register struct vcache *adp, **avcp;
1612 struct AFS_UCRED *acred;
1617 code = afs_lookup(adp, aname, avcp, pnp, flags, rdir, acred);
1623 gafs_create(adp, aname, attrs, aexcl, amode, avcp, acred)
1624 register struct vcache *adp;
1626 struct vattr *attrs;
1629 struct vcache **avcp;
1630 struct AFS_UCRED *acred;
1635 code = afs_create(adp, aname, attrs, aexcl, amode, avcp, acred);
1640 gafs_remove(adp, aname, acred)
1641 register struct vcache *adp;
1643 struct AFS_UCRED *acred;
1648 code = afs_remove(adp, aname, acred);
1653 gafs_link(adp, avc, aname, acred)
1654 register struct vcache *avc;
1655 register struct vcache *adp;
1657 struct AFS_UCRED *acred;
1662 code = afs_link(adp, avc, aname, acred);
1667 gafs_rename(aodp, aname1, andp, aname2, acred)
1668 register struct vcache *aodp, *andp;
1669 char *aname1, *aname2;
1670 struct AFS_UCRED *acred;
1675 code = afs_rename(aodp, aname1, andp, aname2, acred);
1680 gafs_mkdir(adp, aname, attrs, avcp, acred)
1681 register struct vcache *adp;
1682 register struct vcache **avcp;
1684 struct vattr *attrs;
1685 struct AFS_UCRED *acred;
1690 code = afs_mkdir(adp, aname, attrs, avcp, acred);
1696 gafs_rmdir(adp, aname, cdirp, acred)
1697 struct vnode *cdirp;
1698 register struct vcache *adp;
1700 struct AFS_UCRED *acred;
1705 code = afs_rmdir(adp, aname, cdirp, acred);
1711 gafs_readdir(avc, auio, acred, eofp)
1713 register struct vcache *avc;
1715 struct AFS_UCRED *acred;
1720 code = afs_readdir(avc, auio, acred, eofp);
1725 gafs_symlink(adp, aname, attrs, atargetName, acred)
1726 register struct vcache *adp;
1727 register char *atargetName;
1729 struct vattr *attrs;
1730 struct AFS_UCRED *acred;
1735 code = afs_symlink(adp, aname, attrs, atargetName, acred);
1741 gafs_readlink(avc, auio, acred)
1742 register struct vcache *avc;
1744 struct AFS_UCRED *acred;
1749 code = afs_readlink(avc, auio, acred);
1754 #ifdef AFS_SUN53_ENV
1755 gafs_fsync(avc, flag, acred)
1758 gafs_fsync(avc, acred)
1760 register struct vcache *avc;
1761 struct AFS_UCRED *acred;
1766 #ifdef AFS_SUN53_ENV
1767 code = afs_fsync(avc, flag, acred);
1769 code = afs_fsync(avc, acred);
1776 afs_inactive(struct vcache *avc, struct AFS_UCRED *acred)
1778 struct vnode *vp = AFSTOV(avc);
1779 if (afs_shuttingdown)
1783 * In Solaris and HPUX s800 and HP-UX10.0 they actually call us with
1784 * v_count 1 on last reference!
1786 mutex_enter(&vp->v_lock);
1787 if (avc->vrefCount <= 0)
1788 osi_Panic("afs_inactive : v_count <=0\n");
1791 * If more than 1 don't unmap the vnode but do decrement the ref count
1794 if (vp->v_count > 0) {
1795 mutex_exit(&vp->v_lock);
1798 mutex_exit(&vp->v_lock);
1801 * Solaris calls VOP_OPEN on exec, but doesn't call VOP_CLOSE when
1802 * the executable exits. So we clean up the open count here.
1804 * Only do this for mvstat 0 vnodes: when using fakestat, we can't
1805 * lose the open count for volume roots (mvstat 2), even though they
1806 * will get VOP_INACTIVE'd when released by afs_PutFakeStat().
1808 if (avc->opens > 0 && avc->mvstat == 0 && !(avc->states & CCore))
1809 avc->opens = avc->execsOrWriters = 0;
1811 afs_InactiveVCache(avc, acred);
1815 gafs_inactive(avc, acred)
1816 register struct vcache *avc;
1817 struct AFS_UCRED *acred;
1820 afs_inactive(avc, acred);
1825 gafs_fid(avc, fidpp)
1832 code = afs_fid(avc, fidpp);
1837 #endif /* AFS_GLOBAL_SUNLOCK */