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)
56 extern struct backing_dev_info afs_backing_dev_info;
59 extern struct vcache *afs_globalVp;
60 extern int afs_notify_change(struct dentry *dp, struct iattr *iattrp);
61 #if defined(AFS_LINUX26_ENV)
62 /* Some uses of BKL are perhaps not needed for bypass or memcache--
63 * why don't we try it out? */
64 extern struct afs_cacheOps afs_UfsCacheOps;
65 #define maybe_lock_kernel() \
67 if(afs_cacheType == &afs_UfsCacheOps) \
72 #define maybe_unlock_kernel() \
74 if(afs_cacheType == &afs_UfsCacheOps) \
77 #endif /* AFS_CACHE_BYPASS */
80 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
83 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
84 cred_t *credp = crref();
86 afs_size_t isize, offindex;
88 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
89 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
91 /* get a validated vcache entry */
92 code = afs_InitReq(&treq, credp);
94 code = afs_VerifyVCache(vcp, &treq);
99 #if defined(AFS_CACHE_BYPASS)
100 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
101 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
102 offindex = *offp >> PAGE_CACHE_SHIFT;
103 if(offindex > isize) {
109 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
112 code = do_sync_read(fp, buf, count, offp);
114 code = generic_file_read(fp, buf, count, offp);
119 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
120 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
129 /* Now we have integrated VM for writes as well as reads. generic_file_write
130 * also takes care of re-positioning the pointer if file is open in append
131 * mode. Call fake open/close to ensure we do writes of core dumps.
134 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
137 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
138 struct vrequest treq;
139 cred_t *credp = crref();
143 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
144 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
145 (fp->f_flags & O_APPEND) ? 99998 : 99999);
148 /* get a validated vcache entry */
149 code = (ssize_t) afs_InitReq(&treq, credp);
151 code = (ssize_t) afs_VerifyVCache(vcp, &treq);
153 ObtainWriteLock(&vcp->lock, 529);
155 ReleaseWriteLock(&vcp->lock);
161 code = do_sync_write(fp, buf, count, offp);
163 code = generic_file_write(fp, buf, count, offp);
168 ObtainWriteLock(&vcp->lock, 530);
169 afs_FakeClose(vcp, credp);
170 ReleaseWriteLock(&vcp->lock);
172 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
173 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
181 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
183 /* This is a complete rewrite of afs_readdir, since we can make use of
184 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
185 * handling and use of bulkstats will need to be reflected here as well.
188 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
190 extern struct DirEntry *afs_dir_GetBlob();
191 struct vcache *avc = VTOAFS(FILE_INODE(fp));
192 struct vrequest treq;
193 register struct dcache *tdc;
200 afs_size_t origOffset, tlen;
201 cred_t *credp = crref();
202 struct afs_fakestat_state fakestat;
204 #if defined(AFS_LINUX26_ENV)
208 AFS_STATCNT(afs_readdir);
210 code = afs_InitReq(&treq, credp);
215 afs_InitFakeStat(&fakestat);
216 code = afs_EvalFakeStat(&avc, &fakestat, &treq);
220 /* update the cache entry */
222 code = afs_VerifyVCache(avc, &treq);
226 /* get a reference to the entire directory */
227 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
233 ObtainSharedLock(&avc->lock, 810);
234 UpgradeSToWLock(&avc->lock, 811);
235 ObtainReadLock(&tdc->lock);
237 * Make sure that the data in the cache is current. There are two
238 * cases we need to worry about:
239 * 1. The cache data is being fetched by another process.
240 * 2. The cache data is no longer valid
242 while ((avc->states & CStatd)
243 && (tdc->dflags & DFFetching)
244 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
245 ReleaseReadLock(&tdc->lock);
246 ReleaseSharedLock(&avc->lock);
247 afs_osi_Sleep(&tdc->validPos);
248 ObtainSharedLock(&avc->lock, 812);
249 ObtainReadLock(&tdc->lock);
251 if (!(avc->states & CStatd)
252 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
253 ReleaseReadLock(&tdc->lock);
254 ReleaseSharedLock(&avc->lock);
259 /* Set the readdir-in-progress flag, and downgrade the lock
260 * to shared so others will be able to acquire a read lock.
262 avc->states |= CReadDir;
263 avc->dcreaddir = tdc;
264 avc->readdir_pid = MyPidxx;
265 ConvertWToSLock(&avc->lock);
267 /* Fill in until we get an error or we're done. This implementation
268 * takes an offset in units of blobs, rather than bytes.
271 offset = (int) fp->f_pos;
273 dirpos = BlobScan(tdc, offset);
277 de = afs_dir_GetBlob(tdc, dirpos);
281 ino = afs_calc_inum (avc->fid.Fid.Volume, ntohl(de->fid.vnode));
284 len = strlen(de->name);
286 printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %lx, dirpos %d)\n",
287 (unsigned long)&tdc->f.inode, dirpos);
288 DRelease((struct buffer *) de, 0);
289 ReleaseSharedLock(&avc->lock);
295 /* filldir returns -EINVAL when the buffer is full. */
296 #if defined(AFS_LINUX26_ENV) || ((defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE))
298 unsigned int type = DT_UNKNOWN;
299 struct VenusFid afid;
302 afid.Cell = avc->fid.Cell;
303 afid.Fid.Volume = avc->fid.Fid.Volume;
304 afid.Fid.Vnode = ntohl(de->fid.vnode);
305 afid.Fid.Unique = ntohl(de->fid.vunique);
306 if ((avc->states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
308 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
311 } else if (((tvc->states) & (CStatd | CTruth))) {
312 /* CTruth will be set if the object has
317 else if (vtype == VREG)
319 /* Don't do this until we're sure it can't be a mtpt */
320 /* else if (vtype == VLNK)
322 /* what other types does AFS support? */
324 /* clean up from afs_FindVCache */
328 * If this is NFS readdirplus, then the filler is going to
329 * call getattr on this inode, which will deadlock if we're
333 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
337 code = (*filldir) (dirbuf, de->name, len, offset, ino);
339 DRelease((struct buffer *)de, 0);
342 offset = dirpos + 1 + ((len + 16) >> 5);
344 /* If filldir didn't fill in the last one this is still pointing to that
347 fp->f_pos = (loff_t) offset;
349 ReleaseReadLock(&tdc->lock);
351 UpgradeSToWLock(&avc->lock, 813);
352 avc->states &= ~CReadDir;
354 avc->readdir_pid = 0;
355 ReleaseSharedLock(&avc->lock);
359 afs_PutFakeStat(&fakestat);
362 #if defined(AFS_LINUX26_ENV)
363 maybe_unlock_kernel();
369 /* in afs_pioctl.c */
370 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
373 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
374 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
376 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
383 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
385 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
386 cred_t *credp = crref();
387 struct vrequest treq;
391 #if defined(AFS_LINUX24_ENV)
392 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
393 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
394 vmap->vm_end - vmap->vm_start);
396 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
397 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
398 vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32,
402 /* get a validated vcache entry */
403 code = afs_InitReq(&treq, credp);
407 code = afs_VerifyVCache(vcp, &treq);
411 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
414 code = generic_file_mmap(fp, vmap);
417 vcp->states |= CMAPPED;
430 afs_linux_open(struct inode *ip, struct file *fp)
432 struct vcache *vcp = VTOAFS(ip);
433 cred_t *credp = crref();
436 #ifdef AFS_LINUX24_ENV
440 code = afs_open(&vcp, fp->f_flags, credp);
442 #ifdef AFS_LINUX24_ENV
443 maybe_unlock_kernel();
451 afs_linux_release(struct inode *ip, struct file *fp)
453 struct vcache *vcp = VTOAFS(ip);
454 cred_t *credp = crref();
457 #ifdef AFS_LINUX24_ENV
461 code = afs_close(vcp, fp->f_flags, credp);
463 #ifdef AFS_LINUX24_ENV
464 maybe_unlock_kernel();
472 #if defined(AFS_LINUX24_ENV)
473 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
475 afs_linux_fsync(struct file *fp, struct dentry *dp)
479 struct inode *ip = FILE_INODE(fp);
480 cred_t *credp = crref();
482 #ifdef AFS_LINUX24_ENV
486 code = afs_fsync(VTOAFS(ip), credp);
488 #ifdef AFS_LINUX24_ENV
489 maybe_unlock_kernel();
498 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
501 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
502 cred_t *credp = crref();
503 struct AFS_FLOCK flock;
504 /* Convert to a lock format afs_lockctl understands. */
505 memset((char *)&flock, 0, sizeof(flock));
506 flock.l_type = flp->fl_type;
507 flock.l_pid = flp->fl_pid;
509 flock.l_start = flp->fl_start;
510 flock.l_len = flp->fl_end - flp->fl_start;
512 /* Safe because there are no large files, yet */
513 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
514 if (cmd == F_GETLK64)
516 else if (cmd == F_SETLK64)
518 else if (cmd == F_SETLKW64)
520 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
523 code = afs_lockctl(vcp, &flock, cmd, credp);
526 #ifdef AFS_LINUX24_ENV
527 if ((code == 0 || flp->fl_type == F_UNLCK) &&
528 (cmd == F_SETLK || cmd == F_SETLKW)) {
529 #ifdef POSIX_LOCK_FILE_WAIT_ARG
530 code = posix_lock_file(fp, flp, 0);
532 flp->fl_flags &=~ FL_SLEEP;
533 code = posix_lock_file(fp, flp);
535 if (code && flp->fl_type != F_UNLCK) {
536 struct AFS_FLOCK flock2;
538 flock2.l_type = F_UNLCK;
540 afs_lockctl(vcp, &flock2, F_SETLK, credp);
545 /* Convert flock back to Linux's file_lock */
546 flp->fl_type = flock.l_type;
547 flp->fl_pid = flock.l_pid;
548 flp->fl_start = flock.l_start;
549 flp->fl_end = flock.l_start + flock.l_len;
556 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
558 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
560 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
561 cred_t *credp = crref();
562 struct AFS_FLOCK flock;
563 /* Convert to a lock format afs_lockctl understands. */
564 memset((char *)&flock, 0, sizeof(flock));
565 flock.l_type = flp->fl_type;
566 flock.l_pid = flp->fl_pid;
569 flock.l_len = OFFSET_MAX;
571 /* Safe because there are no large files, yet */
572 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
573 if (cmd == F_GETLK64)
575 else if (cmd == F_SETLK64)
577 else if (cmd == F_SETLKW64)
579 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
582 code = afs_lockctl(vcp, &flock, cmd, credp);
585 if ((code == 0 || flp->fl_type == F_UNLCK) &&
586 (cmd == F_SETLK || cmd == F_SETLKW)) {
587 flp->fl_flags &=~ FL_SLEEP;
588 code = flock_lock_file_wait(fp, flp);
589 if (code && flp->fl_type != F_UNLCK) {
590 struct AFS_FLOCK flock2;
592 flock2.l_type = F_UNLCK;
594 afs_lockctl(vcp, &flock2, F_SETLK, credp);
598 /* Convert flock back to Linux's file_lock */
599 flp->fl_type = flock.l_type;
600 flp->fl_pid = flock.l_pid;
608 * essentially the same as afs_fsync() but we need to get the return
609 * code for the sys_close() here, not afs_linux_release(), so call
610 * afs_StoreAllSegments() with AFS_LASTSTORE
613 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
614 afs_linux_flush(struct file *fp, fl_owner_t id)
616 afs_linux_flush(struct file *fp)
619 struct vrequest treq;
623 #if defined(AFS_CACHE_BYPASS)
629 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
637 vcp = VTOAFS(FILE_INODE(fp));
639 code = afs_InitReq(&treq, credp);
642 #if defined(AFS_CACHE_BYPASS)
643 /* If caching is bypassed for this file, or globally, just return 0 */
644 if(cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
647 ObtainReadLock(&vcp->lock);
648 if(vcp->cachingStates & FCSBypass)
650 ReleaseReadLock(&vcp->lock);
653 /* future proof: don't rely on 0 return from afs_InitReq */
658 ObtainSharedLock(&vcp->lock, 535);
659 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
660 UpgradeSToWLock(&vcp->lock, 536);
661 if (!AFS_IS_DISCONNECTED) {
662 code = afs_StoreAllSegments(vcp,
664 AFS_SYNC | AFS_LASTSTORE);
666 #if defined(AFS_DISCON_ENV)
667 if (!vcp->ddirty_flags ||
668 (vcp->ddirty_flags == VDisconShadowed)) {
670 ObtainWriteLock(&afs_DDirtyVCListLock, 710);
671 AFS_DISCON_ADD_DIRTY(vcp);
672 ReleaseWriteLock(&afs_DDirtyVCListLock);
675 /* Set disconnected write flag. */
676 vcp->ddirty_flags |= VDisconWriteOsiFlush;
680 ConvertWToSLock(&vcp->lock);
682 code = afs_CheckCode(code, &treq, 54);
683 ReleaseSharedLock(&vcp->lock);
693 #if !defined(AFS_LINUX24_ENV)
694 /* Not allowed to directly read a directory. */
696 afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos)
704 struct file_operations afs_dir_fops = {
705 #if !defined(AFS_LINUX24_ENV)
706 .read = afs_linux_dir_read,
707 .lock = afs_linux_lock,
708 .fsync = afs_linux_fsync,
710 .read = generic_read_dir,
712 .readdir = afs_linux_readdir,
713 #ifdef HAVE_UNLOCKED_IOCTL
714 .unlocked_ioctl = afs_unlocked_xioctl,
718 #ifdef HAVE_COMPAT_IOCTL
719 .compat_ioctl = afs_unlocked_xioctl,
721 .open = afs_linux_open,
722 .release = afs_linux_release,
725 struct file_operations afs_file_fops = {
726 .read = afs_linux_read,
727 .write = afs_linux_write,
728 #ifdef GENERIC_FILE_AIO_READ
729 .aio_read = generic_file_aio_read,
730 .aio_write = generic_file_aio_write,
732 #ifdef HAVE_UNLOCKED_IOCTL
733 .unlocked_ioctl = afs_unlocked_xioctl,
737 #ifdef HAVE_COMPAT_IOCTL
738 .compat_ioctl = afs_unlocked_xioctl,
740 .mmap = afs_linux_mmap,
741 .open = afs_linux_open,
742 .flush = afs_linux_flush,
743 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
744 .sendfile = generic_file_sendfile,
746 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
747 .splice_write = generic_file_splice_write,
748 .splice_read = generic_file_splice_read,
750 .release = afs_linux_release,
751 .fsync = afs_linux_fsync,
752 .lock = afs_linux_lock,
753 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
754 .flock = afs_linux_flock,
759 /**********************************************************************
760 * AFS Linux dentry operations
761 **********************************************************************/
763 /* check_bad_parent() : Checks if this dentry's vcache is a root vcache
764 * that has its mvid (parent dir's fid) pointer set to the wrong directory
765 * due to being mounted in multiple points at once. If so, check_bad_parent()
766 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
767 * dotdotfid and mtpoint fid members.
769 * dp - dentry to be checked.
773 * This dentry's vcache's mvid will be set to the correct parent directory's
775 * This root vnode's volume will have its dotdotfid and mtpoint fids set
776 * to the correct parent and mountpoint fids.
780 check_bad_parent(struct dentry *dp)
783 struct vcache *vcp = VTOAFS(dp->d_inode), *avc = NULL;
784 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
786 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
789 /* force a lookup, so vcp->mvid is fixed up */
790 afs_lookup(pvc, dp->d_name.name, &avc, credp);
791 if (!avc || vcp != avc) { /* bad, very bad.. */
792 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
793 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
794 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
795 ICL_TYPE_POINTER, dp);
798 AFS_RELE(AFSTOV(avc));
805 /* afs_linux_revalidate
806 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
809 afs_linux_revalidate(struct dentry *dp)
812 struct vcache *vcp = VTOAFS(dp->d_inode);
816 #ifdef AFS_LINUX24_ENV
822 /* Make this a fast path (no crref), since it's called so often. */
823 if (vcp->states & CStatd) {
825 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
826 check_bad_parent(dp); /* check and correct mvid */
829 #ifdef AFS_LINUX24_ENV
837 code = afs_getattr(vcp, &vattr, credp);
839 afs_fill_inode(AFSTOV(vcp), &vattr);
842 #ifdef AFS_LINUX24_ENV
843 maybe_unlock_kernel();
850 #if defined(AFS_LINUX26_ENV)
852 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
854 int err = afs_linux_revalidate(dentry);
856 generic_fillattr(dentry->d_inode, stat);
862 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
863 * In kernels 2.2.10 and above, we are passed an additional flags var which
864 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
865 * we are advised to follow the entry if it is a link or to make sure that
866 * it is a directory. But since the kernel itself checks these possibilities
867 * later on, we shouldn't have to do it until later. Perhaps in the future..
870 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
871 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
872 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
874 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
877 afs_linux_dentry_revalidate(struct dentry *dp)
881 cred_t *credp = NULL;
882 struct vcache *vcp, *pvcp, *tvc = NULL;
884 struct afs_fakestat_state fakestate;
886 #ifdef AFS_LINUX24_ENV
890 afs_InitFakeStat(&fakestate);
894 vcp = VTOAFS(dp->d_inode);
895 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
897 if (vcp == afs_globalVp)
900 if (vcp->mvstat == 1) { /* mount point */
901 if (vcp->mvid && (vcp->states & CMValid)) {
904 struct vrequest treq;
907 code = afs_InitReq(&treq, credp);
909 #ifdef AFS_DARWIN_ENV
910 (strcmp(dp->d_name.name, ".DS_Store") == 0) ||
911 (strcmp(dp->d_name.name, "Contents") == 0) ||
913 (strcmp(dp->d_name.name, ".directory") == 0)) {
917 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
919 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
920 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
921 /* a mount point, not yet replaced by its directory */
926 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
927 check_bad_parent(dp); /* check and correct mvid */
930 /* If the last looker changes, we should make sure the current
931 * looker still has permission to examine this file. This would
932 * always require a crref() which would be "slow".
934 if (vcp->last_looker != treq.uid) {
935 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
938 vcp->last_looker = treq.uid;
942 /* If the parent's DataVersion has changed or the vnode
943 * is longer valid, we need to do a full lookup. VerifyVCache
944 * isn't enough since the vnode may have been renamed.
947 if (hgetlo(pvcp->m.DataVersion) > dp->d_time || !(vcp->states & CStatd)) {
950 afs_lookup(pvcp, dp->d_name.name, &tvc, credp);
951 if (!tvc || tvc != vcp)
954 if (afs_getattr(vcp, &vattr, credp))
957 vattr2inode(AFSTOV(vcp), &vattr);
958 dp->d_time = hgetlo(pvcp->m.DataVersion);
961 /* should we always update the attributes at this point? */
962 /* unlikely--the vcache entry hasn't changed */
966 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
967 if (hgetlo(pvcp->m.DataVersion) > dp->d_time)
971 /* No change in parent's DataVersion so this negative
972 * lookup is still valid. BUT, if a server is down a
973 * negative lookup can result so there should be a
974 * liftime as well. For now, always expire.
987 afs_PutFakeStat(&fakestate);
993 shrink_dcache_parent(dp);
996 #ifdef AFS_LINUX24_ENV
997 maybe_unlock_kernel();
1002 if (have_submounts(dp))
1010 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1012 struct vcache *vcp = VTOAFS(ip);
1015 (void) afs_InactiveVCache(vcp, NULL);
1017 #ifdef DCACHE_NFSFS_RENAMED
1018 #ifdef AFS_LINUX26_ENV
1019 spin_lock(&dp->d_lock);
1021 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
1022 #ifdef AFS_LINUX26_ENV
1023 spin_unlock(&dp->d_lock);
1031 afs_dentry_delete(struct dentry *dp)
1033 if (dp->d_inode && (VTOAFS(dp->d_inode)->states & CUnlinked))
1034 return 1; /* bad inode? */
1039 struct dentry_operations afs_dentry_operations = {
1040 .d_revalidate = afs_linux_dentry_revalidate,
1041 .d_delete = afs_dentry_delete,
1042 .d_iput = afs_dentry_iput,
1045 /**********************************************************************
1046 * AFS Linux inode operations
1047 **********************************************************************/
1051 * Merely need to set enough of vattr to get us through the create. Note
1052 * that the higher level code (open_namei) will take care of any tuncation
1053 * explicitly. Exclusive open is also taken care of in open_namei.
1055 * name is in kernel space at this point.
1058 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1059 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1060 struct nameidata *nd)
1062 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1066 cred_t *credp = crref();
1067 const char *name = dp->d_name.name;
1072 vattr.va_mode = mode;
1073 vattr.va_type = mode & S_IFMT;
1075 #if defined(AFS_LINUX26_ENV)
1076 maybe_lock_kernel();
1079 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1083 struct inode *ip = AFSTOV(vcp);
1085 afs_getattr(vcp, &vattr, credp);
1086 afs_fill_inode(ip, &vattr);
1087 insert_inode_hash(ip);
1088 dp->d_op = &afs_dentry_operations;
1089 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1090 d_instantiate(dp, ip);
1094 #if defined(AFS_LINUX26_ENV)
1095 maybe_unlock_kernel();
1101 /* afs_linux_lookup */
1102 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1103 static struct dentry *
1104 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1105 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1106 struct nameidata *nd)
1108 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1112 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1115 cred_t *credp = crref();
1116 struct vcache *vcp = NULL;
1117 const char *comp = dp->d_name.name;
1118 struct inode *ip = NULL;
1119 #if defined(AFS_LINUX26_ENV)
1120 struct dentry *newdp = NULL;
1124 #if defined(AFS_LINUX26_ENV)
1125 maybe_lock_kernel();
1128 code = afs_lookup(VTOAFS(dip), comp, &vcp, credp);
1134 afs_getattr(vcp, &vattr, credp);
1135 afs_fill_inode(ip, &vattr);
1137 #ifdef HAVE_KERNEL_HLIST_UNHASHED
1138 hlist_unhashed(&ip->i_hash)
1139 #elif defined(AFS_LINUX26_ENV)
1140 ip->i_hash.pprev == NULL
1142 ip->i_hash.prev == NULL
1145 insert_inode_hash(ip);
1147 dp->d_op = &afs_dentry_operations;
1148 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1151 #if defined(AFS_LINUX24_ENV)
1152 if (ip && S_ISDIR(ip->i_mode)) {
1153 struct dentry *alias;
1155 /* Try to invalidate an existing alias in favor of our new one */
1156 alias = d_find_alias(ip);
1157 #if defined(AFS_LINUX26_ENV)
1158 /* But not if it's disconnected; then we want d_splice_alias below */
1159 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1163 if (d_invalidate(alias) == 0) {
1167 #if defined(AFS_LINUX26_ENV)
1176 #if defined(AFS_LINUX26_ENV)
1177 newdp = d_splice_alias(ip, dp);
1182 #if defined(AFS_LINUX26_ENV)
1183 maybe_unlock_kernel();
1187 /* It's ok for the file to not be found. That's noted by the caller by
1188 * seeing that the dp->d_inode field is NULL.
1190 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1191 #if defined(AFS_LINUX26_ENV)
1192 if (!code || code == ENOENT)
1199 return ERR_PTR(-code);
1208 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1211 cred_t *credp = crref();
1212 const char *name = newdp->d_name.name;
1213 struct inode *oldip = olddp->d_inode;
1215 /* If afs_link returned the vnode, we could instantiate the
1216 * dentry. Since it's not, we drop this one and do a new lookup.
1221 code = afs_link(VTOAFS(oldip), VTOAFS(dip), name, credp);
1229 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1232 cred_t *credp = crref();
1233 const char *name = dp->d_name.name;
1234 struct vcache *tvc = VTOAFS(dp->d_inode);
1236 #if defined(AFS_LINUX26_ENV)
1237 maybe_lock_kernel();
1239 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1240 && !(tvc->states & CUnlinked)) {
1241 struct dentry *__dp;
1243 extern char *afs_newname();
1252 osi_FreeSmallSpace(__name);
1253 __name = afs_newname();
1256 __dp = lookup_one_len(__name, dp->d_parent, strlen(__name));
1260 } while (__dp->d_inode != NULL);
1263 code = afs_rename(VTOAFS(dip), dp->d_name.name, VTOAFS(dip), __dp->d_name.name, credp);
1265 tvc->mvid = (void *) __name;
1268 crfree(tvc->uncred);
1270 tvc->uncred = credp;
1271 tvc->states |= CUnlinked;
1272 #ifdef DCACHE_NFSFS_RENAMED
1273 #ifdef AFS_LINUX26_ENV
1274 spin_lock(&dp->d_lock);
1276 dp->d_flags |= DCACHE_NFSFS_RENAMED;
1277 #ifdef AFS_LINUX26_ENV
1278 spin_unlock(&dp->d_lock);
1282 osi_FreeSmallSpace(__name);
1287 __dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1296 code = afs_remove(VTOAFS(dip), name, credp);
1301 #if defined(AFS_LINUX26_ENV)
1302 maybe_unlock_kernel();
1310 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1313 cred_t *credp = crref();
1315 const char *name = dp->d_name.name;
1317 /* If afs_symlink returned the vnode, we could instantiate the
1318 * dentry. Since it's not, we drop this one and do a new lookup.
1324 code = afs_symlink(VTOAFS(dip), name, &vattr, target, credp);
1331 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1334 cred_t *credp = crref();
1335 struct vcache *tvcp = NULL;
1337 const char *name = dp->d_name.name;
1339 #if defined(AFS_LINUX26_ENV)
1340 maybe_lock_kernel();
1343 vattr.va_mask = ATTR_MODE;
1344 vattr.va_mode = mode;
1346 code = afs_mkdir(VTOAFS(dip), name, &vattr, &tvcp, credp);
1349 struct inode *ip = AFSTOV(tvcp);
1351 afs_getattr(tvcp, &vattr, credp);
1352 afs_fill_inode(ip, &vattr);
1354 dp->d_op = &afs_dentry_operations;
1355 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1356 d_instantiate(dp, ip);
1360 #if defined(AFS_LINUX26_ENV)
1361 maybe_unlock_kernel();
1368 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1371 cred_t *credp = crref();
1372 const char *name = dp->d_name.name;
1374 /* locking kernel conflicts with glock? */
1377 code = afs_rmdir(VTOAFS(dip), name, credp);
1380 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1381 * that failed because a directory is not empty. So, we map
1382 * EEXIST to ENOTEMPTY on linux.
1384 if (code == EEXIST) {
1398 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1399 struct inode *newip, struct dentry *newdp)
1402 cred_t *credp = crref();
1403 const char *oldname = olddp->d_name.name;
1404 const char *newname = newdp->d_name.name;
1405 struct dentry *rehash = NULL;
1407 #if defined(AFS_LINUX26_ENV)
1408 /* Prevent any new references during rename operation. */
1409 maybe_lock_kernel();
1411 if (!d_unhashed(newdp)) {
1416 if (!list_empty(&newdp->d_hash)) {
1422 #if defined(AFS_LINUX24_ENV)
1423 if (atomic_read(&olddp->d_count) > 1)
1424 shrink_dcache_parent(olddp);
1428 code = afs_rename(VTOAFS(oldip), oldname, VTOAFS(newip), newname, credp);
1432 olddp->d_time = 0; /* force to revalidate */
1437 #if defined(AFS_LINUX26_ENV)
1438 maybe_unlock_kernel();
1446 /* afs_linux_ireadlink
1447 * Internal readlink which can return link contents to user or kernel space.
1448 * Note that the buffer is NOT supposed to be null-terminated.
1451 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1454 cred_t *credp = crref();
1458 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1459 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1463 return maxlen - tuio.uio_resid;
1468 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1469 /* afs_linux_readlink
1470 * Fill target (which is in user space) with contents of symlink.
1473 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1476 struct inode *ip = dp->d_inode;
1479 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1485 /* afs_linux_follow_link
1486 * a file system dependent link following routine.
1488 #if defined(AFS_LINUX24_ENV)
1489 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1494 name = osi_Alloc(PATH_MAX);
1500 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1508 code = vfs_follow_link(nd, name);
1511 osi_Free(name, PATH_MAX);
1516 #else /* !defined(AFS_LINUX24_ENV) */
1518 static struct dentry *
1519 afs_linux_follow_link(struct dentry *dp, struct dentry *basep,
1520 unsigned int follow)
1528 name = osi_Alloc(PATH_MAX + 1);
1532 return ERR_PTR(-EIO);
1535 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1540 res = ERR_PTR(code);
1543 res = lookup_dentry(name, basep, follow);
1547 osi_Free(name, PATH_MAX + 1);
1551 #endif /* AFS_LINUX24_ENV */
1552 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1554 #if defined(AFS_CACHE_BYPASS)
1556 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1558 /* The kernel calls readpages before trying readpage, with a list of
1559 * pages. The readahead algorithm expands num_pages when it thinks
1560 * the application will benefit. Unlike readpage, the pages are not
1561 * necessarily allocated. If we do not a) allocate required pages and
1562 * b) remove them from page_list, linux will re-enter at afs_linux_readpage
1563 * for each required page (and the page will be pre-allocated) */
1566 afs_linux_readpages(struct file *fp, struct address_space *mapping,
1567 struct list_head *page_list, unsigned num_pages)
1572 struct iovec* iovecp;
1573 struct nocache_read_request *ancr;
1574 struct page *pp, *ppt;
1575 struct pagevec lrupv;
1579 struct inode *ip = FILE_INODE(fp);
1580 struct vcache *avc = VTOAFS(ip);
1581 afs_int32 bypasscache = 0; /* bypass for this read */
1582 afs_int32 base_index = 0;
1583 afs_int32 page_count = 0;
1588 switch(cache_bypass_strategy) {
1589 case NEVER_BYPASS_CACHE:
1591 case ALWAYS_BYPASS_CACHE:
1594 case LARGE_FILES_BYPASS_CACHE:
1595 if(i_size_read(ip) > cache_bypass_threshold) {
1603 /* In the new incarnation of selective caching, a file's caching policy
1604 * can change, eg because file size exceeds threshold, etc. */
1605 trydo_cache_transition(avc, credp, bypasscache);
1608 while(!list_empty(page_list)) {
1609 pp = list_entry(page_list->prev, struct page, lru);
1614 /* background thread must free: iovecp, auio, ancr */
1615 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
1617 auio = osi_Alloc(sizeof(uio_t));
1618 auio->uio_iov = iovecp;
1619 auio->uio_iovcnt = num_pages;
1620 auio->uio_flag = UIO_READ;
1621 auio->uio_seg = AFS_UIOSYS;
1622 auio->uio_resid = num_pages * PAGE_SIZE;
1624 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1626 ancr->offset = auio->uio_offset;
1627 ancr->length = auio->uio_resid;
1629 pagevec_init(&lrupv, 0);
1631 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
1633 if(list_empty(page_list))
1636 pp = list_entry(page_list->prev, struct page, lru);
1637 /* If we allocate a page and don't remove it from page_list,
1638 * the page cache gets upset. */
1640 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1641 if(pp->index > isize) {
1648 offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1649 auio->uio_offset = offset;
1650 base_index = pp->index;
1652 iovecp[page_ix].iov_len = PAGE_SIZE;
1653 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
1654 if(base_index != pp->index) {
1657 page_cache_release(pp);
1658 iovecp[page_ix].iov_base = (void *) 0;
1666 page_cache_release(pp);
1667 iovecp[page_ix].iov_base = (void *) 0;
1670 if(!PageLocked(pp)) {
1674 /* save the page for background map */
1675 iovecp[page_ix].iov_base = (void*) pp;
1677 /* and put it on the LRU cache */
1678 if (!pagevec_add(&lrupv, pp))
1679 __pagevec_lru_add(&lrupv);
1683 /* If there were useful pages in the page list, make sure all pages
1684 * are in the LRU cache, then schedule the read */
1686 pagevec_lru_add(&lrupv);
1687 code = afs_ReadNoCache(avc, ancr, credp);
1689 /* If there is nothing for the background thread to handle,
1690 * it won't be freeing the things that we never gave it */
1691 osi_Free(iovecp, num_pages * sizeof(struct iovec));
1692 osi_Free(auio, sizeof(uio_t));
1693 osi_Free(ancr, sizeof(struct nocache_read_request));
1695 /* we do not flush, release, or unmap pages--that will be
1696 * done for us by the background thread as each page comes in
1697 * from the fileserver */
1704 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
1705 #endif /* defined(AFS_CACHE_BYPASS */
1708 /* afs_linux_readpage
1709 * all reads come through here. A strategy-like read call.
1712 afs_linux_readpage(struct file *fp, struct page *pp)
1715 cred_t *credp = crref();
1716 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1718 afs_offs_t offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1720 ulong address = afs_linux_page_address(pp);
1721 afs_offs_t offset = pageoff(pp);
1723 #if defined(AFS_CACHE_BYPASS)
1724 afs_int32 bypasscache = 0; /* bypass for this read */
1725 struct nocache_read_request *ancr;
1729 struct iovec *iovecp;
1730 struct inode *ip = FILE_INODE(fp);
1731 afs_int32 cnt = page_count(pp);
1732 struct vcache *avc = VTOAFS(ip);
1734 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1738 atomic_add(1, &pp->count);
1739 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1740 clear_bit(PG_error, &pp->flags);
1742 #if defined(AFS_CACHE_BYPASS)
1743 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1744 /* If the page is past the end of the file, skip it */
1745 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1746 if(pp->index > isize) {
1753 /* if bypasscache, receiver frees, else we do */
1754 auio = osi_Alloc(sizeof(uio_t));
1755 iovecp = osi_Alloc(sizeof(struct iovec));
1757 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1760 #if defined(AFS_CACHE_BYPASS)
1762 switch(cache_bypass_strategy) {
1763 case NEVER_BYPASS_CACHE:
1765 case ALWAYS_BYPASS_CACHE:
1768 case LARGE_FILES_BYPASS_CACHE:
1769 if(i_size_read(ip) > cache_bypass_threshold) {
1777 /* In the new incarnation of selective caching, a file's caching policy
1778 * can change, eg because file size exceeds threshold, etc. */
1779 trydo_cache_transition(avc, credp, bypasscache);
1784 /* save the page for background map */
1785 auio->uio_iov->iov_base = (void*) pp;
1786 /* the background thread will free this */
1787 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1789 ancr->offset = offset;
1790 ancr->length = PAGE_SIZE;
1792 maybe_lock_kernel();
1793 code = afs_ReadNoCache(avc, ancr, credp);
1794 maybe_unlock_kernel();
1796 goto done; /* skips release page, doing it in bg thread */
1800 #ifdef AFS_LINUX24_ENV
1801 maybe_lock_kernel();
1804 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 */
1806 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1808 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1809 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1812 #ifdef AFS_LINUX24_ENV
1813 maybe_unlock_kernel();
1816 /* XXX valid for no-cache also? Check last bits of files... :)
1817 * Cognate code goes in afs_NoCacheFetchProc. */
1818 if (auio->uio_resid) /* zero remainder of page */
1819 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1822 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1823 flush_dcache_page(pp);
1824 SetPageUptodate(pp);
1826 set_bit(PG_uptodate, &pp->flags);
1830 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1834 clear_bit(PG_locked, &pp->flags);
1839 #if defined(AFS_CACHE_BYPASS)
1841 /* do not call afs_GetDCache if cache is bypassed */
1847 /* free if not bypassing cache */
1848 osi_Free(auio, sizeof(uio_t));
1849 osi_Free(iovecp, sizeof(struct iovec));
1851 if (!code && AFS_CHUNKOFFSET(offset) == 0) {
1853 struct vrequest treq;
1856 code = afs_InitReq(&treq, credp);
1857 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
1858 tdc = afs_FindDCache(avc, offset);
1860 if (!(tdc->mflags & DFNextStarted))
1861 afs_PrefetchChunk(avc, tdc, credp, &treq);
1864 ReleaseWriteLock(&avc->lock);
1875 #if defined(AFS_LINUX24_ENV)
1877 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1878 unsigned long offset, unsigned int count)
1880 struct vcache *vcp = VTOAFS(ip);
1889 buffer = kmap(pp) + offset;
1890 base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
1893 maybe_lock_kernel();
1895 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1896 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1897 ICL_TYPE_INT32, 99999);
1899 ObtainReadLock(&vcp->lock);
1900 if (vcp->states & CPageWrite) {
1901 ReleaseReadLock(&vcp->lock);
1903 maybe_unlock_kernel();
1906 #ifdef AFS_LINUX26_ENV
1907 #if defined(WRITEPAGE_ACTIVATE)
1908 return WRITEPAGE_ACTIVATE;
1910 return AOP_WRITEPAGE_ACTIVATE;
1913 /* should mark it dirty? */
1917 ReleaseReadLock(&vcp->lock);
1919 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1921 code = afs_write(vcp, &tuio, f_flags, credp, 0);
1923 ip->i_size = vcp->m.Length;
1924 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
1927 struct vrequest treq;
1929 ObtainWriteLock(&vcp->lock, 533);
1930 if (!afs_InitReq(&treq, credp))
1931 code = afs_DoPartialWrite(vcp, &treq);
1932 ReleaseWriteLock(&vcp->lock);
1934 code = code ? -code : count - tuio.uio_resid;
1936 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1937 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1938 ICL_TYPE_INT32, code);
1941 maybe_unlock_kernel();
1950 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
1951 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
1953 afs_linux_writepage(struct page *pp)
1956 struct address_space *mapping = pp->mapping;
1957 struct inode *inode;
1958 unsigned long end_index;
1959 unsigned offset = PAGE_CACHE_SIZE;
1962 #if defined(AFS_LINUX26_ENV)
1963 if (PageReclaim(pp)) {
1964 # if defined(WRITEPAGE_ACTIVATE)
1965 return WRITEPAGE_ACTIVATE;
1967 return AOP_WRITEPAGE_ACTIVATE;
1971 if (PageLaunder(pp)) {
1972 return(fail_writepage(pp));
1976 inode = (struct inode *)mapping->host;
1977 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1980 if (pp->index < end_index)
1982 /* things got complicated... */
1983 offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
1984 /* OK, are we completely out? */
1985 if (pp->index >= end_index + 1 || !offset)
1988 status = afs_linux_writepage_sync(inode, pp, 0, offset);
1989 SetPageUptodate(pp);
1991 if (status == offset)
1997 /* afs_linux_updatepage
1998 * What one would have thought was writepage - write dirty page to file.
1999 * Called from generic_file_write. buffer is still in user space. pagep
2000 * has been filled in with old data if we're updating less than a page.
2003 afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset,
2004 unsigned int count, int sync)
2006 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
2007 u8 *page_addr = (u8 *) afs_linux_page_address(pp);
2013 set_bit(PG_locked, &pp->flags);
2017 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2018 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2019 ICL_TYPE_INT32, 99999);
2020 setup_uio(&tuio, &iovec, page_addr + offset,
2021 (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE,
2024 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
2026 ip->i_size = vcp->m.Length;
2027 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
2030 struct vrequest treq;
2032 ObtainWriteLock(&vcp->lock, 533);
2033 vcp->m.Date = osi_Time(); /* set modification time */
2034 if (!afs_InitReq(&treq, credp))
2035 code = afs_DoPartialWrite(vcp, &treq);
2036 ReleaseWriteLock(&vcp->lock);
2039 code = code ? -code : count - tuio.uio_resid;
2040 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2041 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2042 ICL_TYPE_INT32, code);
2047 clear_bit(PG_locked, &pp->flags);
2052 /* afs_linux_permission
2053 * Check access rights - returns error if can't check or permission denied.
2056 #ifdef IOP_PERMISSION_TAKES_NAMEIDATA
2057 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2059 afs_linux_permission(struct inode *ip, int mode)
2063 cred_t *credp = crref();
2067 if (mode & MAY_EXEC)
2069 if (mode & MAY_READ)
2071 if (mode & MAY_WRITE)
2073 code = afs_access(VTOAFS(ip), tmp, credp);
2080 #if defined(AFS_LINUX24_ENV) && !defined(HAVE_WRITE_BEGIN)
2082 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2087 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
2088 offset, to - offset);
2089 #if !defined(AFS_LINUX26_ENV)
2097 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2100 /* sometime between 2.4.0 and 2.4.19, the callers of prepare_write began to
2101 call kmap directly instead of relying on us to do it */
2102 #if !defined(AFS_LINUX26_ENV)
2109 #if defined(HAVE_WRITE_BEGIN)
2111 afs_linux_write_end(struct file *file, struct address_space *mapping,
2112 loff_t pos, unsigned len, unsigned copied,
2113 struct page *page, void *fsdata)
2116 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2117 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
2119 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
2122 page_cache_release(page);
2127 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2128 loff_t pos, unsigned len, unsigned flags,
2129 struct page **pagep, void **fsdata)
2132 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2133 page = __grab_cache_page(mapping, index);
2141 static struct inode_operations afs_file_iops = {
2142 #if defined(AFS_LINUX26_ENV)
2143 .permission = afs_linux_permission,
2144 .getattr = afs_linux_getattr,
2145 .setattr = afs_notify_change,
2146 #elif defined(AFS_LINUX24_ENV)
2147 .permission = afs_linux_permission,
2148 .revalidate = afs_linux_revalidate,
2149 .setattr = afs_notify_change,
2151 .default_file_ops = &afs_file_fops,
2152 .readpage = afs_linux_readpage,
2153 .revalidate = afs_linux_revalidate,
2154 .updatepage = afs_linux_updatepage,
2158 #if defined(AFS_LINUX24_ENV)
2159 static struct address_space_operations afs_file_aops = {
2160 .readpage = afs_linux_readpage,
2161 #if defined(AFS_CACHE_BYPASS) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2162 .readpages = afs_linux_readpages,
2164 .writepage = afs_linux_writepage,
2165 #if defined (HAVE_WRITE_BEGIN)
2166 .write_begin = afs_linux_write_begin,
2167 .write_end = afs_linux_write_end,
2169 .commit_write = afs_linux_commit_write,
2170 .prepare_write = afs_linux_prepare_write,
2176 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2177 * by what sort of operation is allowed.....
2180 static struct inode_operations afs_dir_iops = {
2181 #if !defined(AFS_LINUX24_ENV)
2182 .default_file_ops = &afs_dir_fops,
2184 .setattr = afs_notify_change,
2186 .create = afs_linux_create,
2187 .lookup = afs_linux_lookup,
2188 .link = afs_linux_link,
2189 .unlink = afs_linux_unlink,
2190 .symlink = afs_linux_symlink,
2191 .mkdir = afs_linux_mkdir,
2192 .rmdir = afs_linux_rmdir,
2193 .rename = afs_linux_rename,
2194 #if defined(AFS_LINUX26_ENV)
2195 .getattr = afs_linux_getattr,
2197 .revalidate = afs_linux_revalidate,
2199 .permission = afs_linux_permission,
2202 /* We really need a separate symlink set of ops, since do_follow_link()
2203 * determines if it _is_ a link by checking if the follow_link op is set.
2205 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2207 afs_symlink_filler(struct file *file, struct page *page)
2209 struct inode *ip = (struct inode *)page->mapping->host;
2210 char *p = (char *)kmap(page);
2213 maybe_lock_kernel();
2215 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2220 p[code] = '\0'; /* null terminate? */
2221 maybe_unlock_kernel();
2223 SetPageUptodate(page);
2229 maybe_unlock_kernel();
2237 static struct address_space_operations afs_symlink_aops = {
2238 .readpage = afs_symlink_filler
2240 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2242 static struct inode_operations afs_symlink_iops = {
2243 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2244 .readlink = page_readlink,
2245 #if defined(HAVE_KERNEL_PAGE_FOLLOW_LINK)
2246 .follow_link = page_follow_link,
2248 .follow_link = page_follow_link_light,
2249 .put_link = page_put_link,
2251 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2252 .readlink = afs_linux_readlink,
2253 .follow_link = afs_linux_follow_link,
2254 #if !defined(AFS_LINUX24_ENV)
2255 .permission = afs_linux_permission,
2256 .revalidate = afs_linux_revalidate,
2258 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2259 #if defined(AFS_LINUX24_ENV)
2260 .setattr = afs_notify_change,
2265 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2269 vattr2inode(ip, vattr);
2271 ip->i_mapping->backing_dev_info = &afs_backing_dev_info;
2272 /* Reset ops if symlink or directory. */
2273 if (S_ISREG(ip->i_mode)) {
2274 ip->i_op = &afs_file_iops;
2275 #if defined(AFS_LINUX24_ENV)
2276 ip->i_fop = &afs_file_fops;
2277 ip->i_data.a_ops = &afs_file_aops;
2280 } else if (S_ISDIR(ip->i_mode)) {
2281 ip->i_op = &afs_dir_iops;
2282 #if defined(AFS_LINUX24_ENV)
2283 ip->i_fop = &afs_dir_fops;
2286 } else if (S_ISLNK(ip->i_mode)) {
2287 ip->i_op = &afs_symlink_iops;
2288 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2289 ip->i_data.a_ops = &afs_symlink_aops;
2290 ip->i_mapping = &ip->i_data;