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"
25 #include "afs/sysincludes.h"
26 #include "afsincludes.h"
27 #include "afs/afs_stats.h"
29 #ifdef HAVE_MM_INLINE_H
30 #include <linux/mm_inline.h>
32 #include <linux/pagemap.h>
33 #include <linux/writeback.h>
34 #include <linux/pagevec.h>
36 #include "afs/afs_bypasscache.h"
38 #include "osi_compat.h"
39 #include "osi_pagecopy.h"
41 #ifndef HAVE_LINUX_PAGEVEC_LRU_ADD_FILE
42 #define __pagevec_lru_add_file __pagevec_lru_add
46 #define MAX_ERRNO 1000L
49 extern struct backing_dev_info *afs_backing_dev_info;
51 extern struct vcache *afs_globalVp;
53 /* This function converts a positive error code from AFS into a negative
54 * code suitable for passing into the Linux VFS layer. It checks that the
55 * error code is within the permissable bounds for the ERR_PTR mechanism.
57 * _All_ error codes which come from the AFS layer should be passed through
58 * this function before being returned to the kernel.
62 afs_convert_code(int code) {
63 if ((code >= 0) && (code <= MAX_ERRNO))
69 /* Linux doesn't require a credp for many functions, and crref is an expensive
70 * operation. This helper function avoids obtaining it for VerifyVCache calls
74 afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
79 if (avc->f.states & CStatd) {
87 code = afs_InitReq(&treq, credp);
89 code = afs_VerifyVCache2(avc, &treq);
96 return afs_convert_code(code);
99 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
101 afs_linux_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long segs, loff_t pos)
103 struct file *fp = iocb->ki_filp;
105 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
108 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
109 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
111 code = afs_linux_VerifyVCache(vcp, NULL);
114 /* Linux's FlushPages implementation doesn't ever use credp,
115 * so we optimise by not using it */
116 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
118 code = generic_file_aio_read(iocb, iov, segs, pos);
122 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
123 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
130 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
133 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
136 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
137 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
139 code = afs_linux_VerifyVCache(vcp, NULL);
142 /* Linux's FlushPages implementation doesn't ever use credp,
143 * so we optimise by not using it */
144 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
146 code = do_sync_read(fp, buf, count, offp);
150 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
151 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
159 /* Now we have integrated VM for writes as well as reads. the generic write operations
160 * also take care of re-positioning the pointer if file is open in append
161 * mode. Call fake open/close to ensure we do writes of core dumps.
163 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
165 afs_linux_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long segs, loff_t pos)
168 struct vcache *vcp = VTOAFS(iocb->ki_filp->f_dentry->d_inode);
173 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
174 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
175 (iocb->ki_filp->f_flags & O_APPEND) ? 99998 : 99999);
177 code = afs_linux_VerifyVCache(vcp, &credp);
179 ObtainWriteLock(&vcp->lock, 529);
181 ReleaseWriteLock(&vcp->lock);
184 code = generic_file_aio_write(iocb, iov, segs, pos);
188 ObtainWriteLock(&vcp->lock, 530);
190 if (vcp->execsOrWriters == 1 && !credp)
193 afs_FakeClose(vcp, credp);
194 ReleaseWriteLock(&vcp->lock);
196 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
197 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
207 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
210 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
215 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
216 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
217 (fp->f_flags & O_APPEND) ? 99998 : 99999);
219 code = afs_linux_VerifyVCache(vcp, &credp);
221 ObtainWriteLock(&vcp->lock, 529);
223 ReleaseWriteLock(&vcp->lock);
226 code = do_sync_write(fp, buf, count, offp);
230 ObtainWriteLock(&vcp->lock, 530);
232 if (vcp->execsOrWriters == 1 && !credp)
235 afs_FakeClose(vcp, credp);
236 ReleaseWriteLock(&vcp->lock);
238 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
239 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
249 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
251 /* This is a complete rewrite of afs_readdir, since we can make use of
252 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
253 * handling and use of bulkstats will need to be reflected here as well.
256 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
258 struct vcache *avc = VTOAFS(FILE_INODE(fp));
259 struct vrequest treq;
265 struct DirBuffer entry;
268 afs_size_t origOffset, tlen;
269 cred_t *credp = crref();
270 struct afs_fakestat_state fakestat;
273 AFS_STATCNT(afs_readdir);
275 code = afs_convert_code(afs_InitReq(&treq, credp));
280 afs_InitFakeStat(&fakestat);
281 code = afs_convert_code(afs_EvalFakeStat(&avc, &fakestat, &treq));
285 /* update the cache entry */
287 code = afs_convert_code(afs_VerifyVCache2(avc, &treq));
291 /* get a reference to the entire directory */
292 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
298 ObtainWriteLock(&avc->lock, 811);
299 ObtainReadLock(&tdc->lock);
301 * Make sure that the data in the cache is current. There are two
302 * cases we need to worry about:
303 * 1. The cache data is being fetched by another process.
304 * 2. The cache data is no longer valid
306 while ((avc->f.states & CStatd)
307 && (tdc->dflags & DFFetching)
308 && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
309 ReleaseReadLock(&tdc->lock);
310 ReleaseWriteLock(&avc->lock);
311 afs_osi_Sleep(&tdc->validPos);
312 ObtainWriteLock(&avc->lock, 812);
313 ObtainReadLock(&tdc->lock);
315 if (!(avc->f.states & CStatd)
316 || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
317 ReleaseReadLock(&tdc->lock);
318 ReleaseWriteLock(&avc->lock);
323 /* Set the readdir-in-progress flag, and downgrade the lock
324 * to shared so others will be able to acquire a read lock.
326 avc->f.states |= CReadDir;
327 avc->dcreaddir = tdc;
328 avc->readdir_pid = MyPidxx2Pid(MyPidxx);
329 ConvertWToSLock(&avc->lock);
331 /* Fill in until we get an error or we're done. This implementation
332 * takes an offset in units of blobs, rather than bytes.
335 offset = (int) fp->f_pos;
337 dirpos = BlobScan(tdc, offset);
341 code = afs_dir_GetVerifiedBlob(tdc, dirpos, &entry);
343 afs_warn("Corrupt directory (inode %lx, dirpos %d)",
344 (unsigned long)&tdc->f.inode, dirpos);
345 ReleaseSharedLock(&avc->lock);
351 de = (struct DirEntry *)entry.data;
352 ino = afs_calc_inum (avc->f.fid.Cell, avc->f.fid.Fid.Volume,
353 ntohl(de->fid.vnode));
354 len = strlen(de->name);
356 /* filldir returns -EINVAL when the buffer is full. */
358 unsigned int type = DT_UNKNOWN;
359 struct VenusFid afid;
362 afid.Cell = avc->f.fid.Cell;
363 afid.Fid.Volume = avc->f.fid.Fid.Volume;
364 afid.Fid.Vnode = ntohl(de->fid.vnode);
365 afid.Fid.Unique = ntohl(de->fid.vunique);
366 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
368 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
371 } else if (((tvc->f.states) & (CStatd | CTruth))) {
372 /* CTruth will be set if the object has
377 else if (vtype == VREG)
379 /* Don't do this until we're sure it can't be a mtpt */
380 /* else if (vtype == VLNK)
382 /* what other types does AFS support? */
384 /* clean up from afs_FindVCache */
388 * If this is NFS readdirplus, then the filler is going to
389 * call getattr on this inode, which will deadlock if we're
393 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
399 offset = dirpos + 1 + ((len + 16) >> 5);
401 /* If filldir didn't fill in the last one this is still pointing to that
404 fp->f_pos = (loff_t) offset;
406 ReleaseReadLock(&tdc->lock);
408 UpgradeSToWLock(&avc->lock, 813);
409 avc->f.states &= ~CReadDir;
411 avc->readdir_pid = 0;
412 ReleaseSharedLock(&avc->lock);
416 afs_PutFakeStat(&fakestat);
423 /* in afs_pioctl.c */
424 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
427 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
428 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
430 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
437 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
439 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
443 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
444 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
445 vmap->vm_end - vmap->vm_start);
447 /* get a validated vcache entry */
448 code = afs_linux_VerifyVCache(vcp, NULL);
451 /* Linux's Flushpage implementation doesn't use credp, so optimise
452 * our code to not need to crref() it */
453 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
455 code = generic_file_mmap(fp, vmap);
458 vcp->f.states |= CMAPPED;
466 afs_linux_open(struct inode *ip, struct file *fp)
468 struct vcache *vcp = VTOAFS(ip);
469 cred_t *credp = crref();
473 code = afs_open(&vcp, fp->f_flags, credp);
477 return afs_convert_code(code);
481 afs_linux_release(struct inode *ip, struct file *fp)
483 struct vcache *vcp = VTOAFS(ip);
484 cred_t *credp = crref();
488 code = afs_close(vcp, fp->f_flags, credp);
489 ObtainWriteLock(&vcp->lock, 807);
494 ReleaseWriteLock(&vcp->lock);
498 return afs_convert_code(code);
502 #if defined(FOP_FSYNC_TAKES_DENTRY)
503 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
504 #elif defined(FOP_FSYNC_TAKES_RANGE)
505 afs_linux_fsync(struct file *fp, loff_t start, loff_t end, int datasync)
507 afs_linux_fsync(struct file *fp, int datasync)
511 struct inode *ip = FILE_INODE(fp);
512 cred_t *credp = crref();
514 #if defined(FOP_FSYNC_TAKES_RANGE)
515 mutex_lock(&ip->i_mutex);
518 code = afs_fsync(VTOAFS(ip), credp);
520 #if defined(FOP_FSYNC_TAKES_RANGE)
521 mutex_unlock(&ip->i_mutex);
524 return afs_convert_code(code);
530 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
533 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
534 cred_t *credp = crref();
535 struct AFS_FLOCK flock;
537 /* Convert to a lock format afs_lockctl understands. */
538 memset(&flock, 0, sizeof(flock));
539 flock.l_type = flp->fl_type;
540 flock.l_pid = flp->fl_pid;
542 flock.l_start = flp->fl_start;
543 if (flp->fl_end == OFFSET_MAX)
544 flock.l_len = 0; /* Lock to end of file */
546 flock.l_len = flp->fl_end - flp->fl_start + 1;
548 /* Safe because there are no large files, yet */
549 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
550 if (cmd == F_GETLK64)
552 else if (cmd == F_SETLK64)
554 else if (cmd == F_SETLKW64)
556 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
559 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
562 if ((code == 0 || flp->fl_type == F_UNLCK) &&
563 (cmd == F_SETLK || cmd == F_SETLKW)) {
564 code = afs_posix_lock_file(fp, flp);
565 if (code && flp->fl_type != F_UNLCK) {
566 struct AFS_FLOCK flock2;
568 flock2.l_type = F_UNLCK;
570 afs_lockctl(vcp, &flock2, F_SETLK, credp);
574 /* If lockctl says there are no conflicting locks, then also check with the
575 * kernel, as lockctl knows nothing about byte range locks
577 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
578 afs_posix_test_lock(fp, flp);
579 /* If we found a lock in the kernel's structure, return it */
580 if (flp->fl_type != F_UNLCK) {
586 /* Convert flock back to Linux's file_lock */
587 flp->fl_type = flock.l_type;
588 flp->fl_pid = flock.l_pid;
589 flp->fl_start = flock.l_start;
590 if (flock.l_len == 0)
591 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
593 flp->fl_end = flock.l_start + flock.l_len - 1;
599 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
601 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
603 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
604 cred_t *credp = crref();
605 struct AFS_FLOCK flock;
606 /* Convert to a lock format afs_lockctl understands. */
607 memset(&flock, 0, sizeof(flock));
608 flock.l_type = flp->fl_type;
609 flock.l_pid = flp->fl_pid;
614 /* Safe because there are no large files, yet */
615 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
616 if (cmd == F_GETLK64)
618 else if (cmd == F_SETLK64)
620 else if (cmd == F_SETLKW64)
622 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
625 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
628 if ((code == 0 || flp->fl_type == F_UNLCK) &&
629 (cmd == F_SETLK || cmd == F_SETLKW)) {
630 flp->fl_flags &=~ FL_SLEEP;
631 code = flock_lock_file_wait(fp, flp);
632 if (code && flp->fl_type != F_UNLCK) {
633 struct AFS_FLOCK flock2;
635 flock2.l_type = F_UNLCK;
637 afs_lockctl(vcp, &flock2, F_SETLK, credp);
641 /* Convert flock back to Linux's file_lock */
642 flp->fl_type = flock.l_type;
643 flp->fl_pid = flock.l_pid;
651 * essentially the same as afs_fsync() but we need to get the return
652 * code for the sys_close() here, not afs_linux_release(), so call
653 * afs_StoreAllSegments() with AFS_LASTSTORE
656 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
657 afs_linux_flush(struct file *fp, fl_owner_t id)
659 afs_linux_flush(struct file *fp)
662 struct vrequest treq;
670 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
678 vcp = VTOAFS(FILE_INODE(fp));
680 code = afs_InitReq(&treq, credp);
683 /* If caching is bypassed for this file, or globally, just return 0 */
684 if (cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
687 ObtainReadLock(&vcp->lock);
688 if (vcp->cachingStates & FCSBypass)
690 ReleaseReadLock(&vcp->lock);
693 /* future proof: don't rely on 0 return from afs_InitReq */
698 ObtainSharedLock(&vcp->lock, 535);
699 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
700 UpgradeSToWLock(&vcp->lock, 536);
701 if (!AFS_IS_DISCONNECTED) {
702 code = afs_StoreAllSegments(vcp,
704 AFS_SYNC | AFS_LASTSTORE);
706 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
708 ConvertWToSLock(&vcp->lock);
710 code = afs_CheckCode(code, &treq, 54);
711 ReleaseSharedLock(&vcp->lock);
718 return afs_convert_code(code);
721 struct file_operations afs_dir_fops = {
722 .read = generic_read_dir,
723 .readdir = afs_linux_readdir,
724 #ifdef HAVE_UNLOCKED_IOCTL
725 .unlocked_ioctl = afs_unlocked_xioctl,
729 #ifdef HAVE_COMPAT_IOCTL
730 .compat_ioctl = afs_unlocked_xioctl,
732 .open = afs_linux_open,
733 .release = afs_linux_release,
734 .llseek = default_llseek,
735 #ifdef HAVE_LINUX_NOOP_FSYNC
738 .fsync = simple_sync_file,
742 struct file_operations afs_file_fops = {
743 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
744 .aio_read = afs_linux_aio_read,
745 .aio_write = afs_linux_aio_write,
747 .read = afs_linux_read,
748 .write = afs_linux_write,
750 #ifdef HAVE_UNLOCKED_IOCTL
751 .unlocked_ioctl = afs_unlocked_xioctl,
755 #ifdef HAVE_COMPAT_IOCTL
756 .compat_ioctl = afs_unlocked_xioctl,
758 .mmap = afs_linux_mmap,
759 .open = afs_linux_open,
760 .flush = afs_linux_flush,
761 #if defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
762 .sendfile = generic_file_sendfile,
764 #if defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
765 .splice_write = generic_file_splice_write,
766 .splice_read = generic_file_splice_read,
768 .release = afs_linux_release,
769 .fsync = afs_linux_fsync,
770 .lock = afs_linux_lock,
771 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
772 .flock = afs_linux_flock,
774 .llseek = default_llseek,
777 static struct dentry *
778 canonical_dentry(struct inode *ip)
780 struct vcache *vcp = VTOAFS(ip);
781 struct dentry *first = NULL, *ret = NULL, *cur;
784 * if vcp->target_link is set, and can be found in ip->i_dentry, use that.
785 * otherwise, use the first dentry in ip->i_dentry.
786 * if ip->i_dentry is empty, use the 'dentry' argument we were given.
788 /* note that vcp->target_link specifies which dentry to use, but we have
789 * no reference held on that dentry. so, we cannot use or dereference
790 * vcp->target_link itself, since it may have been freed. instead, we only
791 * use it to compare to pointers in the ip->i_dentry list. */
795 # ifdef HAVE_DCACHE_LOCK
796 spin_lock(&dcache_lock);
798 spin_lock(&ip->i_lock);
801 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
803 if (!vcp->target_link || cur == vcp->target_link) {
816 vcp->target_link = ret;
818 # ifdef HAVE_DCACHE_LOCK
822 spin_unlock(&dcache_lock);
827 spin_unlock(&ip->i_lock);
833 /**********************************************************************
834 * AFS Linux dentry operations
835 **********************************************************************/
837 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
838 * that has its mvid (parent dir's fid) pointer set to the wrong directory
839 * due to being mounted in multiple points at once. fix_bad_parent()
840 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
841 * dotdotfid and mtpoint fid members.
843 * dp - dentry to be checked.
844 * credp - credentials
845 * vcp, pvc - item's and parent's vcache pointer
849 * This dentry's vcache's mvid will be set to the correct parent directory's
851 * This root vnode's volume will have its dotdotfid and mtpoint fids set
852 * to the correct parent and mountpoint fids.
856 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
858 struct vcache *avc = NULL;
860 /* force a lookup, so vcp->mvid is fixed up */
861 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
862 if (!avc || vcp != avc) { /* bad, very bad.. */
863 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
864 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
865 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
866 ICL_TYPE_POINTER, dp);
869 AFS_RELE(AFSTOV(avc));
874 /* afs_linux_revalidate
875 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
878 afs_linux_revalidate(struct dentry *dp)
881 struct vcache *vcp = VTOAFS(dp->d_inode);
885 if (afs_shuttingdown)
891 /* Make this a fast path (no crref), since it's called so often. */
892 if (vcp->states & CStatd) {
893 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
895 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
896 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
899 fix_bad_parent(dp); /* check and correct mvid */
908 /* This avoids the crref when we don't have to do it. Watch for
909 * changes in afs_getattr that don't get replicated here!
911 if (vcp->f.states & CStatd &&
912 (!afs_fakestat_enable || vcp->mvstat != 1) &&
914 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
915 code = afs_CopyOutAttrs(vcp, &vattr);
918 code = afs_getattr(vcp, &vattr, credp);
923 afs_fill_inode(AFSTOV(vcp), &vattr);
927 return afs_convert_code(code);
931 * Set iattr data into vattr. Assume vattr cleared before call.
934 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
936 vattrp->va_mask = iattrp->ia_valid;
937 if (iattrp->ia_valid & ATTR_MODE)
938 vattrp->va_mode = iattrp->ia_mode;
939 if (iattrp->ia_valid & ATTR_UID)
940 vattrp->va_uid = iattrp->ia_uid;
941 if (iattrp->ia_valid & ATTR_GID)
942 vattrp->va_gid = iattrp->ia_gid;
943 if (iattrp->ia_valid & ATTR_SIZE)
944 vattrp->va_size = iattrp->ia_size;
945 if (iattrp->ia_valid & ATTR_ATIME) {
946 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
947 vattrp->va_atime.tv_usec = 0;
949 if (iattrp->ia_valid & ATTR_MTIME) {
950 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
951 vattrp->va_mtime.tv_usec = 0;
953 if (iattrp->ia_valid & ATTR_CTIME) {
954 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
955 vattrp->va_ctime.tv_usec = 0;
960 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
963 vattr2inode(struct inode *ip, struct vattr *vp)
965 ip->i_ino = vp->va_nodeid;
966 #ifdef HAVE_LINUX_SET_NLINK
967 set_nlink(ip, vp->va_nlink);
969 ip->i_nlink = vp->va_nlink;
971 ip->i_blocks = vp->va_blocks;
972 #ifdef STRUCT_INODE_HAS_I_BLKBITS
973 ip->i_blkbits = AFS_BLKBITS;
975 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
976 ip->i_blksize = vp->va_blocksize;
978 ip->i_rdev = vp->va_rdev;
979 ip->i_mode = vp->va_mode;
980 ip->i_uid = vp->va_uid;
981 ip->i_gid = vp->va_gid;
982 i_size_write(ip, vp->va_size);
983 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
984 ip->i_atime.tv_nsec = 0;
985 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
986 /* Set the mtime nanoseconds to the sysname generation number.
987 * This convinces NFS clients that all directories have changed
988 * any time the sysname list changes.
990 ip->i_mtime.tv_nsec = afs_sysnamegen;
991 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
992 ip->i_ctime.tv_nsec = 0;
996 * Linux version of setattr call. What to change is in the iattr struct.
997 * We need to set bits in both the Linux inode as well as the vcache.
1000 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1003 cred_t *credp = crref();
1004 struct inode *ip = dp->d_inode;
1008 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1011 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1013 afs_getattr(VTOAFS(ip), &vattr, credp);
1014 vattr2inode(ip, &vattr);
1018 return afs_convert_code(code);
1022 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1024 int err = afs_linux_revalidate(dentry);
1026 generic_fillattr(dentry->d_inode, stat);
1031 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1032 * In kernels 2.2.10 and above, we are passed an additional flags var which
1033 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1034 * we are advised to follow the entry if it is a link or to make sure that
1035 * it is a directory. But since the kernel itself checks these possibilities
1036 * later on, we shouldn't have to do it until later. Perhaps in the future..
1038 * The code here assumes that on entry the global lock is not held
1041 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
1042 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1044 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1048 cred_t *credp = NULL;
1049 struct vcache *vcp, *pvcp, *tvc = NULL;
1050 struct dentry *parent;
1052 struct afs_fakestat_state fakestate;
1056 /* We don't support RCU path walking */
1057 if (nd->flags & LOOKUP_RCU)
1061 afs_InitFakeStat(&fakestate);
1064 vcp = VTOAFS(dp->d_inode);
1066 if (vcp == afs_globalVp)
1069 parent = dget_parent(dp);
1070 pvcp = VTOAFS(parent->d_inode);
1072 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1078 if (locked && vcp->mvstat == 1) { /* mount point */
1079 if (vcp->mvid && (vcp->f.states & CMValid)) {
1080 int tryEvalOnly = 0;
1082 struct vrequest treq;
1084 code = afs_InitReq(&treq, credp);
1086 (strcmp(dp->d_name.name, ".directory") == 0)) {
1090 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1092 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1093 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1094 /* a mount point, not yet replaced by its directory */
1099 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1100 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1101 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1106 /* If the last looker changes, we should make sure the current
1107 * looker still has permission to examine this file. This would
1108 * always require a crref() which would be "slow".
1110 if (vcp->last_looker != treq.uid) {
1111 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
1114 vcp->last_looker = treq.uid;
1119 /* If the parent's DataVersion has changed or the vnode
1120 * is longer valid, we need to do a full lookup. VerifyVCache
1121 * isn't enough since the vnode may have been renamed.
1124 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1130 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1131 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1132 if (!tvc || tvc != vcp) {
1137 if (afs_getattr(vcp, &vattr, credp)) {
1142 vattr2inode(AFSTOV(vcp), &vattr);
1143 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1146 /* should we always update the attributes at this point? */
1147 /* unlikely--the vcache entry hasn't changed */
1152 /* If this code is ever enabled, we should use dget_parent to handle
1153 * getting the parent, and dput() to dispose of it. See above for an
1155 pvcp = VTOAFS(dp->d_parent->d_inode);
1156 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1160 /* No change in parent's DataVersion so this negative
1161 * lookup is still valid. BUT, if a server is down a
1162 * negative lookup can result so there should be a
1163 * liftime as well. For now, always expire.
1176 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1178 /* we hold the global lock if we evaluated a mount point */
1185 shrink_dcache_parent(dp);
1191 if (have_submounts(dp))
1199 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1201 struct vcache *vcp = VTOAFS(ip);
1204 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1205 (void) afs_InactiveVCache(vcp, NULL);
1208 afs_linux_clear_nfsfs_renamed(dp);
1214 #if defined(DOP_D_DELETE_TAKES_CONST)
1215 afs_dentry_delete(const struct dentry *dp)
1217 afs_dentry_delete(struct dentry *dp)
1220 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1221 return 1; /* bad inode? */
1226 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1227 static struct vfsmount *
1228 afs_dentry_automount(struct path *path)
1230 struct dentry *target;
1232 target = canonical_dentry(path->dentry->d_inode);
1234 if (target == path->dentry) {
1241 path->dentry = target;
1244 spin_lock(&path->dentry->d_lock);
1245 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1246 spin_unlock(&path->dentry->d_lock);
1251 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1253 struct dentry_operations afs_dentry_operations = {
1254 .d_revalidate = afs_linux_dentry_revalidate,
1255 .d_delete = afs_dentry_delete,
1256 .d_iput = afs_dentry_iput,
1257 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1258 .d_automount = afs_dentry_automount,
1259 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1262 /**********************************************************************
1263 * AFS Linux inode operations
1264 **********************************************************************/
1268 * Merely need to set enough of vattr to get us through the create. Note
1269 * that the higher level code (open_namei) will take care of any tuncation
1270 * explicitly. Exclusive open is also taken care of in open_namei.
1272 * name is in kernel space at this point.
1275 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1276 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1277 struct nameidata *nd)
1279 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1280 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1281 struct nameidata *nd)
1283 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1288 cred_t *credp = crref();
1289 const char *name = dp->d_name.name;
1294 vattr.va_mode = mode;
1295 vattr.va_type = mode & S_IFMT;
1298 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1302 struct inode *ip = AFSTOV(vcp);
1304 afs_getattr(vcp, &vattr, credp);
1305 afs_fill_inode(ip, &vattr);
1306 insert_inode_hash(ip);
1307 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1308 dp->d_op = &afs_dentry_operations;
1310 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1311 d_instantiate(dp, ip);
1316 return afs_convert_code(code);
1319 /* afs_linux_lookup */
1320 static struct dentry *
1321 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1322 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1323 struct nameidata *nd)
1325 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1328 cred_t *credp = crref();
1329 struct vcache *vcp = NULL;
1330 const char *comp = dp->d_name.name;
1331 struct inode *ip = NULL;
1332 struct dentry *newdp = NULL;
1336 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1340 struct vcache *parent_vc = VTOAFS(dip);
1342 if (parent_vc == vcp) {
1343 /* This is possible if the parent dir is a mountpoint to a volume,
1344 * and the dir entry we looked up is a mountpoint to the same
1345 * volume. Linux cannot cope with this, so return an error instead
1346 * of risking a deadlock or panic. */
1354 afs_getattr(vcp, &vattr, credp);
1355 afs_fill_inode(ip, &vattr);
1356 if (hlist_unhashed(&ip->i_hash))
1357 insert_inode_hash(ip);
1359 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1360 dp->d_op = &afs_dentry_operations;
1362 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1365 if (ip && S_ISDIR(ip->i_mode)) {
1367 struct dentry *alias;
1372 /* Try to invalidate an existing alias in favor of our new one */
1373 alias = d_find_alias(ip);
1374 /* But not if it's disconnected; then we want d_splice_alias below */
1375 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1376 if (d_invalidate(alias) == 0) {
1377 /* there may be more aliases; try again until we run out */
1385 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1386 ip->i_flags |= S_AUTOMOUNT;
1389 newdp = d_splice_alias(ip, dp);
1394 /* It's ok for the file to not be found. That's noted by the caller by
1395 * seeing that the dp->d_inode field is NULL.
1397 if (!code || code == ENOENT)
1400 return ERR_PTR(afs_convert_code(code));
1404 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1407 cred_t *credp = crref();
1408 const char *name = newdp->d_name.name;
1409 struct inode *oldip = olddp->d_inode;
1411 /* If afs_link returned the vnode, we could instantiate the
1412 * dentry. Since it's not, we drop this one and do a new lookup.
1417 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1421 return afs_convert_code(code);
1424 /* We have to have a Linux specific sillyrename function, because we
1425 * also have to keep the dcache up to date when we're doing a silly
1426 * rename - so we don't want the generic vnodeops doing this behind our
1431 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1434 struct vcache *tvc = VTOAFS(dentry->d_inode);
1435 struct dentry *__dp = NULL;
1436 char *__name = NULL;
1439 if (afs_linux_nfsfs_renamed(dentry))
1447 osi_FreeSmallSpace(__name);
1448 __name = afs_newname();
1451 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1454 osi_FreeSmallSpace(__name);
1457 } while (__dp->d_inode != NULL);
1460 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1461 VTOAFS(dir), (char *)__dp->d_name.name,
1464 tvc->mvid = (void *) __name;
1467 crfree(tvc->uncred);
1469 tvc->uncred = credp;
1470 tvc->f.states |= CUnlinked;
1471 afs_linux_set_nfsfs_renamed(dentry);
1473 osi_FreeSmallSpace(__name);
1478 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1479 d_move(dentry, __dp);
1488 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1491 cred_t *credp = crref();
1492 const char *name = dp->d_name.name;
1493 struct vcache *tvc = VTOAFS(dp->d_inode);
1495 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1496 && !(tvc->f.states & CUnlinked)) {
1498 code = afs_linux_sillyrename(dip, dp, credp);
1501 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1508 return afs_convert_code(code);
1513 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1516 cred_t *credp = crref();
1518 const char *name = dp->d_name.name;
1520 /* If afs_symlink returned the vnode, we could instantiate the
1521 * dentry. Since it's not, we drop this one and do a new lookup.
1527 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1530 return afs_convert_code(code);
1534 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1535 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1537 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1541 cred_t *credp = crref();
1542 struct vcache *tvcp = NULL;
1544 const char *name = dp->d_name.name;
1547 vattr.va_mask = ATTR_MODE;
1548 vattr.va_mode = mode;
1550 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1553 struct inode *ip = AFSTOV(tvcp);
1555 afs_getattr(tvcp, &vattr, credp);
1556 afs_fill_inode(ip, &vattr);
1558 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1559 dp->d_op = &afs_dentry_operations;
1561 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1562 d_instantiate(dp, ip);
1567 return afs_convert_code(code);
1571 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1574 cred_t *credp = crref();
1575 const char *name = dp->d_name.name;
1577 /* locking kernel conflicts with glock? */
1580 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1583 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1584 * that failed because a directory is not empty. So, we map
1585 * EEXIST to ENOTEMPTY on linux.
1587 if (code == EEXIST) {
1596 return afs_convert_code(code);
1601 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1602 struct inode *newip, struct dentry *newdp)
1605 cred_t *credp = crref();
1606 const char *oldname = olddp->d_name.name;
1607 const char *newname = newdp->d_name.name;
1608 struct dentry *rehash = NULL;
1610 /* Prevent any new references during rename operation. */
1612 if (!d_unhashed(newdp)) {
1617 #if defined(D_COUNT_INT)
1618 spin_lock(&olddp->d_lock);
1619 if (olddp->d_count > 1) {
1620 spin_unlock(&olddp->d_lock);
1621 shrink_dcache_parent(olddp);
1623 spin_unlock(&olddp->d_lock);
1625 if (atomic_read(&olddp->d_count) > 1)
1626 shrink_dcache_parent(olddp);
1630 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1634 olddp->d_time = 0; /* force to revalidate */
1640 return afs_convert_code(code);
1644 /* afs_linux_ireadlink
1645 * Internal readlink which can return link contents to user or kernel space.
1646 * Note that the buffer is NOT supposed to be null-terminated.
1649 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1652 cred_t *credp = crref();
1656 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1657 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1661 return maxlen - tuio.uio_resid;
1663 return afs_convert_code(code);
1666 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1667 /* afs_linux_readlink
1668 * Fill target (which is in user space) with contents of symlink.
1671 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1674 struct inode *ip = dp->d_inode;
1677 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1683 /* afs_linux_follow_link
1684 * a file system dependent link following routine.
1686 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1691 name = kmalloc(PATH_MAX, GFP_NOFS);
1697 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1705 nd_set_link(nd, name);
1710 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1712 char *name = nd_get_link(nd);
1714 if (name && !IS_ERR(name))
1718 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1720 /* Populate a page by filling it from the cache file pointed at by cachefp
1721 * (which contains indicated chunk)
1722 * If task is NULL, the page copy occurs syncronously, and the routine
1723 * returns with page still locked. If task is non-NULL, then page copies
1724 * may occur in the background, and the page will be unlocked when it is
1728 afs_linux_read_cache(struct file *cachefp, struct page *page,
1729 int chunk, struct pagevec *lrupv,
1730 struct afs_pagecopy_task *task) {
1731 loff_t offset = page_offset(page);
1732 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1733 struct page *newpage, *cachepage;
1734 struct address_space *cachemapping;
1738 cachemapping = cacheinode->i_mapping;
1742 /* If we're trying to read a page that's past the end of the disk
1743 * cache file, then just return a zeroed page */
1744 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1745 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1746 SetPageUptodate(page);
1752 /* From our offset, we now need to work out which page in the disk
1753 * file it corresponds to. This will be fun ... */
1754 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1756 while (cachepage == NULL) {
1757 cachepage = find_get_page(cachemapping, pageindex);
1760 newpage = page_cache_alloc_cold(cachemapping);
1766 code = add_to_page_cache(newpage, cachemapping,
1767 pageindex, GFP_KERNEL);
1769 cachepage = newpage;
1772 page_cache_get(cachepage);
1773 if (!pagevec_add(lrupv, cachepage))
1774 __pagevec_lru_add_file(lrupv);
1777 page_cache_release(newpage);
1779 if (code != -EEXIST)
1783 lock_page(cachepage);
1787 if (!PageUptodate(cachepage)) {
1788 ClearPageError(cachepage);
1789 code = cachemapping->a_ops->readpage(NULL, cachepage);
1790 if (!code && !task) {
1791 wait_on_page_locked(cachepage);
1794 unlock_page(cachepage);
1798 if (PageUptodate(cachepage)) {
1799 copy_highpage(page, cachepage);
1800 flush_dcache_page(page);
1801 SetPageUptodate(page);
1806 afs_pagecopy_queue_page(task, cachepage, page);
1818 page_cache_release(cachepage);
1824 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1826 loff_t offset = page_offset(pp);
1827 struct inode *ip = FILE_INODE(fp);
1828 struct vcache *avc = VTOAFS(ip);
1830 struct file *cacheFp = NULL;
1833 struct pagevec lrupv;
1835 /* Not a UFS cache, don't do anything */
1836 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1839 /* Can't do anything if the vcache isn't statd , or if the read
1840 * crosses a chunk boundary.
1842 if (!(avc->f.states & CStatd) ||
1843 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1847 ObtainWriteLock(&avc->lock, 911);
1849 /* XXX - See if hinting actually makes things faster !!! */
1851 /* See if we have a suitable entry already cached */
1855 /* We need to lock xdcache, then dcache, to handle situations where
1856 * the hint is on the free list. However, we can't safely do this
1857 * according to the locking hierarchy. So, use a non blocking lock.
1859 ObtainReadLock(&afs_xdcache);
1860 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1862 if (dcLocked && (tdc->index != NULLIDX)
1863 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1864 && tdc->f.chunk == AFS_CHUNK(offset)
1865 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1866 /* Bonus - the hint was correct */
1869 /* Only destroy the hint if its actually invalid, not if there's
1870 * just been a locking failure */
1872 ReleaseReadLock(&tdc->lock);
1879 ReleaseReadLock(&afs_xdcache);
1882 /* No hint, or hint is no longer valid - see if we can get something
1883 * directly from the dcache
1886 tdc = afs_FindDCache(avc, offset);
1889 ReleaseWriteLock(&avc->lock);
1894 ObtainReadLock(&tdc->lock);
1896 /* Is the dcache we've been given currently up to date */
1897 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1898 (tdc->dflags & DFFetching)) {
1899 ReleaseWriteLock(&avc->lock);
1900 ReleaseReadLock(&tdc->lock);
1905 /* Update our hint for future abuse */
1908 /* Okay, so we've now got a cache file that is up to date */
1910 /* XXX - I suspect we should be locking the inodes before we use them! */
1912 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1913 pagevec_init(&lrupv, 0);
1915 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1917 if (pagevec_count(&lrupv))
1918 __pagevec_lru_add_file(&lrupv);
1920 filp_close(cacheFp, NULL);
1923 ReleaseReadLock(&tdc->lock);
1924 ReleaseWriteLock(&avc->lock);
1931 /* afs_linux_readpage
1933 * This function is split into two, because prepare_write/begin_write
1934 * require a readpage call which doesn't unlock the resulting page upon
1938 afs_linux_fillpage(struct file *fp, struct page *pp)
1943 struct iovec *iovecp;
1944 struct inode *ip = FILE_INODE(fp);
1945 afs_int32 cnt = page_count(pp);
1946 struct vcache *avc = VTOAFS(ip);
1947 afs_offs_t offset = page_offset(pp);
1951 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1961 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1962 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
1964 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1969 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1970 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1971 99999); /* not a possible code value */
1973 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1975 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1976 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1978 AFS_DISCON_UNLOCK();
1981 /* XXX valid for no-cache also? Check last bits of files... :)
1982 * Cognate code goes in afs_NoCacheFetchProc. */
1983 if (auio->uio_resid) /* zero remainder of page */
1984 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1987 flush_dcache_page(pp);
1988 SetPageUptodate(pp);
1997 return afs_convert_code(code);
2001 afs_linux_prefetch(struct file *fp, struct page *pp)
2004 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2005 afs_offs_t offset = page_offset(pp);
2007 if (AFS_CHUNKOFFSET(offset) == 0) {
2009 struct vrequest treq;
2014 code = afs_InitReq(&treq, credp);
2015 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2016 tdc = afs_FindDCache(avc, offset);
2018 if (!(tdc->mflags & DFNextStarted))
2019 afs_PrefetchChunk(avc, tdc, credp, &treq);
2022 ReleaseWriteLock(&avc->lock);
2027 return afs_convert_code(code);
2032 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2033 struct list_head *page_list, unsigned num_pages)
2038 struct iovec* iovecp;
2039 struct nocache_read_request *ancr;
2041 struct pagevec lrupv;
2045 struct inode *ip = FILE_INODE(fp);
2046 struct vcache *avc = VTOAFS(ip);
2047 afs_int32 base_index = 0;
2048 afs_int32 page_count = 0;
2051 /* background thread must free: iovecp, auio, ancr */
2052 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2054 auio = osi_Alloc(sizeof(struct uio));
2055 auio->uio_iov = iovecp;
2056 auio->uio_iovcnt = num_pages;
2057 auio->uio_flag = UIO_READ;
2058 auio->uio_seg = AFS_UIOSYS;
2059 auio->uio_resid = num_pages * PAGE_SIZE;
2061 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2063 ancr->offset = auio->uio_offset;
2064 ancr->length = auio->uio_resid;
2066 pagevec_init(&lrupv, 0);
2068 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2070 if(list_empty(page_list))
2073 pp = list_entry(page_list->prev, struct page, lru);
2074 /* If we allocate a page and don't remove it from page_list,
2075 * the page cache gets upset. */
2077 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2078 if(pp->index > isize) {
2085 offset = page_offset(pp);
2086 auio->uio_offset = offset;
2087 base_index = pp->index;
2089 iovecp[page_ix].iov_len = PAGE_SIZE;
2090 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2091 if(base_index != pp->index) {
2094 page_cache_release(pp);
2095 iovecp[page_ix].iov_base = (void *) 0;
2097 ancr->length -= PAGE_SIZE;
2104 page_cache_release(pp);
2105 iovecp[page_ix].iov_base = (void *) 0;
2108 if(!PageLocked(pp)) {
2112 /* increment page refcount--our original design assumed
2113 * that locking it would effectively pin it; protect
2114 * ourselves from the possiblity that this assumption is
2115 * is faulty, at low cost (provided we do not fail to
2116 * do the corresponding decref on the other side) */
2119 /* save the page for background map */
2120 iovecp[page_ix].iov_base = (void*) pp;
2122 /* and put it on the LRU cache */
2123 if (!pagevec_add(&lrupv, pp))
2124 __pagevec_lru_add_file(&lrupv);
2128 /* If there were useful pages in the page list, make sure all pages
2129 * are in the LRU cache, then schedule the read */
2131 if (pagevec_count(&lrupv))
2132 __pagevec_lru_add_file(&lrupv);
2134 code = afs_ReadNoCache(avc, ancr, credp);
2137 /* If there is nothing for the background thread to handle,
2138 * it won't be freeing the things that we never gave it */
2139 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2140 osi_Free(auio, sizeof(struct uio));
2141 osi_Free(ancr, sizeof(struct nocache_read_request));
2143 /* we do not flush, release, or unmap pages--that will be
2144 * done for us by the background thread as each page comes in
2145 * from the fileserver */
2146 return afs_convert_code(code);
2151 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2153 cred_t *credp = NULL;
2155 struct iovec *iovecp;
2156 struct nocache_read_request *ancr;
2160 * Special case: if page is at or past end of file, just zero it and set
2163 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2164 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2165 SetPageUptodate(pp);
2172 /* receiver frees */
2173 auio = osi_Alloc(sizeof(struct uio));
2174 iovecp = osi_Alloc(sizeof(struct iovec));
2176 /* address can be NULL, because we overwrite it with 'pp', below */
2177 setup_uio(auio, iovecp, NULL, page_offset(pp),
2178 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2180 /* save the page for background map */
2181 get_page(pp); /* see above */
2182 auio->uio_iov->iov_base = (void*) pp;
2183 /* the background thread will free this */
2184 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2186 ancr->offset = page_offset(pp);
2187 ancr->length = PAGE_SIZE;
2190 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2193 return afs_convert_code(code);
2197 afs_linux_can_bypass(struct inode *ip) {
2198 switch(cache_bypass_strategy) {
2199 case NEVER_BYPASS_CACHE:
2201 case ALWAYS_BYPASS_CACHE:
2203 case LARGE_FILES_BYPASS_CACHE:
2204 if(i_size_read(ip) > cache_bypass_threshold)
2211 /* Check if a file is permitted to bypass the cache by policy, and modify
2212 * the cache bypass state recorded for that file */
2215 afs_linux_bypass_check(struct inode *ip) {
2218 int bypass = afs_linux_can_bypass(ip);
2221 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2229 afs_linux_readpage(struct file *fp, struct page *pp)
2233 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2234 code = afs_linux_bypass_readpage(fp, pp);
2236 code = afs_linux_fillpage(fp, pp);
2238 code = afs_linux_prefetch(fp, pp);
2245 /* Readpages reads a number of pages for a particular file. We use
2246 * this to optimise the reading, by limiting the number of times upon which
2247 * we have to lookup, lock and open vcaches and dcaches
2251 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2252 struct list_head *page_list, unsigned int num_pages)
2254 struct inode *inode = mapping->host;
2255 struct vcache *avc = VTOAFS(inode);
2257 struct file *cacheFp = NULL;
2259 unsigned int page_idx;
2261 struct pagevec lrupv;
2262 struct afs_pagecopy_task *task;
2264 if (afs_linux_bypass_check(inode))
2265 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2267 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2271 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2276 ObtainWriteLock(&avc->lock, 912);
2279 task = afs_pagecopy_init_task();
2282 pagevec_init(&lrupv, 0);
2283 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2284 struct page *page = list_entry(page_list->prev, struct page, lru);
2285 list_del(&page->lru);
2286 offset = page_offset(page);
2288 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2290 ReleaseReadLock(&tdc->lock);
2295 filp_close(cacheFp, NULL);
2300 if ((tdc = afs_FindDCache(avc, offset))) {
2301 ObtainReadLock(&tdc->lock);
2302 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2303 (tdc->dflags & DFFetching)) {
2304 ReleaseReadLock(&tdc->lock);
2311 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2314 if (tdc && !add_to_page_cache(page, mapping, page->index,
2316 page_cache_get(page);
2317 if (!pagevec_add(&lrupv, page))
2318 __pagevec_lru_add_file(&lrupv);
2320 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2322 page_cache_release(page);
2324 if (pagevec_count(&lrupv))
2325 __pagevec_lru_add_file(&lrupv);
2328 filp_close(cacheFp, NULL);
2330 afs_pagecopy_put_task(task);
2334 ReleaseReadLock(&tdc->lock);
2338 ReleaseWriteLock(&avc->lock);
2343 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2346 afs_linux_prepare_writeback(struct vcache *avc) {
2347 if (avc->f.states & CPageWrite) {
2348 return AOP_WRITEPAGE_ACTIVATE;
2350 avc->f.states |= CPageWrite;
2355 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2356 struct vrequest treq;
2359 if (!afs_InitReq(&treq, credp))
2360 code = afs_DoPartialWrite(avc, &treq);
2362 return afs_convert_code(code);
2366 afs_linux_complete_writeback(struct vcache *avc) {
2367 avc->f.states &= ~CPageWrite;
2370 /* Writeback a given page syncronously. Called with no AFS locks held */
2372 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2373 unsigned long offset, unsigned int count,
2376 struct vcache *vcp = VTOAFS(ip);
2384 buffer = kmap(pp) + offset;
2385 base = page_offset(pp) + offset;
2388 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2389 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2390 ICL_TYPE_INT32, 99999);
2392 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2394 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2396 i_size_write(ip, vcp->f.m.Length);
2397 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2399 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
2401 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2402 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2403 ICL_TYPE_INT32, code);
2412 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2413 unsigned long offset, unsigned int count)
2417 struct vcache *vcp = VTOAFS(ip);
2420 /* Catch recursive writeback. This occurs if the kernel decides
2421 * writeback is required whilst we are writing to the cache, or
2422 * flushing to the server. When we're running syncronously (as
2423 * opposed to from writepage) we can't actually do anything about
2424 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2427 ObtainWriteLock(&vcp->lock, 532);
2428 afs_linux_prepare_writeback(vcp);
2429 ReleaseWriteLock(&vcp->lock);
2433 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2436 ObtainWriteLock(&vcp->lock, 533);
2438 code1 = afs_linux_dopartialwrite(vcp, credp);
2439 afs_linux_complete_writeback(vcp);
2440 ReleaseWriteLock(&vcp->lock);
2451 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2452 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2454 afs_linux_writepage(struct page *pp)
2457 struct address_space *mapping = pp->mapping;
2458 struct inode *inode;
2461 unsigned int to = PAGE_CACHE_SIZE;
2466 if (PageReclaim(pp)) {
2467 return AOP_WRITEPAGE_ACTIVATE;
2468 /* XXX - Do we need to redirty the page here? */
2473 inode = mapping->host;
2474 vcp = VTOAFS(inode);
2475 isize = i_size_read(inode);
2477 /* Don't defeat an earlier truncate */
2478 if (page_offset(pp) > isize) {
2479 set_page_writeback(pp);
2485 ObtainWriteLock(&vcp->lock, 537);
2486 code = afs_linux_prepare_writeback(vcp);
2487 if (code == AOP_WRITEPAGE_ACTIVATE) {
2488 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2489 * to return with the page still locked */
2490 ReleaseWriteLock(&vcp->lock);
2495 /* Grab the creds structure currently held in the vnode, and
2496 * get a reference to it, in case it goes away ... */
2502 ReleaseWriteLock(&vcp->lock);
2505 set_page_writeback(pp);
2507 SetPageUptodate(pp);
2509 /* We can unlock the page here, because it's protected by the
2510 * page_writeback flag. This should make us less vulnerable to
2511 * deadlocking in afs_write and afs_DoPartialWrite
2515 /* If this is the final page, then just write the number of bytes that
2516 * are actually in it */
2517 if ((isize - page_offset(pp)) < to )
2518 to = isize - page_offset(pp);
2520 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2523 ObtainWriteLock(&vcp->lock, 538);
2525 /* As much as we might like to ignore a file server error here,
2526 * and just try again when we close(), unfortunately StoreAllSegments
2527 * will invalidate our chunks if the server returns a permanent error,
2528 * so we need to at least try and get that error back to the user
2531 code1 = afs_linux_dopartialwrite(vcp, credp);
2533 afs_linux_complete_writeback(vcp);
2534 ReleaseWriteLock(&vcp->lock);
2539 end_page_writeback(pp);
2540 page_cache_release(pp);
2551 /* afs_linux_permission
2552 * Check access rights - returns error if can't check or permission denied.
2555 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2556 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2557 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2558 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2560 afs_linux_permission(struct inode *ip, int mode)
2567 /* Check for RCU path walking */
2568 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2569 if (flags & IPERM_FLAG_RCU)
2571 #elif defined(MAY_NOT_BLOCK)
2572 if (mode & MAY_NOT_BLOCK)
2578 if (mode & MAY_EXEC)
2580 if (mode & MAY_READ)
2582 if (mode & MAY_WRITE)
2584 code = afs_access(VTOAFS(ip), tmp, credp);
2588 return afs_convert_code(code);
2592 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2596 struct inode *inode = FILE_INODE(file);
2597 loff_t pagebase = page_offset(page);
2599 if (i_size_read(inode) < (pagebase + offset))
2600 i_size_write(inode, pagebase + offset);
2602 if (PageChecked(page)) {
2603 SetPageUptodate(page);
2604 ClearPageChecked(page);
2607 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2613 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2617 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2618 * prepare_write. Essentially, if the page exists within the file,
2619 * and is not being fully written, then we should populate it.
2622 if (!PageUptodate(page)) {
2623 loff_t pagebase = page_offset(page);
2624 loff_t isize = i_size_read(page->mapping->host);
2626 /* Is the location we are writing to beyond the end of the file? */
2627 if (pagebase >= isize ||
2628 ((from == 0) && (pagebase + to) >= isize)) {
2629 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2630 SetPageChecked(page);
2631 /* Are we we writing a full page */
2632 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2633 SetPageChecked(page);
2634 /* Is the page readable, if it's wronly, we don't care, because we're
2635 * not actually going to read from it ... */
2636 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2637 /* We don't care if fillpage fails, because if it does the page
2638 * won't be marked as up to date
2640 afs_linux_fillpage(file, page);
2646 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2648 afs_linux_write_end(struct file *file, struct address_space *mapping,
2649 loff_t pos, unsigned len, unsigned copied,
2650 struct page *page, void *fsdata)
2653 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2655 code = afs_linux_commit_write(file, page, from, from + len);
2658 page_cache_release(page);
2663 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2664 loff_t pos, unsigned len, unsigned flags,
2665 struct page **pagep, void **fsdata)
2668 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2669 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2672 page = grab_cache_page_write_begin(mapping, index, flags);
2675 code = afs_linux_prepare_write(file, page, from, from + len);
2678 page_cache_release(page);
2685 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2687 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2689 struct dentry **dpp;
2690 struct dentry *target;
2692 target = canonical_dentry(dentry->d_inode);
2694 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2695 dpp = &nd->path.dentry;
2705 *dpp = dget(dentry);
2710 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2713 static struct inode_operations afs_file_iops = {
2714 .permission = afs_linux_permission,
2715 .getattr = afs_linux_getattr,
2716 .setattr = afs_notify_change,
2719 static struct address_space_operations afs_file_aops = {
2720 .readpage = afs_linux_readpage,
2721 .readpages = afs_linux_readpages,
2722 .writepage = afs_linux_writepage,
2723 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2724 .write_begin = afs_linux_write_begin,
2725 .write_end = afs_linux_write_end,
2727 .commit_write = afs_linux_commit_write,
2728 .prepare_write = afs_linux_prepare_write,
2733 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2734 * by what sort of operation is allowed.....
2737 static struct inode_operations afs_dir_iops = {
2738 .setattr = afs_notify_change,
2739 .create = afs_linux_create,
2740 .lookup = afs_linux_lookup,
2741 .link = afs_linux_link,
2742 .unlink = afs_linux_unlink,
2743 .symlink = afs_linux_symlink,
2744 .mkdir = afs_linux_mkdir,
2745 .rmdir = afs_linux_rmdir,
2746 .rename = afs_linux_rename,
2747 .getattr = afs_linux_getattr,
2748 .permission = afs_linux_permission,
2749 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2750 .follow_link = afs_linux_dir_follow_link,
2754 /* We really need a separate symlink set of ops, since do_follow_link()
2755 * determines if it _is_ a link by checking if the follow_link op is set.
2757 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2759 afs_symlink_filler(struct file *file, struct page *page)
2761 struct inode *ip = (struct inode *)page->mapping->host;
2762 char *p = (char *)kmap(page);
2766 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2771 p[code] = '\0'; /* null terminate? */
2773 SetPageUptodate(page);
2785 static struct address_space_operations afs_symlink_aops = {
2786 .readpage = afs_symlink_filler
2788 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2790 static struct inode_operations afs_symlink_iops = {
2791 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2792 .readlink = page_readlink,
2793 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2794 .follow_link = page_follow_link,
2796 .follow_link = page_follow_link_light,
2797 .put_link = page_put_link,
2799 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2800 .readlink = afs_linux_readlink,
2801 .follow_link = afs_linux_follow_link,
2802 .put_link = afs_linux_put_link,
2803 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2804 .setattr = afs_notify_change,
2808 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2812 vattr2inode(ip, vattr);
2814 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2815 /* Reset ops if symlink or directory. */
2816 if (S_ISREG(ip->i_mode)) {
2817 ip->i_op = &afs_file_iops;
2818 ip->i_fop = &afs_file_fops;
2819 ip->i_data.a_ops = &afs_file_aops;
2821 } else if (S_ISDIR(ip->i_mode)) {
2822 ip->i_op = &afs_dir_iops;
2823 ip->i_fop = &afs_dir_fops;
2825 } else if (S_ISLNK(ip->i_mode)) {
2826 ip->i_op = &afs_symlink_iops;
2827 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2828 ip->i_data.a_ops = &afs_symlink_aops;
2829 ip->i_mapping = &ip->i_data;