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 #if defined(AFS_LINUX26_ENV)
61 /* Some uses of BKL are perhaps not needed for bypass or memcache--
62 * why don't we try it out? */
63 extern struct afs_cacheOps afs_UfsCacheOps;
64 #define maybe_lock_kernel() \
66 if(afs_cacheType == &afs_UfsCacheOps) \
71 #define maybe_unlock_kernel() \
73 if(afs_cacheType == &afs_UfsCacheOps) \
76 #endif /* AFS_CACHE_BYPASS */
79 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
82 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
83 cred_t *credp = crref();
85 afs_size_t isize, offindex;
87 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
88 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
90 /* get a validated vcache entry */
91 code = afs_InitReq(&treq, credp);
93 code = afs_VerifyVCache(vcp, &treq);
98 #if defined(AFS_CACHE_BYPASS)
99 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
100 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
101 offindex = *offp >> PAGE_CACHE_SHIFT;
102 if(offindex > isize) {
108 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
111 code = do_sync_read(fp, buf, count, offp);
113 code = generic_file_read(fp, buf, count, offp);
118 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
119 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
128 /* Now we have integrated VM for writes as well as reads. generic_file_write
129 * also takes care of re-positioning the pointer if file is open in append
130 * mode. Call fake open/close to ensure we do writes of core dumps.
133 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
136 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
137 struct vrequest treq;
138 cred_t *credp = crref();
142 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
143 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
144 (fp->f_flags & O_APPEND) ? 99998 : 99999);
147 /* get a validated vcache entry */
148 code = (ssize_t) afs_InitReq(&treq, credp);
150 code = (ssize_t) afs_VerifyVCache(vcp, &treq);
152 ObtainWriteLock(&vcp->lock, 529);
154 ReleaseWriteLock(&vcp->lock);
160 code = do_sync_write(fp, buf, count, offp);
162 code = generic_file_write(fp, buf, count, offp);
167 ObtainWriteLock(&vcp->lock, 530);
168 afs_FakeClose(vcp, credp);
169 ReleaseWriteLock(&vcp->lock);
171 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
172 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
180 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
182 /* This is a complete rewrite of afs_readdir, since we can make use of
183 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
184 * handling and use of bulkstats will need to be reflected here as well.
187 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
189 extern struct DirEntry *afs_dir_GetBlob();
190 struct vcache *avc = VTOAFS(FILE_INODE(fp));
191 struct vrequest treq;
192 register struct dcache *tdc;
199 afs_size_t origOffset, tlen;
200 cred_t *credp = crref();
201 struct afs_fakestat_state fakestat;
203 #if defined(AFS_LINUX26_ENV)
207 AFS_STATCNT(afs_readdir);
209 code = afs_InitReq(&treq, credp);
214 afs_InitFakeStat(&fakestat);
215 code = afs_EvalFakeStat(&avc, &fakestat, &treq);
219 /* update the cache entry */
221 code = afs_VerifyVCache(avc, &treq);
225 /* get a reference to the entire directory */
226 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
232 ObtainSharedLock(&avc->lock, 810);
233 UpgradeSToWLock(&avc->lock, 811);
234 ObtainReadLock(&tdc->lock);
236 * Make sure that the data in the cache is current. There are two
237 * cases we need to worry about:
238 * 1. The cache data is being fetched by another process.
239 * 2. The cache data is no longer valid
241 while ((avc->states & CStatd)
242 && (tdc->dflags & DFFetching)
243 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
244 ReleaseReadLock(&tdc->lock);
245 ReleaseSharedLock(&avc->lock);
246 afs_osi_Sleep(&tdc->validPos);
247 ObtainSharedLock(&avc->lock, 812);
248 ObtainReadLock(&tdc->lock);
250 if (!(avc->states & CStatd)
251 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
252 ReleaseReadLock(&tdc->lock);
253 ReleaseSharedLock(&avc->lock);
258 /* Set the readdir-in-progress flag, and downgrade the lock
259 * to shared so others will be able to acquire a read lock.
261 avc->states |= CReadDir;
262 avc->dcreaddir = tdc;
263 avc->readdir_pid = MyPidxx;
264 ConvertWToSLock(&avc->lock);
266 /* Fill in until we get an error or we're done. This implementation
267 * takes an offset in units of blobs, rather than bytes.
270 offset = (int) fp->f_pos;
272 dirpos = BlobScan(tdc, offset);
276 de = afs_dir_GetBlob(tdc, dirpos);
280 ino = afs_calc_inum (avc->fid.Fid.Volume, ntohl(de->fid.vnode));
283 len = strlen(de->name);
285 printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %lx, dirpos %d)\n",
286 (unsigned long)&tdc->f.inode, dirpos);
287 DRelease((struct buffer *) de, 0);
288 ReleaseSharedLock(&avc->lock);
294 /* filldir returns -EINVAL when the buffer is full. */
295 #if defined(AFS_LINUX26_ENV) || ((defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE))
297 unsigned int type = DT_UNKNOWN;
298 struct VenusFid afid;
301 afid.Cell = avc->fid.Cell;
302 afid.Fid.Volume = avc->fid.Fid.Volume;
303 afid.Fid.Vnode = ntohl(de->fid.vnode);
304 afid.Fid.Unique = ntohl(de->fid.vunique);
305 if ((avc->states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
307 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
310 } else if (((tvc->states) & (CStatd | CTruth))) {
311 /* CTruth will be set if the object has
316 else if (vtype == VREG)
318 /* Don't do this until we're sure it can't be a mtpt */
319 /* else if (vtype == VLNK)
321 /* what other types does AFS support? */
323 /* clean up from afs_FindVCache */
327 * If this is NFS readdirplus, then the filler is going to
328 * call getattr on this inode, which will deadlock if we're
332 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
336 code = (*filldir) (dirbuf, de->name, len, offset, ino);
338 DRelease((struct buffer *)de, 0);
341 offset = dirpos + 1 + ((len + 16) >> 5);
343 /* If filldir didn't fill in the last one this is still pointing to that
346 fp->f_pos = (loff_t) offset;
348 ReleaseReadLock(&tdc->lock);
350 UpgradeSToWLock(&avc->lock, 813);
351 avc->states &= ~CReadDir;
353 avc->readdir_pid = 0;
354 ReleaseSharedLock(&avc->lock);
358 afs_PutFakeStat(&fakestat);
361 #if defined(AFS_LINUX26_ENV)
362 maybe_unlock_kernel();
368 /* in afs_pioctl.c */
369 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
372 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
373 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
375 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
382 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
384 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
385 cred_t *credp = crref();
386 struct vrequest treq;
390 #if defined(AFS_LINUX24_ENV)
391 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
392 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
393 vmap->vm_end - vmap->vm_start);
395 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
396 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
397 vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32,
401 /* get a validated vcache entry */
402 code = afs_InitReq(&treq, credp);
406 code = afs_VerifyVCache(vcp, &treq);
410 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
413 code = generic_file_mmap(fp, vmap);
416 vcp->states |= CMAPPED;
429 afs_linux_open(struct inode *ip, struct file *fp)
431 struct vcache *vcp = VTOAFS(ip);
432 cred_t *credp = crref();
435 #ifdef AFS_LINUX24_ENV
439 code = afs_open(&vcp, fp->f_flags, credp);
441 #ifdef AFS_LINUX24_ENV
442 maybe_unlock_kernel();
450 afs_linux_release(struct inode *ip, struct file *fp)
452 struct vcache *vcp = VTOAFS(ip);
453 cred_t *credp = crref();
456 #ifdef AFS_LINUX24_ENV
460 code = afs_close(vcp, fp->f_flags, credp);
462 #ifdef AFS_LINUX24_ENV
463 maybe_unlock_kernel();
471 #if defined(AFS_LINUX24_ENV)
472 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
474 afs_linux_fsync(struct file *fp, struct dentry *dp)
478 struct inode *ip = FILE_INODE(fp);
479 cred_t *credp = crref();
481 #ifdef AFS_LINUX24_ENV
485 code = afs_fsync(VTOAFS(ip), credp);
487 #ifdef AFS_LINUX24_ENV
488 maybe_unlock_kernel();
497 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
500 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
501 cred_t *credp = crref();
502 struct AFS_FLOCK flock;
503 /* Convert to a lock format afs_lockctl understands. */
504 memset((char *)&flock, 0, sizeof(flock));
505 flock.l_type = flp->fl_type;
506 flock.l_pid = flp->fl_pid;
508 flock.l_start = flp->fl_start;
509 flock.l_len = flp->fl_end - flp->fl_start;
511 /* Safe because there are no large files, yet */
512 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
513 if (cmd == F_GETLK64)
515 else if (cmd == F_SETLK64)
517 else if (cmd == F_SETLKW64)
519 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
522 code = afs_lockctl(vcp, &flock, cmd, credp);
525 #ifdef AFS_LINUX24_ENV
526 if ((code == 0 || flp->fl_type == F_UNLCK) &&
527 (cmd == F_SETLK || cmd == F_SETLKW)) {
528 #ifdef POSIX_LOCK_FILE_WAIT_ARG
529 code = posix_lock_file(fp, flp, 0);
531 flp->fl_flags &=~ FL_SLEEP;
532 code = posix_lock_file(fp, flp);
534 if (code && flp->fl_type != F_UNLCK) {
535 struct AFS_FLOCK flock2;
537 flock2.l_type = F_UNLCK;
539 afs_lockctl(vcp, &flock2, F_SETLK, credp);
544 /* Convert flock back to Linux's file_lock */
545 flp->fl_type = flock.l_type;
546 flp->fl_pid = flock.l_pid;
547 flp->fl_start = flock.l_start;
548 flp->fl_end = flock.l_start + flock.l_len;
555 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
557 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
559 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
560 cred_t *credp = crref();
561 struct AFS_FLOCK flock;
562 /* Convert to a lock format afs_lockctl understands. */
563 memset((char *)&flock, 0, sizeof(flock));
564 flock.l_type = flp->fl_type;
565 flock.l_pid = flp->fl_pid;
568 flock.l_len = OFFSET_MAX;
570 /* Safe because there are no large files, yet */
571 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
572 if (cmd == F_GETLK64)
574 else if (cmd == F_SETLK64)
576 else if (cmd == F_SETLKW64)
578 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
581 code = afs_lockctl(vcp, &flock, cmd, credp);
584 if ((code == 0 || flp->fl_type == F_UNLCK) &&
585 (cmd == F_SETLK || cmd == F_SETLKW)) {
586 flp->fl_flags &=~ FL_SLEEP;
587 code = flock_lock_file_wait(fp, flp);
588 if (code && flp->fl_type != F_UNLCK) {
589 struct AFS_FLOCK flock2;
591 flock2.l_type = F_UNLCK;
593 afs_lockctl(vcp, &flock2, F_SETLK, credp);
597 /* Convert flock back to Linux's file_lock */
598 flp->fl_type = flock.l_type;
599 flp->fl_pid = flock.l_pid;
607 * essentially the same as afs_fsync() but we need to get the return
608 * code for the sys_close() here, not afs_linux_release(), so call
609 * afs_StoreAllSegments() with AFS_LASTSTORE
612 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
613 afs_linux_flush(struct file *fp, fl_owner_t id)
615 afs_linux_flush(struct file *fp)
618 struct vrequest treq;
622 #if defined(AFS_CACHE_BYPASS)
628 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
636 vcp = VTOAFS(FILE_INODE(fp));
638 code = afs_InitReq(&treq, credp);
641 #if defined(AFS_CACHE_BYPASS)
642 /* If caching is bypassed for this file, or globally, just return 0 */
643 if(cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
646 ObtainReadLock(&vcp->lock);
647 if(vcp->cachingStates & FCSBypass)
649 ReleaseReadLock(&vcp->lock);
652 /* future proof: don't rely on 0 return from afs_InitReq */
657 ObtainSharedLock(&vcp->lock, 535);
658 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
659 UpgradeSToWLock(&vcp->lock, 536);
660 if (!AFS_IS_DISCONNECTED) {
661 code = afs_StoreAllSegments(vcp,
663 AFS_SYNC | AFS_LASTSTORE);
665 #if defined(AFS_DISCON_ENV)
666 if (!vcp->ddirty_flags ||
667 (vcp->ddirty_flags == VDisconShadowed)) {
669 ObtainWriteLock(&afs_DDirtyVCListLock, 710);
670 AFS_DISCON_ADD_DIRTY(vcp);
671 ReleaseWriteLock(&afs_DDirtyVCListLock);
674 /* Set disconnected write flag. */
675 vcp->ddirty_flags |= VDisconWriteOsiFlush;
679 ConvertWToSLock(&vcp->lock);
681 code = afs_CheckCode(code, &treq, 54);
682 ReleaseSharedLock(&vcp->lock);
692 #if !defined(AFS_LINUX24_ENV)
693 /* Not allowed to directly read a directory. */
695 afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos)
703 struct file_operations afs_dir_fops = {
704 #if !defined(AFS_LINUX24_ENV)
705 .read = afs_linux_dir_read,
706 .lock = afs_linux_lock,
707 .fsync = afs_linux_fsync,
709 .read = generic_read_dir,
711 .readdir = afs_linux_readdir,
712 #ifdef HAVE_UNLOCKED_IOCTL
713 .unlocked_ioctl = afs_unlocked_xioctl,
717 #ifdef HAVE_COMPAT_IOCTL
718 .compat_ioctl = afs_unlocked_xioctl,
720 .open = afs_linux_open,
721 .release = afs_linux_release,
724 struct file_operations afs_file_fops = {
725 .read = afs_linux_read,
726 .write = afs_linux_write,
727 #ifdef GENERIC_FILE_AIO_READ
728 .aio_read = generic_file_aio_read,
729 .aio_write = generic_file_aio_write,
731 #ifdef HAVE_UNLOCKED_IOCTL
732 .unlocked_ioctl = afs_unlocked_xioctl,
736 #ifdef HAVE_COMPAT_IOCTL
737 .compat_ioctl = afs_unlocked_xioctl,
739 .mmap = afs_linux_mmap,
740 .open = afs_linux_open,
741 .flush = afs_linux_flush,
742 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
743 .sendfile = generic_file_sendfile,
745 #if defined(AFS_LINUX26_ENV) && defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
746 .splice_write = generic_file_splice_write,
747 .splice_read = generic_file_splice_read,
749 .release = afs_linux_release,
750 .fsync = afs_linux_fsync,
751 .lock = afs_linux_lock,
752 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
753 .flock = afs_linux_flock,
758 /**********************************************************************
759 * AFS Linux dentry operations
760 **********************************************************************/
762 /* check_bad_parent() : Checks if this dentry's vcache is a root vcache
763 * that has its mvid (parent dir's fid) pointer set to the wrong directory
764 * due to being mounted in multiple points at once. If so, check_bad_parent()
765 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
766 * dotdotfid and mtpoint fid members.
768 * dp - dentry to be checked.
772 * This dentry's vcache's mvid will be set to the correct parent directory's
774 * This root vnode's volume will have its dotdotfid and mtpoint fids set
775 * to the correct parent and mountpoint fids.
779 check_bad_parent(struct dentry *dp)
782 struct vcache *vcp = VTOAFS(dp->d_inode), *avc = NULL;
783 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
785 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
788 /* force a lookup, so vcp->mvid is fixed up */
789 afs_lookup(pvc, dp->d_name.name, &avc, credp);
790 if (!avc || vcp != avc) { /* bad, very bad.. */
791 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
792 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
793 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
794 ICL_TYPE_POINTER, dp);
797 AFS_RELE(AFSTOV(avc));
804 /* afs_linux_revalidate
805 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
808 afs_linux_revalidate(struct dentry *dp)
811 struct vcache *vcp = VTOAFS(dp->d_inode);
815 #ifdef AFS_LINUX24_ENV
821 /* Make this a fast path (no crref), since it's called so often. */
822 if (vcp->states & CStatd) {
824 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
825 check_bad_parent(dp); /* check and correct mvid */
828 #ifdef AFS_LINUX24_ENV
836 code = afs_getattr(vcp, &vattr, credp);
838 afs_fill_inode(AFSTOV(vcp), &vattr);
841 #ifdef AFS_LINUX24_ENV
842 maybe_unlock_kernel();
849 #if defined(AFS_LINUX26_ENV)
851 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
853 int err = afs_linux_revalidate(dentry);
855 generic_fillattr(dentry->d_inode, stat);
861 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
862 * In kernels 2.2.10 and above, we are passed an additional flags var which
863 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
864 * we are advised to follow the entry if it is a link or to make sure that
865 * it is a directory. But since the kernel itself checks these possibilities
866 * later on, we shouldn't have to do it until later. Perhaps in the future..
869 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
870 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
871 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
873 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
876 afs_linux_dentry_revalidate(struct dentry *dp)
880 cred_t *credp = NULL;
881 struct vcache *vcp, *pvcp, *tvc = NULL;
883 struct afs_fakestat_state fakestate;
885 #ifdef AFS_LINUX24_ENV
889 afs_InitFakeStat(&fakestate);
893 vcp = VTOAFS(dp->d_inode);
894 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
896 if (vcp == afs_globalVp)
899 if (vcp->mvstat == 1) { /* mount point */
900 if (vcp->mvid && (vcp->states & CMValid)) {
903 struct vrequest treq;
906 code = afs_InitReq(&treq, credp);
908 #ifdef AFS_DARWIN_ENV
909 (strcmp(dp->d_name.name, ".DS_Store") == 0) ||
910 (strcmp(dp->d_name.name, "Contents") == 0) ||
912 (strcmp(dp->d_name.name, ".directory") == 0)) {
916 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
918 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
919 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
920 /* a mount point, not yet replaced by its directory */
925 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
926 check_bad_parent(dp); /* check and correct mvid */
929 /* If the last looker changes, we should make sure the current
930 * looker still has permission to examine this file. This would
931 * always require a crref() which would be "slow".
933 if (vcp->last_looker != treq.uid) {
934 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
937 vcp->last_looker = treq.uid;
941 /* If the parent's DataVersion has changed or the vnode
942 * is longer valid, we need to do a full lookup. VerifyVCache
943 * isn't enough since the vnode may have been renamed.
946 if (hgetlo(pvcp->m.DataVersion) > dp->d_time || !(vcp->states & CStatd)) {
949 afs_lookup(pvcp, dp->d_name.name, &tvc, credp);
950 if (!tvc || tvc != vcp)
953 if (afs_getattr(vcp, &vattr, credp))
956 vattr2inode(AFSTOV(vcp), &vattr);
957 dp->d_time = hgetlo(pvcp->m.DataVersion);
960 /* should we always update the attributes at this point? */
961 /* unlikely--the vcache entry hasn't changed */
965 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
966 if (hgetlo(pvcp->m.DataVersion) > dp->d_time)
970 /* No change in parent's DataVersion so this negative
971 * lookup is still valid. BUT, if a server is down a
972 * negative lookup can result so there should be a
973 * liftime as well. For now, always expire.
986 afs_PutFakeStat(&fakestate);
992 shrink_dcache_parent(dp);
995 #ifdef AFS_LINUX24_ENV
996 maybe_unlock_kernel();
1001 if (have_submounts(dp))
1009 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1011 struct vcache *vcp = VTOAFS(ip);
1014 (void) afs_InactiveVCache(vcp, NULL);
1016 #ifdef DCACHE_NFSFS_RENAMED
1017 #ifdef AFS_LINUX26_ENV
1018 spin_lock(&dp->d_lock);
1020 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
1021 #ifdef AFS_LINUX26_ENV
1022 spin_unlock(&dp->d_lock);
1030 afs_dentry_delete(struct dentry *dp)
1032 if (dp->d_inode && (VTOAFS(dp->d_inode)->states & CUnlinked))
1033 return 1; /* bad inode? */
1038 struct dentry_operations afs_dentry_operations = {
1039 .d_revalidate = afs_linux_dentry_revalidate,
1040 .d_delete = afs_dentry_delete,
1041 .d_iput = afs_dentry_iput,
1044 /**********************************************************************
1045 * AFS Linux inode operations
1046 **********************************************************************/
1050 * Merely need to set enough of vattr to get us through the create. Note
1051 * that the higher level code (open_namei) will take care of any tuncation
1052 * explicitly. Exclusive open is also taken care of in open_namei.
1054 * name is in kernel space at this point.
1057 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1058 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1059 struct nameidata *nd)
1061 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1065 cred_t *credp = crref();
1066 const char *name = dp->d_name.name;
1071 vattr.va_mode = mode;
1072 vattr.va_type = mode & S_IFMT;
1074 #if defined(AFS_LINUX26_ENV)
1075 maybe_lock_kernel();
1078 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1082 struct inode *ip = AFSTOV(vcp);
1084 afs_getattr(vcp, &vattr, credp);
1085 afs_fill_inode(ip, &vattr);
1086 insert_inode_hash(ip);
1087 dp->d_op = &afs_dentry_operations;
1088 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1089 d_instantiate(dp, ip);
1093 #if defined(AFS_LINUX26_ENV)
1094 maybe_unlock_kernel();
1100 /* afs_linux_lookup */
1101 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1102 static struct dentry *
1103 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1104 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1105 struct nameidata *nd)
1107 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1111 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1114 cred_t *credp = crref();
1115 struct vcache *vcp = NULL;
1116 const char *comp = dp->d_name.name;
1117 struct inode *ip = NULL;
1118 #if defined(AFS_LINUX26_ENV)
1119 struct dentry *newdp = NULL;
1123 #if defined(AFS_LINUX26_ENV)
1124 maybe_lock_kernel();
1127 code = afs_lookup(VTOAFS(dip), comp, &vcp, credp);
1133 afs_getattr(vcp, &vattr, credp);
1134 afs_fill_inode(ip, &vattr);
1136 #ifdef HAVE_KERNEL_HLIST_UNHASHED
1137 hlist_unhashed(&ip->i_hash)
1138 #elif defined(AFS_LINUX26_ENV)
1139 ip->i_hash.pprev == NULL
1141 ip->i_hash.prev == NULL
1144 insert_inode_hash(ip);
1146 dp->d_op = &afs_dentry_operations;
1147 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1150 #if defined(AFS_LINUX24_ENV)
1151 if (ip && S_ISDIR(ip->i_mode)) {
1152 struct dentry *alias;
1154 /* Try to invalidate an existing alias in favor of our new one */
1155 alias = d_find_alias(ip);
1156 #if defined(AFS_LINUX26_ENV)
1157 /* But not if it's disconnected; then we want d_splice_alias below */
1158 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1162 if (d_invalidate(alias) == 0) {
1166 #if defined(AFS_LINUX26_ENV)
1175 #if defined(AFS_LINUX26_ENV)
1176 newdp = d_splice_alias(ip, dp);
1181 #if defined(AFS_LINUX26_ENV)
1182 maybe_unlock_kernel();
1186 /* It's ok for the file to not be found. That's noted by the caller by
1187 * seeing that the dp->d_inode field is NULL.
1189 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1190 #if defined(AFS_LINUX26_ENV)
1191 if (!code || code == ENOENT)
1198 return ERR_PTR(-code);
1207 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1210 cred_t *credp = crref();
1211 const char *name = newdp->d_name.name;
1212 struct inode *oldip = olddp->d_inode;
1214 /* If afs_link returned the vnode, we could instantiate the
1215 * dentry. Since it's not, we drop this one and do a new lookup.
1220 code = afs_link(VTOAFS(oldip), VTOAFS(dip), name, credp);
1228 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1231 cred_t *credp = crref();
1232 const char *name = dp->d_name.name;
1233 struct vcache *tvc = VTOAFS(dp->d_inode);
1235 #if defined(AFS_LINUX26_ENV)
1236 maybe_lock_kernel();
1238 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1239 && !(tvc->states & CUnlinked)) {
1240 struct dentry *__dp;
1242 extern char *afs_newname();
1251 osi_FreeSmallSpace(__name);
1252 __name = afs_newname();
1255 __dp = lookup_one_len(__name, dp->d_parent, strlen(__name));
1259 } while (__dp->d_inode != NULL);
1262 code = afs_rename(VTOAFS(dip), dp->d_name.name, VTOAFS(dip), __dp->d_name.name, credp);
1264 tvc->mvid = (void *) __name;
1267 crfree(tvc->uncred);
1269 tvc->uncred = credp;
1270 tvc->states |= CUnlinked;
1271 #ifdef DCACHE_NFSFS_RENAMED
1272 #ifdef AFS_LINUX26_ENV
1273 spin_lock(&dp->d_lock);
1275 dp->d_flags |= DCACHE_NFSFS_RENAMED;
1276 #ifdef AFS_LINUX26_ENV
1277 spin_unlock(&dp->d_lock);
1281 osi_FreeSmallSpace(__name);
1286 __dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1295 code = afs_remove(VTOAFS(dip), name, credp);
1300 #if defined(AFS_LINUX26_ENV)
1301 maybe_unlock_kernel();
1309 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1312 cred_t *credp = crref();
1314 const char *name = dp->d_name.name;
1316 /* If afs_symlink returned the vnode, we could instantiate the
1317 * dentry. Since it's not, we drop this one and do a new lookup.
1323 code = afs_symlink(VTOAFS(dip), name, &vattr, target, credp);
1330 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1333 cred_t *credp = crref();
1334 struct vcache *tvcp = NULL;
1336 const char *name = dp->d_name.name;
1338 #if defined(AFS_LINUX26_ENV)
1339 maybe_lock_kernel();
1342 vattr.va_mask = ATTR_MODE;
1343 vattr.va_mode = mode;
1345 code = afs_mkdir(VTOAFS(dip), name, &vattr, &tvcp, credp);
1348 struct inode *ip = AFSTOV(tvcp);
1350 afs_getattr(tvcp, &vattr, credp);
1351 afs_fill_inode(ip, &vattr);
1353 dp->d_op = &afs_dentry_operations;
1354 dp->d_time = hgetlo(VTOAFS(dip)->m.DataVersion);
1355 d_instantiate(dp, ip);
1359 #if defined(AFS_LINUX26_ENV)
1360 maybe_unlock_kernel();
1367 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1370 cred_t *credp = crref();
1371 const char *name = dp->d_name.name;
1373 /* locking kernel conflicts with glock? */
1376 code = afs_rmdir(VTOAFS(dip), name, credp);
1379 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1380 * that failed because a directory is not empty. So, we map
1381 * EEXIST to ENOTEMPTY on linux.
1383 if (code == EEXIST) {
1397 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1398 struct inode *newip, struct dentry *newdp)
1401 cred_t *credp = crref();
1402 const char *oldname = olddp->d_name.name;
1403 const char *newname = newdp->d_name.name;
1404 struct dentry *rehash = NULL;
1406 #if defined(AFS_LINUX26_ENV)
1407 /* Prevent any new references during rename operation. */
1408 maybe_lock_kernel();
1410 if (!d_unhashed(newdp)) {
1415 if (!list_empty(&newdp->d_hash)) {
1421 #if defined(AFS_LINUX24_ENV)
1422 if (atomic_read(&olddp->d_count) > 1)
1423 shrink_dcache_parent(olddp);
1427 code = afs_rename(VTOAFS(oldip), oldname, VTOAFS(newip), newname, credp);
1431 olddp->d_time = 0; /* force to revalidate */
1436 #if defined(AFS_LINUX26_ENV)
1437 maybe_unlock_kernel();
1445 /* afs_linux_ireadlink
1446 * Internal readlink which can return link contents to user or kernel space.
1447 * Note that the buffer is NOT supposed to be null-terminated.
1450 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1453 cred_t *credp = crref();
1457 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1458 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1462 return maxlen - tuio.uio_resid;
1467 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1468 /* afs_linux_readlink
1469 * Fill target (which is in user space) with contents of symlink.
1472 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1475 struct inode *ip = dp->d_inode;
1478 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1484 /* afs_linux_follow_link
1485 * a file system dependent link following routine.
1487 #if defined(AFS_LINUX24_ENV)
1488 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1493 name = osi_Alloc(PATH_MAX);
1499 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1507 code = vfs_follow_link(nd, name);
1510 osi_Free(name, PATH_MAX);
1515 #else /* !defined(AFS_LINUX24_ENV) */
1517 static struct dentry *
1518 afs_linux_follow_link(struct dentry *dp, struct dentry *basep,
1519 unsigned int follow)
1527 name = osi_Alloc(PATH_MAX + 1);
1531 return ERR_PTR(-EIO);
1534 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1539 res = ERR_PTR(code);
1542 res = lookup_dentry(name, basep, follow);
1546 osi_Free(name, PATH_MAX + 1);
1550 #endif /* AFS_LINUX24_ENV */
1551 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1553 #if defined(AFS_CACHE_BYPASS)
1555 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1557 /* The kernel calls readpages before trying readpage, with a list of
1558 * pages. The readahead algorithm expands num_pages when it thinks
1559 * the application will benefit. Unlike readpage, the pages are not
1560 * necessarily allocated. If we do not a) allocate required pages and
1561 * b) remove them from page_list, linux will re-enter at afs_linux_readpage
1562 * for each required page (and the page will be pre-allocated) */
1565 afs_linux_readpages(struct file *fp, struct address_space *mapping,
1566 struct list_head *page_list, unsigned num_pages)
1571 struct iovec* iovecp;
1572 struct nocache_read_request *ancr;
1573 struct page *pp, *ppt;
1574 struct pagevec lrupv;
1578 struct inode *ip = FILE_INODE(fp);
1579 struct vcache *avc = VTOAFS(ip);
1580 afs_int32 bypasscache = 0; /* bypass for this read */
1581 afs_int32 base_index = 0;
1582 afs_int32 page_count = 0;
1587 switch(cache_bypass_strategy) {
1588 case NEVER_BYPASS_CACHE:
1590 case ALWAYS_BYPASS_CACHE:
1593 case LARGE_FILES_BYPASS_CACHE:
1594 if(i_size_read(ip) > cache_bypass_threshold) {
1602 /* In the new incarnation of selective caching, a file's caching policy
1603 * can change, eg because file size exceeds threshold, etc. */
1604 trydo_cache_transition(avc, credp, bypasscache);
1607 while(!list_empty(page_list)) {
1608 pp = list_entry(page_list->prev, struct page, lru);
1613 /* background thread must free: iovecp, auio, ancr */
1614 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
1616 auio = osi_Alloc(sizeof(uio_t));
1617 auio->uio_iov = iovecp;
1618 auio->uio_iovcnt = num_pages;
1619 auio->uio_flag = UIO_READ;
1620 auio->uio_seg = AFS_UIOSYS;
1621 auio->uio_resid = num_pages * PAGE_SIZE;
1623 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1625 ancr->offset = auio->uio_offset;
1626 ancr->length = auio->uio_resid;
1628 pagevec_init(&lrupv, 0);
1630 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
1632 if(list_empty(page_list))
1635 pp = list_entry(page_list->prev, struct page, lru);
1636 /* If we allocate a page and don't remove it from page_list,
1637 * the page cache gets upset. */
1639 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1640 if(pp->index > isize) {
1647 offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1648 auio->uio_offset = offset;
1649 base_index = pp->index;
1651 iovecp[page_ix].iov_len = PAGE_SIZE;
1652 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
1653 if(base_index != pp->index) {
1656 page_cache_release(pp);
1657 iovecp[page_ix].iov_base = (void *) 0;
1665 page_cache_release(pp);
1666 iovecp[page_ix].iov_base = (void *) 0;
1669 if(!PageLocked(pp)) {
1673 /* save the page for background map */
1674 iovecp[page_ix].iov_base = (void*) pp;
1676 /* and put it on the LRU cache */
1677 if (!pagevec_add(&lrupv, pp))
1678 __pagevec_lru_add(&lrupv);
1682 /* If there were useful pages in the page list, make sure all pages
1683 * are in the LRU cache, then schedule the read */
1685 pagevec_lru_add(&lrupv);
1686 code = afs_ReadNoCache(avc, ancr, credp);
1688 /* If there is nothing for the background thread to handle,
1689 * it won't be freeing the things that we never gave it */
1690 osi_Free(iovecp, num_pages * sizeof(struct iovec));
1691 osi_Free(auio, sizeof(uio_t));
1692 osi_Free(ancr, sizeof(struct nocache_read_request));
1694 /* we do not flush, release, or unmap pages--that will be
1695 * done for us by the background thread as each page comes in
1696 * from the fileserver */
1703 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
1704 #endif /* defined(AFS_CACHE_BYPASS */
1707 /* afs_linux_readpage
1708 * all reads come through here. A strategy-like read call.
1711 afs_linux_readpage(struct file *fp, struct page *pp)
1714 cred_t *credp = crref();
1715 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1717 afs_offs_t offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1719 ulong address = afs_linux_page_address(pp);
1720 afs_offs_t offset = pageoff(pp);
1722 #if defined(AFS_CACHE_BYPASS)
1723 afs_int32 bypasscache = 0; /* bypass for this read */
1724 struct nocache_read_request *ancr;
1728 struct iovec *iovecp;
1729 struct inode *ip = FILE_INODE(fp);
1730 afs_int32 cnt = page_count(pp);
1731 struct vcache *avc = VTOAFS(ip);
1733 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1737 atomic_add(1, &pp->count);
1738 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1739 clear_bit(PG_error, &pp->flags);
1741 #if defined(AFS_CACHE_BYPASS)
1742 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1743 /* If the page is past the end of the file, skip it */
1744 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
1745 if(pp->index > isize) {
1752 /* if bypasscache, receiver frees, else we do */
1753 auio = osi_Alloc(sizeof(uio_t));
1754 iovecp = osi_Alloc(sizeof(struct iovec));
1756 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1759 #if defined(AFS_CACHE_BYPASS)
1761 switch(cache_bypass_strategy) {
1762 case NEVER_BYPASS_CACHE:
1764 case ALWAYS_BYPASS_CACHE:
1767 case LARGE_FILES_BYPASS_CACHE:
1768 if(i_size_read(ip) > cache_bypass_threshold) {
1776 /* In the new incarnation of selective caching, a file's caching policy
1777 * can change, eg because file size exceeds threshold, etc. */
1778 trydo_cache_transition(avc, credp, bypasscache);
1783 /* save the page for background map */
1784 auio->uio_iov->iov_base = (void*) pp;
1785 /* the background thread will free this */
1786 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1788 ancr->offset = offset;
1789 ancr->length = PAGE_SIZE;
1791 maybe_lock_kernel();
1792 code = afs_ReadNoCache(avc, ancr, credp);
1793 maybe_unlock_kernel();
1795 goto done; /* skips release page, doing it in bg thread */
1799 #ifdef AFS_LINUX24_ENV
1800 maybe_lock_kernel();
1803 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 */
1805 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1807 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1808 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1811 #ifdef AFS_LINUX24_ENV
1812 maybe_unlock_kernel();
1815 /* XXX valid for no-cache also? Check last bits of files... :)
1816 * Cognate code goes in afs_NoCacheFetchProc. */
1817 if (auio->uio_resid) /* zero remainder of page */
1818 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1821 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1822 flush_dcache_page(pp);
1823 SetPageUptodate(pp);
1825 set_bit(PG_uptodate, &pp->flags);
1829 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1833 clear_bit(PG_locked, &pp->flags);
1838 #if defined(AFS_CACHE_BYPASS)
1840 /* do not call afs_GetDCache if cache is bypassed */
1846 /* free if not bypassing cache */
1847 osi_Free(auio, sizeof(uio_t));
1848 osi_Free(iovecp, sizeof(struct iovec));
1850 if (!code && AFS_CHUNKOFFSET(offset) == 0) {
1852 struct vrequest treq;
1855 code = afs_InitReq(&treq, credp);
1856 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
1857 tdc = afs_FindDCache(avc, offset);
1859 if (!(tdc->mflags & DFNextStarted))
1860 afs_PrefetchChunk(avc, tdc, credp, &treq);
1863 ReleaseWriteLock(&avc->lock);
1874 #if defined(AFS_LINUX24_ENV)
1876 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1877 unsigned long offset, unsigned int count)
1879 struct vcache *vcp = VTOAFS(ip);
1888 buffer = kmap(pp) + offset;
1889 base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
1892 maybe_lock_kernel();
1894 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1895 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1896 ICL_TYPE_INT32, 99999);
1898 ObtainReadLock(&vcp->lock);
1899 if (vcp->states & CPageWrite) {
1900 ReleaseReadLock(&vcp->lock);
1902 maybe_unlock_kernel();
1905 #ifdef AFS_LINUX26_ENV
1906 #if defined(WRITEPAGE_ACTIVATE)
1907 return WRITEPAGE_ACTIVATE;
1909 return AOP_WRITEPAGE_ACTIVATE;
1912 /* should mark it dirty? */
1916 ReleaseReadLock(&vcp->lock);
1918 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1920 code = afs_write(vcp, &tuio, f_flags, credp, 0);
1922 ip->i_size = vcp->m.Length;
1923 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
1926 struct vrequest treq;
1928 ObtainWriteLock(&vcp->lock, 533);
1929 if (!afs_InitReq(&treq, credp))
1930 code = afs_DoPartialWrite(vcp, &treq);
1931 ReleaseWriteLock(&vcp->lock);
1933 code = code ? -code : count - tuio.uio_resid;
1935 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1936 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1937 ICL_TYPE_INT32, code);
1940 maybe_unlock_kernel();
1949 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
1950 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
1952 afs_linux_writepage(struct page *pp)
1955 struct address_space *mapping = pp->mapping;
1956 struct inode *inode;
1957 unsigned long end_index;
1958 unsigned offset = PAGE_CACHE_SIZE;
1961 #if defined(AFS_LINUX26_ENV)
1962 if (PageReclaim(pp)) {
1963 # if defined(WRITEPAGE_ACTIVATE)
1964 return WRITEPAGE_ACTIVATE;
1966 return AOP_WRITEPAGE_ACTIVATE;
1970 if (PageLaunder(pp)) {
1971 return(fail_writepage(pp));
1975 inode = (struct inode *)mapping->host;
1976 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1979 if (pp->index < end_index)
1981 /* things got complicated... */
1982 offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
1983 /* OK, are we completely out? */
1984 if (pp->index >= end_index + 1 || !offset)
1987 status = afs_linux_writepage_sync(inode, pp, 0, offset);
1988 SetPageUptodate(pp);
1990 if (status == offset)
1996 /* afs_linux_updatepage
1997 * What one would have thought was writepage - write dirty page to file.
1998 * Called from generic_file_write. buffer is still in user space. pagep
1999 * has been filled in with old data if we're updating less than a page.
2002 afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset,
2003 unsigned int count, int sync)
2005 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
2006 u8 *page_addr = (u8 *) afs_linux_page_address(pp);
2012 set_bit(PG_locked, &pp->flags);
2016 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2017 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2018 ICL_TYPE_INT32, 99999);
2019 setup_uio(&tuio, &iovec, page_addr + offset,
2020 (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE,
2023 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
2025 ip->i_size = vcp->m.Length;
2026 ip->i_blocks = ((vcp->m.Length + 1023) >> 10) << 1;
2029 struct vrequest treq;
2031 ObtainWriteLock(&vcp->lock, 533);
2032 vcp->m.Date = osi_Time(); /* set modification time */
2033 if (!afs_InitReq(&treq, credp))
2034 code = afs_DoPartialWrite(vcp, &treq);
2035 ReleaseWriteLock(&vcp->lock);
2038 code = code ? -code : count - tuio.uio_resid;
2039 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2040 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2041 ICL_TYPE_INT32, code);
2046 clear_bit(PG_locked, &pp->flags);
2051 /* afs_linux_permission
2052 * Check access rights - returns error if can't check or permission denied.
2055 #ifdef IOP_PERMISSION_TAKES_NAMEIDATA
2056 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2058 afs_linux_permission(struct inode *ip, int mode)
2062 cred_t *credp = crref();
2066 if (mode & MAY_EXEC)
2068 if (mode & MAY_READ)
2070 if (mode & MAY_WRITE)
2072 code = afs_access(VTOAFS(ip), tmp, credp);
2079 #if defined(AFS_LINUX24_ENV)
2081 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2086 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
2087 offset, to - offset);
2088 #if !defined(AFS_LINUX26_ENV)
2096 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2099 /* sometime between 2.4.0 and 2.4.19, the callers of prepare_write began to
2100 call kmap directly instead of relying on us to do it */
2101 #if !defined(AFS_LINUX26_ENV)
2107 extern int afs_notify_change(struct dentry *dp, struct iattr *iattrp);
2110 static struct inode_operations afs_file_iops = {
2111 #if defined(AFS_LINUX26_ENV)
2112 .permission = afs_linux_permission,
2113 .getattr = afs_linux_getattr,
2114 .setattr = afs_notify_change,
2115 #elif defined(AFS_LINUX24_ENV)
2116 .permission = afs_linux_permission,
2117 .revalidate = afs_linux_revalidate,
2118 .setattr = afs_notify_change,
2120 .default_file_ops = &afs_file_fops,
2121 .readpage = afs_linux_readpage,
2122 .revalidate = afs_linux_revalidate,
2123 .updatepage = afs_linux_updatepage,
2127 #if defined(AFS_LINUX24_ENV)
2128 static struct address_space_operations afs_file_aops = {
2129 .readpage = afs_linux_readpage,
2130 #if defined(AFS_CACHE_BYPASS) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
2131 .readpages = afs_linux_readpages,
2133 .writepage = afs_linux_writepage,
2134 .commit_write = afs_linux_commit_write,
2135 .prepare_write = afs_linux_prepare_write,
2140 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2141 * by what sort of operation is allowed.....
2144 static struct inode_operations afs_dir_iops = {
2145 #if !defined(AFS_LINUX24_ENV)
2146 .default_file_ops = &afs_dir_fops,
2148 .setattr = afs_notify_change,
2150 .create = afs_linux_create,
2151 .lookup = afs_linux_lookup,
2152 .link = afs_linux_link,
2153 .unlink = afs_linux_unlink,
2154 .symlink = afs_linux_symlink,
2155 .mkdir = afs_linux_mkdir,
2156 .rmdir = afs_linux_rmdir,
2157 .rename = afs_linux_rename,
2158 #if defined(AFS_LINUX26_ENV)
2159 .getattr = afs_linux_getattr,
2161 .revalidate = afs_linux_revalidate,
2163 .permission = afs_linux_permission,
2166 /* We really need a separate symlink set of ops, since do_follow_link()
2167 * determines if it _is_ a link by checking if the follow_link op is set.
2169 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2171 afs_symlink_filler(struct file *file, struct page *page)
2173 struct inode *ip = (struct inode *)page->mapping->host;
2174 char *p = (char *)kmap(page);
2177 maybe_lock_kernel();
2179 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2184 p[code] = '\0'; /* null terminate? */
2185 maybe_unlock_kernel();
2187 SetPageUptodate(page);
2193 maybe_unlock_kernel();
2201 static struct address_space_operations afs_symlink_aops = {
2202 .readpage = afs_symlink_filler
2204 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2206 static struct inode_operations afs_symlink_iops = {
2207 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2208 .readlink = page_readlink,
2209 #if defined(HAVE_KERNEL_PAGE_FOLLOW_LINK)
2210 .follow_link = page_follow_link,
2212 .follow_link = page_follow_link_light,
2213 .put_link = page_put_link,
2215 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2216 .readlink = afs_linux_readlink,
2217 .follow_link = afs_linux_follow_link,
2218 #if !defined(AFS_LINUX24_ENV)
2219 .permission = afs_linux_permission,
2220 .revalidate = afs_linux_revalidate,
2222 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2223 #if defined(AFS_LINUX24_ENV)
2224 .setattr = afs_notify_change,
2229 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2233 vattr2inode(ip, vattr);
2235 ip->i_mapping->backing_dev_info = &afs_backing_dev_info;
2236 /* Reset ops if symlink or directory. */
2237 if (S_ISREG(ip->i_mode)) {
2238 ip->i_op = &afs_file_iops;
2239 #if defined(AFS_LINUX24_ENV)
2240 ip->i_fop = &afs_file_fops;
2241 ip->i_data.a_ops = &afs_file_aops;
2244 } else if (S_ISDIR(ip->i_mode)) {
2245 ip->i_op = &afs_dir_iops;
2246 #if defined(AFS_LINUX24_ENV)
2247 ip->i_fop = &afs_dir_fops;
2250 } else if (S_ISLNK(ip->i_mode)) {
2251 ip->i_op = &afs_symlink_iops;
2252 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2253 ip->i_data.a_ops = &afs_symlink_aops;
2254 ip->i_mapping = &ip->i_data;