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 * Linux specific vnodeops. Also includes the glue routines required to call
14 * So far the only truly scary part is that Linux relies on the inode cache
15 * to be up to date. Don't you dare break a callback and expect an fstat
16 * to give you meaningful information. This appears to be fixed in the 2.1
17 * development kernels. As it is we can fix this now by intercepting the
21 #include <afsconfig.h>
22 #include "afs/param.h"
27 #include "afs/sysincludes.h"
28 #include "afsincludes.h"
29 #include "afs/afs_stats.h"
31 #ifdef HAVE_MM_INLINE_H
32 #include "h/mm_inline.h"
34 #include "h/pagemap.h"
35 #if defined(AFS_LINUX24_ENV)
36 #include "h/smp_lock.h"
38 #if defined(AFS_LINUX26_ENV)
39 #include "h/writeback.h"
40 #include "h/pagevec.h"
42 #if defined(AFS_CACHE_BYPASS)
44 #include "afs/afs_bypasscache.h"
48 #define pageoff(pp) pgoff2loff((pp)->index)
50 #define pageoff(pp) pp->offset
53 #if defined(AFS_LINUX26_ENV)
54 #define LockPage(pp) lock_page(pp)
55 #define UnlockPage(pp) unlock_page(pp)
58 extern struct vcache *afs_globalVp;
59 #if defined(AFS_LINUX26_ENV)
60 /* Some uses of BKL are perhaps not needed for bypass or memcache--
61 * why don't we try it out? */
62 extern struct afs_cacheOps afs_UfsCacheOps;
63 #define maybe_lock_kernel() \
65 if(afs_cacheType == &afs_UfsCacheOps) \
70 #define maybe_unlock_kernel() \
72 if(afs_cacheType == &afs_UfsCacheOps) \
75 #endif /* AFS_CACHE_BYPASS */
78 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
81 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
82 cred_t *credp = crref();
84 afs_size_t isize, offindex;
86 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
87 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
89 /* get a validated vcache entry */
90 code = afs_InitReq(&treq, credp);
92 code = afs_VerifyVCache(vcp, &treq);
97 #if defined(AFS_CACHE_BYPASS)
98 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
99 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
100 offindex = *offp >> PAGE_CACHE_SHIFT;
101 if(offindex > isize) {
107 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
110 code = do_sync_read(fp, buf, count, offp);
112 code = generic_file_read(fp, buf, count, offp);
117 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
118 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
127 /* Now we have integrated VM for writes as well as reads. generic_file_write
128 * also takes care of re-positioning the pointer if file is open in append
129 * mode. Call fake open/close to ensure we do writes of core dumps.
132 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
135 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
136 struct vrequest treq;
137 cred_t *credp = crref();
141 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
142 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
143 (fp->f_flags & O_APPEND) ? 99998 : 99999);
146 /* get a validated vcache entry */
147 code = (ssize_t) afs_InitReq(&treq, credp);
149 code = (ssize_t) afs_VerifyVCache(vcp, &treq);
151 ObtainWriteLock(&vcp->lock, 529);
153 ReleaseWriteLock(&vcp->lock);
159 code = do_sync_write(fp, buf, count, offp);
161 code = generic_file_write(fp, buf, count, offp);
166 ObtainWriteLock(&vcp->lock, 530);
167 afs_FakeClose(vcp, credp);
168 ReleaseWriteLock(&vcp->lock);
170 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
171 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
179 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
181 /* This is a complete rewrite of afs_readdir, since we can make use of
182 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
183 * handling and use of bulkstats will need to be reflected here as well.
186 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
188 extern struct DirEntry *afs_dir_GetBlob();
189 struct vcache *avc = VTOAFS(FILE_INODE(fp));
190 struct vrequest treq;
191 register struct dcache *tdc;
198 afs_size_t origOffset, tlen;
199 cred_t *credp = crref();
200 struct afs_fakestat_state fakestat;
202 #if defined(AFS_LINUX26_ENV)
206 AFS_STATCNT(afs_readdir);
208 code = afs_InitReq(&treq, credp);
213 afs_InitFakeStat(&fakestat);
214 code = afs_EvalFakeStat(&avc, &fakestat, &treq);
218 /* update the cache entry */
220 code = afs_VerifyVCache(avc, &treq);
224 /* get a reference to the entire directory */
225 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
231 ObtainSharedLock(&avc->lock, 810);
232 UpgradeSToWLock(&avc->lock, 811);
233 ObtainReadLock(&tdc->lock);
235 * Make sure that the data in the cache is current. There are two
236 * cases we need to worry about:
237 * 1. The cache data is being fetched by another process.
238 * 2. The cache data is no longer valid
240 while ((avc->states & CStatd)
241 && (tdc->dflags & DFFetching)
242 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
243 ReleaseReadLock(&tdc->lock);
244 ReleaseSharedLock(&avc->lock);
245 afs_osi_Sleep(&tdc->validPos);
246 ObtainSharedLock(&avc->lock, 812);
247 ObtainReadLock(&tdc->lock);
249 if (!(avc->states & CStatd)
250 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
251 ReleaseReadLock(&tdc->lock);
252 ReleaseSharedLock(&avc->lock);
257 /* Set the readdir-in-progress flag, and downgrade the lock
258 * to shared so others will be able to acquire a read lock.
260 avc->states |= CReadDir;
261 avc->dcreaddir = tdc;
262 avc->readdir_pid = MyPidxx;
263 ConvertWToSLock(&avc->lock);
265 /* Fill in until we get an error or we're done. This implementation
266 * takes an offset in units of blobs, rather than bytes.
269 offset = (int) fp->f_pos;
271 dirpos = BlobScan(tdc, offset);
275 de = afs_dir_GetBlob(tdc, dirpos);
279 ino = afs_calc_inum (avc->fid.Fid.Volume, ntohl(de->fid.vnode));
282 len = strlen(de->name);
284 printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %lx, dirpos %d)\n",
285 (unsigned long)&tdc->f.inode, dirpos);
286 DRelease((struct buffer *) de, 0);
287 ReleaseSharedLock(&avc->lock);
293 /* filldir returns -EINVAL when the buffer is full. */
294 #if defined(AFS_LINUX26_ENV) || ((defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE))
296 unsigned int type = DT_UNKNOWN;
297 struct VenusFid afid;
300 afid.Cell = avc->fid.Cell;
301 afid.Fid.Volume = avc->fid.Fid.Volume;
302 afid.Fid.Vnode = ntohl(de->fid.vnode);
303 afid.Fid.Unique = ntohl(de->fid.vunique);
304 if ((avc->states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
306 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
309 } else if (((tvc->states) & (CStatd | CTruth))) {
310 /* CTruth will be set if the object has
315 else if (vtype == VREG)
317 /* Don't do this until we're sure it can't be a mtpt */
318 /* else if (vtype == VLNK)
320 /* what other types does AFS support? */
322 /* clean up from afs_FindVCache */
326 * If this is NFS readdirplus, then the filler is going to
327 * call getattr on this inode, which will deadlock if we're
331 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
335 code = (*filldir) (dirbuf, de->name, len, offset, ino);
337 DRelease((struct buffer *)de, 0);
340 offset = dirpos + 1 + ((len + 16) >> 5);
342 /* If filldir didn't fill in the last one this is still pointing to that
345 fp->f_pos = (loff_t) offset;
347 ReleaseReadLock(&tdc->lock);
349 UpgradeSToWLock(&avc->lock, 813);
350 avc->states &= ~CReadDir;
352 avc->readdir_pid = 0;
353 ReleaseSharedLock(&avc->lock);
357 afs_PutFakeStat(&fakestat);
360 #if defined(AFS_LINUX26_ENV)
361 maybe_unlock_kernel();
367 /* in afs_pioctl.c */
368 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
371 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
372 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
374 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
381 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
383 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
384 cred_t *credp = crref();
385 struct vrequest treq;
389 #if defined(AFS_LINUX24_ENV)
390 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
391 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
392 vmap->vm_end - vmap->vm_start);
394 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
395 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
396 vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32,
400 /* get a validated vcache entry */
401 code = afs_InitReq(&treq, credp);
405 code = afs_VerifyVCache(vcp, &treq);
409 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
412 code = generic_file_mmap(fp, vmap);
415 vcp->states |= CMAPPED;
428 afs_linux_open(struct inode *ip, struct file *fp)
430 struct vcache *vcp = VTOAFS(ip);
431 cred_t *credp = crref();
434 #ifdef AFS_LINUX24_ENV
438 code = afs_open(&vcp, fp->f_flags, credp);
440 #ifdef AFS_LINUX24_ENV
441 maybe_unlock_kernel();
449 afs_linux_release(struct inode *ip, struct file *fp)
451 struct vcache *vcp = VTOAFS(ip);
452 cred_t *credp = crref();
455 #ifdef AFS_LINUX24_ENV
459 code = afs_close(vcp, fp->f_flags, credp);
461 #ifdef AFS_LINUX24_ENV
462 maybe_unlock_kernel();
470 #if defined(AFS_LINUX24_ENV)
471 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
473 afs_linux_fsync(struct file *fp, struct dentry *dp)
477 struct inode *ip = FILE_INODE(fp);
478 cred_t *credp = crref();
480 #ifdef AFS_LINUX24_ENV
484 code = afs_fsync(VTOAFS(ip), credp);
486 #ifdef AFS_LINUX24_ENV
487 maybe_unlock_kernel();
496 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
499 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
500 cred_t *credp = crref();
501 struct AFS_FLOCK flock;
502 /* Convert to a lock format afs_lockctl understands. */
503 memset((char *)&flock, 0, sizeof(flock));
504 flock.l_type = flp->fl_type;
505 flock.l_pid = flp->fl_pid;
507 flock.l_start = flp->fl_start;
508 flock.l_len = flp->fl_end - flp->fl_start;
510 /* Safe because there are no large files, yet */
511 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
512 if (cmd == F_GETLK64)
514 else if (cmd == F_SETLK64)
516 else if (cmd == F_SETLKW64)
518 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
521 code = afs_lockctl(vcp, &flock, cmd, credp);
524 #ifdef AFS_LINUX24_ENV
525 if ((code == 0 || flp->fl_type == F_UNLCK) &&
526 (cmd == F_SETLK || cmd == F_SETLKW)) {
527 #ifdef POSIX_LOCK_FILE_WAIT_ARG
528 code = posix_lock_file(fp, flp, 0);
530 flp->fl_flags &=~ FL_SLEEP;
531 code = posix_lock_file(fp, flp);
533 if (code && flp->fl_type != F_UNLCK) {
534 struct AFS_FLOCK flock2;
536 flock2.l_type = F_UNLCK;
538 afs_lockctl(vcp, &flock2, F_SETLK, credp);
543 /* Convert flock back to Linux's file_lock */
544 flp->fl_type = flock.l_type;
545 flp->fl_pid = flock.l_pid;
546 flp->fl_start = flock.l_start;
547 flp->fl_end = flock.l_start + flock.l_len;
554 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
556 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
558 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
559 cred_t *credp = crref();
560 struct AFS_FLOCK flock;
561 /* Convert to a lock format afs_lockctl understands. */
562 memset((char *)&flock, 0, sizeof(flock));
563 flock.l_type = flp->fl_type;
564 flock.l_pid = flp->fl_pid;
567 flock.l_len = OFFSET_MAX;
569 /* Safe because there are no large files, yet */
570 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
571 if (cmd == F_GETLK64)
573 else if (cmd == F_SETLK64)
575 else if (cmd == F_SETLKW64)
577 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
580 code = afs_lockctl(vcp, &flock, cmd, credp);
583 if ((code == 0 || flp->fl_type == F_UNLCK) &&
584 (cmd == F_SETLK || cmd == F_SETLKW)) {
585 flp->fl_flags &=~ FL_SLEEP;
586 code = flock_lock_file_wait(fp, flp);
587 if (code && flp->fl_type != F_UNLCK) {
588 struct AFS_FLOCK flock2;
590 flock2.l_type = F_UNLCK;
592 afs_lockctl(vcp, &flock2, F_SETLK, credp);
596 /* Convert flock back to Linux's file_lock */
597 flp->fl_type = flock.l_type;
598 flp->fl_pid = flock.l_pid;
606 * essentially the same as afs_fsync() but we need to get the return
607 * code for the sys_close() here, not afs_linux_release(), so call
608 * afs_StoreAllSegments() with AFS_LASTSTORE
611 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
612 afs_linux_flush(struct file *fp, fl_owner_t id)
614 afs_linux_flush(struct file *fp)
617 struct vrequest treq;
621 #if defined(AFS_CACHE_BYPASS)
627 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
635 vcp = VTOAFS(FILE_INODE(fp));
637 code = afs_InitReq(&treq, credp);
640 #if defined(AFS_CACHE_BYPASS)
641 /* If caching is bypassed for this file, or globally, just return 0 */
642 if(cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
645 ObtainReadLock(&vcp->lock);
646 if(vcp->cachingStates & FCSBypass)
648 ReleaseReadLock(&vcp->lock);
651 /* future proof: don't rely on 0 return from afs_InitReq */
656 ObtainSharedLock(&vcp->lock, 535);
657 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
658 UpgradeSToWLock(&vcp->lock, 536);
659 if (!AFS_IS_DISCONNECTED) {
660 code = afs_StoreAllSegments(vcp,
662 AFS_SYNC | AFS_LASTSTORE);
664 #if defined(AFS_DISCON_ENV)
665 if (!vcp->ddirty_flags ||
666 (vcp->ddirty_flags == VDisconShadowed)) {
668 ObtainWriteLock(&afs_DDirtyVCListLock, 710);
669 AFS_DISCON_ADD_DIRTY(vcp);
670 ReleaseWriteLock(&afs_DDirtyVCListLock);
673 /* Set disconnected write flag. */
674 vcp->ddirty_flags |= VDisconWriteOsiFlush;
678 ConvertWToSLock(&vcp->lock);
680 code = afs_CheckCode(code, &treq, 54);
681 ReleaseSharedLock(&vcp->lock);
691 #if !defined(AFS_LINUX24_ENV)
692 /* Not allowed to directly read a directory. */
694 afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos)
702 struct file_operations afs_dir_fops = {
703 #if !defined(AFS_LINUX24_ENV)
704 .read = afs_linux_dir_read,
705 .lock = afs_linux_lock,
706 .fsync = afs_linux_fsync,
708 .read = generic_read_dir,
710 .readdir = afs_linux_readdir,
711 #ifdef HAVE_UNLOCKED_IOCTL
712 .unlocked_ioctl = afs_unlocked_xioctl,
716 #ifdef HAVE_COMPAT_IOCTL
717 .compat_ioctl = afs_unlocked_xioctl,
719 .open = afs_linux_open,
720 .release = afs_linux_release,
723 struct file_operations afs_file_fops = {
724 .read = afs_linux_read,
725 .write = afs_linux_write,
726 #ifdef GENERIC_FILE_AIO_READ
727 .aio_read = generic_file_aio_read,
728 .aio_write = generic_file_aio_write,
730 #ifdef HAVE_UNLOCKED_IOCTL
731 .unlocked_ioctl = afs_unlocked_xioctl,
735 #ifdef HAVE_COMPAT_IOCTL
736 .compat_ioctl = afs_unlocked_xioctl,
738 .mmap = afs_linux_mmap,
739 .open = afs_linux_open,
740 .flush = afs_linux_flush,
741 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
742 .sendfile = generic_file_sendfile,
744 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
745 .splice_write = generic_file_splice_write,
746 .splice_read = generic_file_splice_read,
748 .release = afs_linux_release,
749 .fsync = afs_linux_fsync,
750 .lock = afs_linux_lock,
751 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
752 .flock = afs_linux_flock,
757 /**********************************************************************
758 * AFS Linux dentry operations
759 **********************************************************************/
761 /* check_bad_parent() : Checks if this dentry's vcache is a root vcache
762 * that has its mvid (parent dir's fid) pointer set to the wrong directory
763 * due to being mounted in multiple points at once. If so, check_bad_parent()
764 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
765 * dotdotfid and mtpoint fid members.
767 * dp - dentry to be checked.
771 * This dentry's vcache's mvid will be set to the correct parent directory's
773 * This root vnode's volume will have its dotdotfid and mtpoint fids set
774 * to the correct parent and mountpoint fids.
778 check_bad_parent(struct dentry *dp)
781 struct vcache *vcp = VTOAFS(dp->d_inode), *avc = NULL;
782 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
784 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
787 /* force a lookup, so vcp->mvid is fixed up */
788 afs_lookup(pvc, dp->d_name.name, &avc, credp);
789 if (!avc || vcp != avc) { /* bad, very bad.. */
790 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
791 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
792 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
793 ICL_TYPE_POINTER, dp);
796 AFS_RELE(AFSTOV(avc));
803 /* afs_linux_revalidate
804 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
807 afs_linux_revalidate(struct dentry *dp)
810 struct vcache *vcp = VTOAFS(dp->d_inode);
814 #ifdef AFS_LINUX24_ENV
820 /* Make this a fast path (no crref), since it's called so often. */
821 if (vcp->states & CStatd) {
823 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
824 check_bad_parent(dp); /* check and correct mvid */
827 #ifdef AFS_LINUX24_ENV
835 code = afs_getattr(vcp, &vattr, credp);
837 afs_fill_inode(AFSTOV(vcp), &vattr);
840 #ifdef AFS_LINUX24_ENV
841 maybe_unlock_kernel();
848 #if defined(AFS_LINUX26_ENV)
850 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
852 int err = afs_linux_revalidate(dentry);
854 generic_fillattr(dentry->d_inode, stat);
860 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
861 * In kernels 2.2.10 and above, we are passed an additional flags var which
862 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
863 * we are advised to follow the entry if it is a link or to make sure that
864 * it is a directory. But since the kernel itself checks these possibilities
865 * later on, we shouldn't have to do it until later. Perhaps in the future..
868 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
869 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
870 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
872 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
875 afs_linux_dentry_revalidate(struct dentry *dp)
879 cred_t *credp = NULL;
880 struct vcache *vcp, *pvcp, *tvc = NULL;
882 struct afs_fakestat_state fakestate;
884 #ifdef AFS_LINUX24_ENV
888 afs_InitFakeStat(&fakestate);
892 vcp = VTOAFS(dp->d_inode);
893 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
895 if (vcp == afs_globalVp)
898 if (vcp->mvstat == 1) { /* mount point */
899 if (vcp->mvid && (vcp->states & CMValid)) {
902 struct vrequest treq;
905 code = afs_InitReq(&treq, credp);
907 #ifdef AFS_DARWIN_ENV
908 (strcmp(dp->d_name.name, ".DS_Store") == 0) ||
909 (strcmp(dp->d_name.name, "Contents") == 0) ||
911 (strcmp(dp->d_name.name, ".directory") == 0)) {
915 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
917 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
918 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
919 /* a mount point, not yet replaced by its directory */
924 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
925 check_bad_parent(dp); /* check and correct mvid */
928 /* If the last looker changes, we should make sure the current
929 * looker still has permission to examine this file. This would
930 * always require a crref() which would be "slow".
932 if (vcp->last_looker != treq.uid) {
933 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
936 vcp->last_looker = treq.uid;
940 /* If the parent's DataVersion has changed or the vnode
941 * is longer valid, we need to do a full lookup. VerifyVCache
942 * isn't enough since the vnode may have been renamed.
945 if (hgetlo(pvcp->m.DataVersion) > dp->d_time || !(vcp->states & CStatd)) {
948 afs_lookup(pvcp, dp->d_name.name, &tvc, credp);
949 if (!tvc || tvc != vcp)
952 if (afs_getattr(vcp, &vattr, credp))
955 vattr2inode(AFSTOV(vcp), &vattr);
956 dp->d_time = hgetlo(pvcp->m.DataVersion);
959 /* should we always update the attributes at this point? */
960 /* unlikely--the vcache entry hasn't changed */
964 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
965 if (hgetlo(pvcp->m.DataVersion) > dp->d_time)
969 /* No change in parent's DataVersion so this negative
970 * lookup is still valid. BUT, if a server is down a
971 * negative lookup can result so there should be a
972 * liftime as well. For now, always expire.
985 afs_PutFakeStat(&fakestate);
991 shrink_dcache_parent(dp);
994 #ifdef AFS_LINUX24_ENV
995 maybe_unlock_kernel();
1000 if (have_submounts(dp))
1008 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1010 struct vcache *vcp = VTOAFS(ip);
1013 (void) afs_InactiveVCache(vcp, NULL);
1015 #ifdef DCACHE_NFSFS_RENAMED
1016 #ifdef AFS_LINUX26_ENV
1017 spin_lock(&dp->d_lock);
1019 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
1020 #ifdef AFS_LINUX26_ENV
1021 spin_unlock(&dp->d_lock);
1029 afs_dentry_delete(struct dentry *dp)
1031 if (dp->d_inode && (VTOAFS(dp->d_inode)->states & CUnlinked))
1032 return 1; /* bad inode? */
1037 struct dentry_operations afs_dentry_operations = {
1038 .d_revalidate = afs_linux_dentry_revalidate,
1039 .d_delete = afs_dentry_delete,
1040 .d_iput = afs_dentry_iput,
1043 /**********************************************************************
1044 * AFS Linux inode operations
1045 **********************************************************************/
1049 * Merely need to set enough of vattr to get us through the create. Note
1050 * that the higher level code (open_namei) will take care of any tuncation
1051 * explicitly. Exclusive open is also taken care of in open_namei.
1053 * name is in kernel space at this point.
1056 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1057 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1058 struct nameidata *nd)
1060 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1064 cred_t *credp = crref();
1065 const char *name = dp->d_name.name;
1070 vattr.va_mode = mode;
1071 vattr.va_type = mode & S_IFMT;
1073 #if defined(AFS_LINUX26_ENV)
1074 maybe_lock_kernel();
1077 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1081 struct inode *ip = AFSTOV(vcp);
1083 afs_getattr(vcp, &vattr, credp);
1084 afs_fill_inode(ip, &vattr);
1085 insert_inode_hash(ip);
1086 dp->d_op = &afs_dentry_operations;
1087 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1088 d_instantiate(dp, ip);
1092 #if defined(AFS_LINUX26_ENV)
1093 maybe_unlock_kernel();
1099 /* afs_linux_lookup */
1100 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1101 static struct dentry *
1102 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1103 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1104 struct nameidata *nd)
1106 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1110 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1113 cred_t *credp = crref();
1114 struct vcache *vcp = NULL;
1115 const char *comp = dp->d_name.name;
1116 struct inode *ip = NULL;
1117 #if defined(AFS_LINUX26_ENV)
1118 struct dentry *newdp = NULL;
1122 #if defined(AFS_LINUX26_ENV)
1123 maybe_lock_kernel();
1126 code = afs_lookup(VTOAFS(dip), comp, &vcp, credp);
1132 afs_getattr(vcp, &vattr, credp);
1133 afs_fill_inode(ip, &vattr);
1135 #ifdef HAVE_KERNEL_HLIST_UNHASHED
1136 hlist_unhashed(&ip->i_hash)
1137 #elif defined(AFS_LINUX26_ENV)
1138 ip->i_hash.pprev == NULL
1140 ip->i_hash.prev == NULL
1143 insert_inode_hash(ip);
1145 dp->d_op = &afs_dentry_operations;
1146 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1149 #if defined(AFS_LINUX24_ENV)
1150 if (ip && S_ISDIR(ip->i_mode)) {
1151 struct dentry *alias;
1153 /* Try to invalidate an existing alias in favor of our new one */
1154 alias = d_find_alias(ip);
1155 #if defined(AFS_LINUX26_ENV)
1156 /* But not if it's disconnected; then we want d_splice_alias below */
1157 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1161 if (d_invalidate(alias) == 0) {
1165 #if defined(AFS_LINUX26_ENV)
1174 #if defined(AFS_LINUX26_ENV)
1175 newdp = d_splice_alias(ip, dp);
1180 #if defined(AFS_LINUX26_ENV)
1181 maybe_unlock_kernel();
1185 /* It's ok for the file to not be found. That's noted by the caller by
1186 * seeing that the dp->d_inode field is NULL.
1188 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1189 #if defined(AFS_LINUX26_ENV)
1190 if (!code || code == ENOENT)
1197 return ERR_PTR(-code);
1206 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1209 cred_t *credp = crref();
1210 const char *name = newdp->d_name.name;
1211 struct inode *oldip = olddp->d_inode;
1213 /* If afs_link returned the vnode, we could instantiate the
1214 * dentry. Since it's not, we drop this one and do a new lookup.
1219 code = afs_link(VTOAFS(oldip), VTOAFS(dip), name, credp);
1227 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1230 cred_t *credp = crref();
1231 const char *name = dp->d_name.name;
1232 struct vcache *tvc = VTOAFS(dp->d_inode);
1234 #if defined(AFS_LINUX26_ENV)
1235 maybe_lock_kernel();
1237 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1238 && !(tvc->states & CUnlinked)) {
1239 struct dentry *__dp;
1241 extern char *afs_newname();
1250 osi_FreeSmallSpace(__name);
1251 __name = afs_newname();
1254 __dp = lookup_one_len(__name, dp->d_parent, strlen(__name));
1258 } while (__dp->d_inode != NULL);
1261 code = afs_rename(VTOAFS(dip), dp->d_name.name, VTOAFS(dip), __dp->d_name.name, credp);
1263 tvc->mvid = (void *) __name;
1266 crfree(tvc->uncred);
1268 tvc->uncred = credp;
1269 tvc->states |= CUnlinked;
1270 #ifdef DCACHE_NFSFS_RENAMED
1271 #ifdef AFS_LINUX26_ENV
1272 spin_lock(&dp->d_lock);
1274 dp->d_flags |= DCACHE_NFSFS_RENAMED;
1275 #ifdef AFS_LINUX26_ENV
1276 spin_unlock(&dp->d_lock);
1280 osi_FreeSmallSpace(__name);
1285 __dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1294 code = afs_remove(VTOAFS(dip), name, credp);
1299 #if defined(AFS_LINUX26_ENV)
1300 maybe_unlock_kernel();
1308 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1311 cred_t *credp = crref();
1313 const char *name = dp->d_name.name;
1315 /* If afs_symlink returned the vnode, we could instantiate the
1316 * dentry. Since it's not, we drop this one and do a new lookup.
1322 code = afs_symlink(VTOAFS(dip), name, &vattr, target, credp);
1329 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1332 cred_t *credp = crref();
1333 struct vcache *tvcp = NULL;
1335 const char *name = dp->d_name.name;
1337 #if defined(AFS_LINUX26_ENV)
1338 maybe_lock_kernel();
1341 vattr.va_mask = ATTR_MODE;
1342 vattr.va_mode = mode;
1344 code = afs_mkdir(VTOAFS(dip), name, &vattr, &tvcp, credp);
1347 struct inode *ip = AFSTOV(tvcp);
1349 afs_getattr(tvcp, &vattr, credp);
1350 afs_fill_inode(ip, &vattr);
1352 dp->d_op = &afs_dentry_operations;
1353 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1354 d_instantiate(dp, ip);
1358 #if defined(AFS_LINUX26_ENV)
1359 maybe_unlock_kernel();
1366 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1369 cred_t *credp = crref();
1370 const char *name = dp->d_name.name;
1372 /* locking kernel conflicts with glock? */
1375 code = afs_rmdir(VTOAFS(dip), name, credp);
1378 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1379 * that failed because a directory is not empty. So, we map
1380 * EEXIST to ENOTEMPTY on linux.
1382 if (code == EEXIST) {
1396 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1397 struct inode *newip, struct dentry *newdp)
1400 cred_t *credp = crref();
1401 const char *oldname = olddp->d_name.name;
1402 const char *newname = newdp->d_name.name;
1403 struct dentry *rehash = NULL;
1405 #if defined(AFS_LINUX26_ENV)
1406 /* Prevent any new references during rename operation. */
1407 maybe_lock_kernel();
1409 if (!d_unhashed(newdp)) {
1414 if (!list_empty(&newdp->d_hash)) {
1420 #if defined(AFS_LINUX24_ENV)
1421 if (atomic_read(&olddp->d_count) > 1)
1422 shrink_dcache_parent(olddp);
1426 code = afs_rename(VTOAFS(oldip), oldname, VTOAFS(newip), newname, credp);
1430 olddp->d_time = 0; /* force to revalidate */
1435 #if defined(AFS_LINUX26_ENV)
1436 maybe_unlock_kernel();
1444 /* afs_linux_ireadlink
1445 * Internal readlink which can return link contents to user or kernel space.
1446 * Note that the buffer is NOT supposed to be null-terminated.
1449 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1452 cred_t *credp = crref();
1456 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1457 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1461 return maxlen - tuio.uio_resid;
1466 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1467 /* afs_linux_readlink
1468 * Fill target (which is in user space) with contents of symlink.
1471 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1474 struct inode *ip = dp->d_inode;
1477 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1483 /* afs_linux_follow_link
1484 * a file system dependent link following routine.
1486 #if defined(AFS_LINUX24_ENV)
1487 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1492 name = osi_Alloc(PATH_MAX);
1498 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1506 code = vfs_follow_link(nd, name);
1509 osi_Free(name, PATH_MAX);
1514 #else /* !defined(AFS_LINUX24_ENV) */
1516 static struct dentry *
1517 afs_linux_follow_link(struct dentry *dp, struct dentry *basep,
1518 unsigned int follow)
1526 name = osi_Alloc(PATH_MAX + 1);
1530 return ERR_PTR(-EIO);
1533 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1538 res = ERR_PTR(code);
1541 res = lookup_dentry(name, basep, follow);
1545 osi_Free(name, PATH_MAX + 1);
1549 #endif /* AFS_LINUX24_ENV */
1550 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1552 #if defined(AFS_CACHE_BYPASS)
1554 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1556 /* The kernel calls readpages before trying readpage, with a list of
1557 * pages. The readahead algorithm expands num_pages when it thinks
1558 * the application will benefit. Unlike readpage, the pages are not
1559 * necessarily allocated. If we do not a) allocate required pages and
1560 * b) remove them from page_list, linux will re-enter at afs_linux_readpage
1561 * for each required page (and the page will be pre-allocated) */
1564 afs_linux_readpages(struct file *fp, struct address_space *mapping,
1565 struct list_head *page_list, unsigned num_pages)
1570 struct iovec* iovecp;
1571 struct nocache_read_request *ancr;
1572 struct page *pp, *ppt;
1573 struct pagevec lrupv;
1577 struct inode *ip = FILE_INODE(fp);
1578 struct vcache *avc = VTOAFS(ip);
1579 afs_int32 bypasscache = 0; /* bypass for this read */
1580 afs_int32 base_index = 0;
1581 afs_int32 page_count = 0;
1586 switch(cache_bypass_strategy) {
1587 case NEVER_BYPASS_CACHE:
1589 case ALWAYS_BYPASS_CACHE:
1592 case LARGE_FILES_BYPASS_CACHE:
1593 if(i_size_read(ip) > cache_bypass_threshold) {
1601 /* In the new incarnation of selective caching, a file's caching policy
1602 * can change, eg because file size exceeds threshold, etc. */
1603 trydo_cache_transition(avc, credp, bypasscache);
1606 while(!list_empty(page_list)) {
1607 pp = list_entry(page_list->prev, struct page, lru);
1612 /* background thread must free: iovecp, auio, ancr */
1613 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
1615 auio = osi_Alloc(sizeof(uio_t));
1616 auio->uio_iov = iovecp;
1617 auio->uio_iovcnt = num_pages;
1618 auio->uio_flag = UIO_READ;
1619 auio->uio_seg = AFS_UIOSYS;
1620 auio->uio_resid = num_pages * PAGE_SIZE;
1622 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1624 ancr->offset = auio->uio_offset;
1625 ancr->length = auio->uio_resid;
1627 pagevec_init(&lrupv, 0);
1629 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
1631 if(list_empty(page_list))
1634 pp = list_entry(page_list->prev, struct page, lru);
1635 /* If we allocate a page and don't remove it from page_list,
1636 * the page cache gets upset. */
1638 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1639 if(pp->index > isize) {
1646 offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1647 auio->uio_offset = offset;
1648 base_index = pp->index;
1650 iovecp[page_ix].iov_len = PAGE_SIZE;
1651 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
1652 if(base_index != pp->index) {
1655 page_cache_release(pp);
1656 iovecp[page_ix].iov_base = (void *) 0;
1664 page_cache_release(pp);
1665 iovecp[page_ix].iov_base = (void *) 0;
1668 if(!PageLocked(pp)) {
1672 /* save the page for background map */
1673 iovecp[page_ix].iov_base = (void*) pp;
1675 /* and put it on the LRU cache */
1676 if (!pagevec_add(&lrupv, pp))
1677 __pagevec_lru_add(&lrupv);
1681 /* If there were useful pages in the page list, make sure all pages
1682 * are in the LRU cache, then schedule the read */
1684 pagevec_lru_add(&lrupv);
1685 code = afs_ReadNoCache(avc, ancr, credp);
1687 /* If there is nothing for the background thread to handle,
1688 * it won't be freeing the things that we never gave it */
1689 osi_Free(iovecp, num_pages * sizeof(struct iovec));
1690 osi_Free(auio, sizeof(uio_t));
1691 osi_Free(ancr, sizeof(struct nocache_read_request));
1693 /* we do not flush, release, or unmap pages--that will be
1694 * done for us by the background thread as each page comes in
1695 * from the fileserver */
1702 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
1703 #endif /* defined(AFS_CACHE_BYPASS */
1706 /* afs_linux_readpage
1707 * all reads come through here. A strategy-like read call.
1710 afs_linux_readpage(struct file *fp, struct page *pp)
1713 cred_t *credp = crref();
1714 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1716 afs_offs_t offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1718 ulong address = afs_linux_page_address(pp);
1719 afs_offs_t offset = pageoff(pp);
1721 #if defined(AFS_CACHE_BYPASS)
1722 afs_int32 bypasscache = 0; /* bypass for this read */
1723 struct nocache_read_request *ancr;
1727 struct iovec *iovecp;
1728 struct inode *ip = FILE_INODE(fp);
1729 afs_int32 cnt = page_count(pp);
1730 struct vcache *avc = VTOAFS(ip);
1732 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1736 atomic_add(1, &pp->count);
1737 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1738 clear_bit(PG_error, &pp->flags);
1740 #if defined(AFS_CACHE_BYPASS)
1741 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1742 /* If the page is past the end of the file, skip it */
1743 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1744 if(pp->index > isize) {
1751 /* if bypasscache, receiver frees, else we do */
1752 auio = osi_Alloc(sizeof(uio_t));
1753 iovecp = osi_Alloc(sizeof(struct iovec));
1755 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1758 #if defined(AFS_CACHE_BYPASS)
1760 switch(cache_bypass_strategy) {
1761 case NEVER_BYPASS_CACHE:
1763 case ALWAYS_BYPASS_CACHE:
1766 case LARGE_FILES_BYPASS_CACHE:
1767 if(i_size_read(ip) > cache_bypass_threshold) {
1775 /* In the new incarnation of selective caching, a file's caching policy
1776 * can change, eg because file size exceeds threshold, etc. */
1777 trydo_cache_transition(avc, credp, bypasscache);
1782 /* save the page for background map */
1783 auio->uio_iov->iov_base = (void*) pp;
1784 /* the background thread will free this */
1785 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1787 ancr->offset = offset;
1788 ancr->length = PAGE_SIZE;
1790 maybe_lock_kernel();
1791 code = afs_ReadNoCache(avc, ancr, credp);
1792 maybe_unlock_kernel();
1794 goto done; /* skips release page, doing it in bg thread */
1798 #ifdef AFS_LINUX24_ENV
1799 maybe_lock_kernel();
1802 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip, ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32, 99999); /* not a possible code value */
1804 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1806 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1807 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1810 #ifdef AFS_LINUX24_ENV
1811 maybe_unlock_kernel();
1814 /* XXX valid for no-cache also? Check last bits of files... :)
1815 * Cognate code goes in afs_NoCacheFetchProc. */
1816 if (auio->uio_resid) /* zero remainder of page */
1817 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1820 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1821 flush_dcache_page(pp);
1822 SetPageUptodate(pp);
1824 set_bit(PG_uptodate, &pp->flags);
1828 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1832 clear_bit(PG_locked, &pp->flags);
1837 #if defined(AFS_CACHE_BYPASS)
1839 /* do not call afs_GetDCache if cache is bypassed */
1845 /* free if not bypassing cache */
1846 osi_Free(auio, sizeof(uio_t));
1847 osi_Free(iovecp, sizeof(struct iovec));
1849 if (!code && AFS_CHUNKOFFSET(offset) == 0) {
1851 struct vrequest treq;
1854 code = afs_InitReq(&treq, credp);
1855 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
1856 tdc = afs_FindDCache(avc, offset);
1858 if (!(tdc->mflags & DFNextStarted))
1859 afs_PrefetchChunk(avc, tdc, credp, &treq);
1862 ReleaseWriteLock(&avc->lock);
1873 #if defined(AFS_LINUX24_ENV)
1875 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1876 unsigned long offset, unsigned int count)
1878 struct vcache *vcp = VTOAFS(ip);
1887 buffer = kmap(pp) + offset;
1888 base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
1891 maybe_lock_kernel();
1893 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1894 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1895 ICL_TYPE_INT32, 99999);
1897 ObtainReadLock(&vcp->lock);
1898 if (vcp->states & CPageWrite) {
1899 ReleaseReadLock(&vcp->lock);
1901 maybe_unlock_kernel();
1904 #ifdef AFS_LINUX26_ENV
1905 #if defined(WRITEPAGE_ACTIVATE)
1906 return WRITEPAGE_ACTIVATE;
1908 return AOP_WRITEPAGE_ACTIVATE;
1911 /* should mark it dirty? */
1915 ReleaseReadLock(&vcp->lock);
1917 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1919 code = afs_write(vcp, &tuio, f_flags, credp, 0);
1921 ip->i_size = vcp->m.Length;
1922 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
1925 struct vrequest treq;
1927 ObtainWriteLock(&vcp->lock, 533);
1928 if (!afs_InitReq(&treq, credp))
1929 code = afs_DoPartialWrite(vcp, &treq);
1930 ReleaseWriteLock(&vcp->lock);
1932 code = code ? -code : count - tuio.uio_resid;
1934 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1935 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1936 ICL_TYPE_INT32, code);
1939 maybe_unlock_kernel();
1948 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
1949 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
1951 afs_linux_writepage(struct page *pp)
1954 struct address_space *mapping = pp->mapping;
1955 struct inode *inode;
1956 unsigned long end_index;
1957 unsigned offset = PAGE_CACHE_SIZE;
1960 #if defined(AFS_LINUX26_ENV)
1961 if (PageReclaim(pp)) {
1962 # if defined(WRITEPAGE_ACTIVATE)
1963 return WRITEPAGE_ACTIVATE;
1965 return AOP_WRITEPAGE_ACTIVATE;
1969 if (PageLaunder(pp)) {
1970 return(fail_writepage(pp));
1974 inode = (struct inode *)mapping->host;
1975 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1978 if (pp->index < end_index)
1980 /* things got complicated... */
1981 offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
1982 /* OK, are we completely out? */
1983 if (pp->index >= end_index + 1 || !offset)
1986 status = afs_linux_writepage_sync(inode, pp, 0, offset);
1987 SetPageUptodate(pp);
1989 if (status == offset)
1995 /* afs_linux_updatepage
1996 * What one would have thought was writepage - write dirty page to file.
1997 * Called from generic_file_write. buffer is still in user space. pagep
1998 * has been filled in with old data if we're updating less than a page.
2001 afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset,
2002 unsigned int count, int sync)
2004 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
2005 u8 *page_addr = (u8 *) afs_linux_page_address(pp);
2011 set_bit(PG_locked, &pp->flags);
2015 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2016 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2017 ICL_TYPE_INT32, 99999);
2018 setup_uio(&tuio, &iovec, page_addr + offset,
2019 (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE,
2022 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
2024 ip->i_size = vcp->m.Length;
2025 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
2028 struct vrequest treq;
2030 ObtainWriteLock(&vcp->lock, 533);
2031 vcp->m.Date = osi_Time(); /* set modification time */
2032 if (!afs_InitReq(&treq, credp))
2033 code = afs_DoPartialWrite(vcp, &treq);
2034 ReleaseWriteLock(&vcp->lock);
2037 code = code ? -code : count - tuio.uio_resid;
2038 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2039 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2040 ICL_TYPE_INT32, code);
2045 clear_bit(PG_locked, &pp->flags);
2050 /* afs_linux_permission
2051 * Check access rights - returns error if can't check or permission denied.
2054 #ifdef IOP_PERMISSION_TAKES_NAMEIDATA
2055 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2057 afs_linux_permission(struct inode *ip, int mode)
2061 cred_t *credp = crref();
2065 if (mode & MAY_EXEC)
2067 if (mode & MAY_READ)
2069 if (mode & MAY_WRITE)
2071 code = afs_access(VTOAFS(ip), tmp, credp);
2078 #if defined(AFS_LINUX24_ENV)
2080 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2085 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
2086 offset, to - offset);
2087 #if !defined(AFS_LINUX26_ENV)
2095 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2098 /* sometime between 2.4.0 and 2.4.19, the callers of prepare_write began to
2099 call kmap directly instead of relying on us to do it */
2100 #if !defined(AFS_LINUX26_ENV)
2106 extern int afs_notify_change(struct dentry *dp, struct iattr *iattrp);
2109 static struct inode_operations afs_file_iops = {
2110 #if defined(AFS_LINUX26_ENV)
2111 .permission = afs_linux_permission,
2112 .getattr = afs_linux_getattr,
2113 .setattr = afs_notify_change,
2114 #elif defined(AFS_LINUX24_ENV)
2115 .permission = afs_linux_permission,
2116 .revalidate = afs_linux_revalidate,
2117 .setattr = afs_notify_change,
2119 .default_file_ops = &afs_file_fops,
2120 .readpage = afs_linux_readpage,
2121 .revalidate = afs_linux_revalidate,
2122 .updatepage = afs_linux_updatepage,
2126 #if defined(AFS_LINUX24_ENV)
2127 static struct address_space_operations afs_file_aops = {
2128 .readpage = afs_linux_readpage,
2129 #if defined(AFS_CACHE_BYPASS) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2130 .readpages = afs_linux_readpages,
2132 .writepage = afs_linux_writepage,
2133 .commit_write = afs_linux_commit_write,
2134 .prepare_write = afs_linux_prepare_write,
2139 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2140 * by what sort of operation is allowed.....
2143 static struct inode_operations afs_dir_iops = {
2144 #if !defined(AFS_LINUX24_ENV)
2145 .default_file_ops = &afs_dir_fops,
2147 .setattr = afs_notify_change,
2149 .create = afs_linux_create,
2150 .lookup = afs_linux_lookup,
2151 .link = afs_linux_link,
2152 .unlink = afs_linux_unlink,
2153 .symlink = afs_linux_symlink,
2154 .mkdir = afs_linux_mkdir,
2155 .rmdir = afs_linux_rmdir,
2156 .rename = afs_linux_rename,
2157 #if defined(AFS_LINUX26_ENV)
2158 .getattr = afs_linux_getattr,
2160 .revalidate = afs_linux_revalidate,
2162 .permission = afs_linux_permission,
2165 /* We really need a separate symlink set of ops, since do_follow_link()
2166 * determines if it _is_ a link by checking if the follow_link op is set.
2168 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2170 afs_symlink_filler(struct file *file, struct page *page)
2172 struct inode *ip = (struct inode *)page->mapping->host;
2173 char *p = (char *)kmap(page);
2176 maybe_lock_kernel();
2178 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2183 p[code] = '\0'; /* null terminate? */
2184 maybe_unlock_kernel();
2186 SetPageUptodate(page);
2192 maybe_unlock_kernel();
2200 static struct address_space_operations afs_symlink_aops = {
2201 .readpage = afs_symlink_filler
2203 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2205 static struct inode_operations afs_symlink_iops = {
2206 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2207 .readlink = page_readlink,
2208 #if defined(HAVE_KERNEL_PAGE_FOLLOW_LINK)
2209 .follow_link = page_follow_link,
2211 .follow_link = page_follow_link_light,
2212 .put_link = page_put_link,
2214 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2215 .readlink = afs_linux_readlink,
2216 .follow_link = afs_linux_follow_link,
2217 #if !defined(AFS_LINUX24_ENV)
2218 .permission = afs_linux_permission,
2219 .revalidate = afs_linux_revalidate,
2221 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2222 #if defined(AFS_LINUX24_ENV)
2223 .setattr = afs_notify_change,
2228 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2232 vattr2inode(ip, vattr);
2234 /* Reset ops if symlink or directory. */
2235 if (S_ISREG(ip->i_mode)) {
2236 ip->i_op = &afs_file_iops;
2237 #if defined(AFS_LINUX24_ENV)
2238 ip->i_fop = &afs_file_fops;
2239 ip->i_data.a_ops = &afs_file_aops;
2242 } else if (S_ISDIR(ip->i_mode)) {
2243 ip->i_op = &afs_dir_iops;
2244 #if defined(AFS_LINUX24_ENV)
2245 ip->i_fop = &afs_dir_fops;
2248 } else if (S_ISLNK(ip->i_mode)) {
2249 ip->i_op = &afs_symlink_iops;
2250 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2251 ip->i_data.a_ops = &afs_symlink_aops;
2252 ip->i_mapping = &ip->i_data;