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
100 # ifdef LINUX_HAS_NONVECTOR_AIO
102 afs_linux_aio_read(struct kiocb *iocb, char __user *buf, size_t bufsize,
106 afs_linux_aio_read(struct kiocb *iocb, const struct iovec *buf,
107 unsigned long bufsize, loff_t pos)
110 struct file *fp = iocb->ki_filp;
112 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
115 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
116 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
117 (afs_int32)bufsize, ICL_TYPE_INT32, 99999);
118 code = afs_linux_VerifyVCache(vcp, NULL);
121 /* Linux's FlushPages implementation doesn't ever use credp,
122 * so we optimise by not using it */
123 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
125 code = generic_file_aio_read(iocb, buf, bufsize, pos);
129 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
130 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
131 (afs_int32)bufsize, ICL_TYPE_INT32, code);
137 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
140 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
143 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
144 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
146 code = afs_linux_VerifyVCache(vcp, NULL);
149 /* Linux's FlushPages implementation doesn't ever use credp,
150 * so we optimise by not using it */
151 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
153 code = do_sync_read(fp, buf, count, offp);
157 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
158 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
166 /* Now we have integrated VM for writes as well as reads. the generic write operations
167 * also take care of re-positioning the pointer if file is open in append
168 * mode. Call fake open/close to ensure we do writes of core dumps.
170 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
171 # ifdef LINUX_HAS_NONVECTOR_AIO
173 afs_linux_aio_write(struct kiocb *iocb, const char __user *buf, size_t bufsize,
177 afs_linux_aio_write(struct kiocb *iocb, const struct iovec *buf,
178 unsigned long bufsize, loff_t pos)
182 struct vcache *vcp = VTOAFS(iocb->ki_filp->f_dentry->d_inode);
187 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
188 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
189 (afs_int32)bufsize, ICL_TYPE_INT32,
190 (iocb->ki_filp->f_flags & O_APPEND) ? 99998 : 99999);
192 code = afs_linux_VerifyVCache(vcp, &credp);
194 ObtainWriteLock(&vcp->lock, 529);
196 ReleaseWriteLock(&vcp->lock);
199 code = generic_file_aio_write(iocb, buf, bufsize, pos);
203 ObtainWriteLock(&vcp->lock, 530);
205 if (vcp->execsOrWriters == 1 && !credp)
208 afs_FakeClose(vcp, credp);
209 ReleaseWriteLock(&vcp->lock);
211 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
212 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
213 (afs_int32)bufsize, ICL_TYPE_INT32, code);
222 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
225 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
230 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
231 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
232 (fp->f_flags & O_APPEND) ? 99998 : 99999);
234 code = afs_linux_VerifyVCache(vcp, &credp);
236 ObtainWriteLock(&vcp->lock, 529);
238 ReleaseWriteLock(&vcp->lock);
241 code = do_sync_write(fp, buf, count, offp);
245 ObtainWriteLock(&vcp->lock, 530);
247 if (vcp->execsOrWriters == 1 && !credp)
250 afs_FakeClose(vcp, credp);
251 ReleaseWriteLock(&vcp->lock);
253 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
254 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
264 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
266 /* This is a complete rewrite of afs_readdir, since we can make use of
267 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
268 * handling and use of bulkstats will need to be reflected here as well.
271 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
273 struct vcache *avc = VTOAFS(FILE_INODE(fp));
274 struct vrequest treq;
280 struct DirBuffer entry;
283 afs_size_t origOffset, tlen;
284 cred_t *credp = crref();
285 struct afs_fakestat_state fakestat;
288 AFS_STATCNT(afs_readdir);
290 code = afs_convert_code(afs_InitReq(&treq, credp));
295 afs_InitFakeStat(&fakestat);
296 code = afs_convert_code(afs_EvalFakeStat(&avc, &fakestat, &treq));
300 /* update the cache entry */
302 code = afs_convert_code(afs_VerifyVCache2(avc, &treq));
306 /* get a reference to the entire directory */
307 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
313 ObtainWriteLock(&avc->lock, 811);
314 ObtainReadLock(&tdc->lock);
316 * Make sure that the data in the cache is current. There are two
317 * cases we need to worry about:
318 * 1. The cache data is being fetched by another process.
319 * 2. The cache data is no longer valid
321 while ((avc->f.states & CStatd)
322 && (tdc->dflags & DFFetching)
323 && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
324 ReleaseReadLock(&tdc->lock);
325 ReleaseWriteLock(&avc->lock);
326 afs_osi_Sleep(&tdc->validPos);
327 ObtainWriteLock(&avc->lock, 812);
328 ObtainReadLock(&tdc->lock);
330 if (!(avc->f.states & CStatd)
331 || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
332 ReleaseReadLock(&tdc->lock);
333 ReleaseWriteLock(&avc->lock);
338 /* Set the readdir-in-progress flag, and downgrade the lock
339 * to shared so others will be able to acquire a read lock.
341 avc->f.states |= CReadDir;
342 avc->dcreaddir = tdc;
343 avc->readdir_pid = MyPidxx2Pid(MyPidxx);
344 ConvertWToSLock(&avc->lock);
346 /* Fill in until we get an error or we're done. This implementation
347 * takes an offset in units of blobs, rather than bytes.
350 offset = (int) fp->f_pos;
352 dirpos = BlobScan(tdc, offset);
356 code = afs_dir_GetVerifiedBlob(tdc, dirpos, &entry);
358 afs_warn("Corrupt directory (inode %lx, dirpos %d)",
359 (unsigned long)&tdc->f.inode, dirpos);
360 ReleaseSharedLock(&avc->lock);
366 de = (struct DirEntry *)entry.data;
367 ino = afs_calc_inum (avc->f.fid.Cell, avc->f.fid.Fid.Volume,
368 ntohl(de->fid.vnode));
369 len = strlen(de->name);
371 /* filldir returns -EINVAL when the buffer is full. */
373 unsigned int type = DT_UNKNOWN;
374 struct VenusFid afid;
377 afid.Cell = avc->f.fid.Cell;
378 afid.Fid.Volume = avc->f.fid.Fid.Volume;
379 afid.Fid.Vnode = ntohl(de->fid.vnode);
380 afid.Fid.Unique = ntohl(de->fid.vunique);
381 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
383 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
386 } else if (((tvc->f.states) & (CStatd | CTruth))) {
387 /* CTruth will be set if the object has
392 else if (vtype == VREG)
394 /* Don't do this until we're sure it can't be a mtpt */
395 /* else if (vtype == VLNK)
397 /* what other types does AFS support? */
399 /* clean up from afs_FindVCache */
403 * If this is NFS readdirplus, then the filler is going to
404 * call getattr on this inode, which will deadlock if we're
408 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
414 offset = dirpos + 1 + ((len + 16) >> 5);
416 /* If filldir didn't fill in the last one this is still pointing to that
419 fp->f_pos = (loff_t) offset;
421 ReleaseReadLock(&tdc->lock);
423 UpgradeSToWLock(&avc->lock, 813);
424 avc->f.states &= ~CReadDir;
426 avc->readdir_pid = 0;
427 ReleaseSharedLock(&avc->lock);
431 afs_PutFakeStat(&fakestat);
438 /* in afs_pioctl.c */
439 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
442 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
443 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
445 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
452 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
454 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
458 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
459 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
460 vmap->vm_end - vmap->vm_start);
462 /* get a validated vcache entry */
463 code = afs_linux_VerifyVCache(vcp, NULL);
466 /* Linux's Flushpage implementation doesn't use credp, so optimise
467 * our code to not need to crref() it */
468 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
470 code = generic_file_mmap(fp, vmap);
473 vcp->f.states |= CMAPPED;
481 afs_linux_open(struct inode *ip, struct file *fp)
483 struct vcache *vcp = VTOAFS(ip);
484 cred_t *credp = crref();
488 code = afs_open(&vcp, fp->f_flags, credp);
492 return afs_convert_code(code);
496 afs_linux_release(struct inode *ip, struct file *fp)
498 struct vcache *vcp = VTOAFS(ip);
499 cred_t *credp = crref();
503 code = afs_close(vcp, fp->f_flags, credp);
504 ObtainWriteLock(&vcp->lock, 807);
509 ReleaseWriteLock(&vcp->lock);
513 return afs_convert_code(code);
517 #if defined(FOP_FSYNC_TAKES_DENTRY)
518 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
519 #elif defined(FOP_FSYNC_TAKES_RANGE)
520 afs_linux_fsync(struct file *fp, loff_t start, loff_t end, int datasync)
522 afs_linux_fsync(struct file *fp, int datasync)
526 struct inode *ip = FILE_INODE(fp);
527 cred_t *credp = crref();
529 #if defined(FOP_FSYNC_TAKES_RANGE)
530 mutex_lock(&ip->i_mutex);
533 code = afs_fsync(VTOAFS(ip), credp);
535 #if defined(FOP_FSYNC_TAKES_RANGE)
536 mutex_unlock(&ip->i_mutex);
539 return afs_convert_code(code);
545 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
548 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
549 cred_t *credp = crref();
550 struct AFS_FLOCK flock;
552 /* Convert to a lock format afs_lockctl understands. */
553 memset(&flock, 0, sizeof(flock));
554 flock.l_type = flp->fl_type;
555 flock.l_pid = flp->fl_pid;
557 flock.l_start = flp->fl_start;
558 if (flp->fl_end == OFFSET_MAX)
559 flock.l_len = 0; /* Lock to end of file */
561 flock.l_len = flp->fl_end - flp->fl_start + 1;
563 /* Safe because there are no large files, yet */
564 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
565 if (cmd == F_GETLK64)
567 else if (cmd == F_SETLK64)
569 else if (cmd == F_SETLKW64)
571 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
574 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
577 if ((code == 0 || flp->fl_type == F_UNLCK) &&
578 (cmd == F_SETLK || cmd == F_SETLKW)) {
579 code = afs_posix_lock_file(fp, flp);
580 if (code && flp->fl_type != F_UNLCK) {
581 struct AFS_FLOCK flock2;
583 flock2.l_type = F_UNLCK;
585 afs_lockctl(vcp, &flock2, F_SETLK, credp);
589 /* If lockctl says there are no conflicting locks, then also check with the
590 * kernel, as lockctl knows nothing about byte range locks
592 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
593 afs_posix_test_lock(fp, flp);
594 /* If we found a lock in the kernel's structure, return it */
595 if (flp->fl_type != F_UNLCK) {
601 /* Convert flock back to Linux's file_lock */
602 flp->fl_type = flock.l_type;
603 flp->fl_pid = flock.l_pid;
604 flp->fl_start = flock.l_start;
605 if (flock.l_len == 0)
606 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
608 flp->fl_end = flock.l_start + flock.l_len - 1;
614 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
616 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
618 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
619 cred_t *credp = crref();
620 struct AFS_FLOCK flock;
621 /* Convert to a lock format afs_lockctl understands. */
622 memset(&flock, 0, sizeof(flock));
623 flock.l_type = flp->fl_type;
624 flock.l_pid = flp->fl_pid;
629 /* Safe because there are no large files, yet */
630 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
631 if (cmd == F_GETLK64)
633 else if (cmd == F_SETLK64)
635 else if (cmd == F_SETLKW64)
637 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
640 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
643 if ((code == 0 || flp->fl_type == F_UNLCK) &&
644 (cmd == F_SETLK || cmd == F_SETLKW)) {
645 flp->fl_flags &=~ FL_SLEEP;
646 code = flock_lock_file_wait(fp, flp);
647 if (code && flp->fl_type != F_UNLCK) {
648 struct AFS_FLOCK flock2;
650 flock2.l_type = F_UNLCK;
652 afs_lockctl(vcp, &flock2, F_SETLK, credp);
656 /* Convert flock back to Linux's file_lock */
657 flp->fl_type = flock.l_type;
658 flp->fl_pid = flock.l_pid;
666 * essentially the same as afs_fsync() but we need to get the return
667 * code for the sys_close() here, not afs_linux_release(), so call
668 * afs_StoreAllSegments() with AFS_LASTSTORE
671 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
672 afs_linux_flush(struct file *fp, fl_owner_t id)
674 afs_linux_flush(struct file *fp)
677 struct vrequest treq;
685 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
693 vcp = VTOAFS(FILE_INODE(fp));
695 code = afs_InitReq(&treq, credp);
698 /* If caching is bypassed for this file, or globally, just return 0 */
699 if (cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
702 ObtainReadLock(&vcp->lock);
703 if (vcp->cachingStates & FCSBypass)
705 ReleaseReadLock(&vcp->lock);
708 /* future proof: don't rely on 0 return from afs_InitReq */
713 ObtainSharedLock(&vcp->lock, 535);
714 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
715 UpgradeSToWLock(&vcp->lock, 536);
716 if (!AFS_IS_DISCONNECTED) {
717 code = afs_StoreAllSegments(vcp,
719 AFS_SYNC | AFS_LASTSTORE);
721 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
723 ConvertWToSLock(&vcp->lock);
725 code = afs_CheckCode(code, &treq, 54);
726 ReleaseSharedLock(&vcp->lock);
733 return afs_convert_code(code);
736 struct file_operations afs_dir_fops = {
737 .read = generic_read_dir,
738 .readdir = afs_linux_readdir,
739 #ifdef HAVE_UNLOCKED_IOCTL
740 .unlocked_ioctl = afs_unlocked_xioctl,
744 #ifdef HAVE_COMPAT_IOCTL
745 .compat_ioctl = afs_unlocked_xioctl,
747 .open = afs_linux_open,
748 .release = afs_linux_release,
749 .llseek = default_llseek,
750 #ifdef HAVE_LINUX_NOOP_FSYNC
753 .fsync = simple_sync_file,
757 struct file_operations afs_file_fops = {
758 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
759 .aio_read = afs_linux_aio_read,
760 .aio_write = afs_linux_aio_write,
762 .read = afs_linux_read,
763 .write = afs_linux_write,
765 #ifdef HAVE_UNLOCKED_IOCTL
766 .unlocked_ioctl = afs_unlocked_xioctl,
770 #ifdef HAVE_COMPAT_IOCTL
771 .compat_ioctl = afs_unlocked_xioctl,
773 .mmap = afs_linux_mmap,
774 .open = afs_linux_open,
775 .flush = afs_linux_flush,
776 #if defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
777 .sendfile = generic_file_sendfile,
779 #if defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
780 .splice_write = generic_file_splice_write,
781 .splice_read = generic_file_splice_read,
783 .release = afs_linux_release,
784 .fsync = afs_linux_fsync,
785 .lock = afs_linux_lock,
786 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
787 .flock = afs_linux_flock,
789 .llseek = default_llseek,
792 static struct dentry *
793 canonical_dentry(struct inode *ip)
795 struct vcache *vcp = VTOAFS(ip);
796 struct dentry *first = NULL, *ret = NULL, *cur;
797 #if defined(D_ALIAS_IS_HLIST)
798 struct hlist_node *p;
802 * if vcp->target_link is set, and can be found in ip->i_dentry, use that.
803 * otherwise, use the first dentry in ip->i_dentry.
804 * if ip->i_dentry is empty, use the 'dentry' argument we were given.
806 /* note that vcp->target_link specifies which dentry to use, but we have
807 * no reference held on that dentry. so, we cannot use or dereference
808 * vcp->target_link itself, since it may have been freed. instead, we only
809 * use it to compare to pointers in the ip->i_dentry list. */
813 # ifdef HAVE_DCACHE_LOCK
814 spin_lock(&dcache_lock);
816 spin_lock(&ip->i_lock);
819 #if defined(D_ALIAS_IS_HLIST)
820 hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
822 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
825 if (!vcp->target_link || cur == vcp->target_link) {
838 vcp->target_link = ret;
840 # ifdef HAVE_DCACHE_LOCK
844 spin_unlock(&dcache_lock);
849 spin_unlock(&ip->i_lock);
855 /**********************************************************************
856 * AFS Linux dentry operations
857 **********************************************************************/
859 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
860 * that has its mvid (parent dir's fid) pointer set to the wrong directory
861 * due to being mounted in multiple points at once. fix_bad_parent()
862 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
863 * dotdotfid and mtpoint fid members.
865 * dp - dentry to be checked.
866 * credp - credentials
867 * vcp, pvc - item's and parent's vcache pointer
871 * This dentry's vcache's mvid will be set to the correct parent directory's
873 * This root vnode's volume will have its dotdotfid and mtpoint fids set
874 * to the correct parent and mountpoint fids.
878 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
880 struct vcache *avc = NULL;
882 /* force a lookup, so vcp->mvid is fixed up */
883 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
884 if (!avc || vcp != avc) { /* bad, very bad.. */
885 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
886 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
887 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
888 ICL_TYPE_POINTER, dp);
891 AFS_RELE(AFSTOV(avc));
896 /* afs_linux_revalidate
897 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
900 afs_linux_revalidate(struct dentry *dp)
903 struct vcache *vcp = VTOAFS(dp->d_inode);
907 if (afs_shuttingdown)
913 /* Make this a fast path (no crref), since it's called so often. */
914 if (vcp->states & CStatd) {
915 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
917 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
918 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
921 fix_bad_parent(dp); /* check and correct mvid */
930 /* This avoids the crref when we don't have to do it. Watch for
931 * changes in afs_getattr that don't get replicated here!
933 if (vcp->f.states & CStatd &&
934 (!afs_fakestat_enable || vcp->mvstat != 1) &&
936 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
937 code = afs_CopyOutAttrs(vcp, &vattr);
940 code = afs_getattr(vcp, &vattr, credp);
945 afs_fill_inode(AFSTOV(vcp), &vattr);
949 return afs_convert_code(code);
953 * Set iattr data into vattr. Assume vattr cleared before call.
956 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
958 vattrp->va_mask = iattrp->ia_valid;
959 if (iattrp->ia_valid & ATTR_MODE)
960 vattrp->va_mode = iattrp->ia_mode;
961 if (iattrp->ia_valid & ATTR_UID)
962 vattrp->va_uid = iattrp->ia_uid;
963 if (iattrp->ia_valid & ATTR_GID)
964 vattrp->va_gid = iattrp->ia_gid;
965 if (iattrp->ia_valid & ATTR_SIZE)
966 vattrp->va_size = iattrp->ia_size;
967 if (iattrp->ia_valid & ATTR_ATIME) {
968 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
969 vattrp->va_atime.tv_usec = 0;
971 if (iattrp->ia_valid & ATTR_MTIME) {
972 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
973 vattrp->va_mtime.tv_usec = 0;
975 if (iattrp->ia_valid & ATTR_CTIME) {
976 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
977 vattrp->va_ctime.tv_usec = 0;
982 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
985 vattr2inode(struct inode *ip, struct vattr *vp)
987 ip->i_ino = vp->va_nodeid;
988 #ifdef HAVE_LINUX_SET_NLINK
989 set_nlink(ip, vp->va_nlink);
991 ip->i_nlink = vp->va_nlink;
993 ip->i_blocks = vp->va_blocks;
994 #ifdef STRUCT_INODE_HAS_I_BLKBITS
995 ip->i_blkbits = AFS_BLKBITS;
997 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
998 ip->i_blksize = vp->va_blocksize;
1000 ip->i_rdev = vp->va_rdev;
1001 ip->i_mode = vp->va_mode;
1002 ip->i_uid = vp->va_uid;
1003 ip->i_gid = vp->va_gid;
1004 i_size_write(ip, vp->va_size);
1005 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
1006 ip->i_atime.tv_nsec = 0;
1007 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
1008 /* Set the mtime nanoseconds to the sysname generation number.
1009 * This convinces NFS clients that all directories have changed
1010 * any time the sysname list changes.
1012 ip->i_mtime.tv_nsec = afs_sysnamegen;
1013 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
1014 ip->i_ctime.tv_nsec = 0;
1017 /* afs_notify_change
1018 * Linux version of setattr call. What to change is in the iattr struct.
1019 * We need to set bits in both the Linux inode as well as the vcache.
1022 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1025 cred_t *credp = crref();
1026 struct inode *ip = dp->d_inode;
1030 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1033 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1035 afs_getattr(VTOAFS(ip), &vattr, credp);
1036 vattr2inode(ip, &vattr);
1040 return afs_convert_code(code);
1044 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1046 int err = afs_linux_revalidate(dentry);
1048 generic_fillattr(dentry->d_inode, stat);
1053 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1054 * In kernels 2.2.10 and above, we are passed an additional flags var which
1055 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1056 * we are advised to follow the entry if it is a link or to make sure that
1057 * it is a directory. But since the kernel itself checks these possibilities
1058 * later on, we shouldn't have to do it until later. Perhaps in the future..
1060 * The code here assumes that on entry the global lock is not held
1063 #if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1064 afs_linux_dentry_revalidate(struct dentry *dp, unsigned int flags)
1065 #elif defined(DOP_REVALIDATE_TAKES_NAMEIDATA)
1066 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1068 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1072 cred_t *credp = NULL;
1073 struct vcache *vcp, *pvcp, *tvc = NULL;
1074 struct dentry *parent;
1076 struct afs_fakestat_state fakestate;
1080 /* We don't support RCU path walking */
1081 # if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1082 if (flags & LOOKUP_RCU)
1084 if (nd->flags & LOOKUP_RCU)
1089 afs_InitFakeStat(&fakestate);
1092 vcp = VTOAFS(dp->d_inode);
1094 if (vcp == afs_globalVp)
1097 parent = dget_parent(dp);
1098 pvcp = VTOAFS(parent->d_inode);
1100 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1106 if (locked && vcp->mvstat == 1) { /* mount point */
1107 if (vcp->mvid && (vcp->f.states & CMValid)) {
1108 int tryEvalOnly = 0;
1110 struct vrequest treq;
1112 code = afs_InitReq(&treq, credp);
1114 (strcmp(dp->d_name.name, ".directory") == 0)) {
1118 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1120 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1121 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1122 /* a mount point, not yet replaced by its directory */
1127 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1128 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1129 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1134 /* If the last looker changes, we should make sure the current
1135 * looker still has permission to examine this file. This would
1136 * always require a crref() which would be "slow".
1138 if (vcp->last_looker != treq.uid) {
1139 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
1142 vcp->last_looker = treq.uid;
1147 /* If the parent's DataVersion has changed or the vnode
1148 * is longer valid, we need to do a full lookup. VerifyVCache
1149 * isn't enough since the vnode may have been renamed.
1152 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1158 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1159 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1160 if (!tvc || tvc != vcp) {
1165 if (afs_getattr(vcp, &vattr, credp)) {
1170 vattr2inode(AFSTOV(vcp), &vattr);
1171 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1174 /* should we always update the attributes at this point? */
1175 /* unlikely--the vcache entry hasn't changed */
1180 /* If this code is ever enabled, we should use dget_parent to handle
1181 * getting the parent, and dput() to dispose of it. See above for an
1183 pvcp = VTOAFS(dp->d_parent->d_inode);
1184 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1188 /* No change in parent's DataVersion so this negative
1189 * lookup is still valid. BUT, if a server is down a
1190 * negative lookup can result so there should be a
1191 * liftime as well. For now, always expire.
1204 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1206 /* we hold the global lock if we evaluated a mount point */
1213 shrink_dcache_parent(dp);
1219 if (have_submounts(dp))
1227 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1229 struct vcache *vcp = VTOAFS(ip);
1232 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1233 (void) afs_InactiveVCache(vcp, NULL);
1236 afs_linux_clear_nfsfs_renamed(dp);
1242 #if defined(DOP_D_DELETE_TAKES_CONST)
1243 afs_dentry_delete(const struct dentry *dp)
1245 afs_dentry_delete(struct dentry *dp)
1248 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1249 return 1; /* bad inode? */
1254 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1255 static struct vfsmount *
1256 afs_dentry_automount(afs_linux_path_t *path)
1258 struct dentry *target;
1260 target = canonical_dentry(path->dentry->d_inode);
1262 if (target == path->dentry) {
1269 path->dentry = target;
1272 spin_lock(&path->dentry->d_lock);
1273 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1274 spin_unlock(&path->dentry->d_lock);
1279 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1281 struct dentry_operations afs_dentry_operations = {
1282 .d_revalidate = afs_linux_dentry_revalidate,
1283 .d_delete = afs_dentry_delete,
1284 .d_iput = afs_dentry_iput,
1285 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1286 .d_automount = afs_dentry_automount,
1287 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1290 /**********************************************************************
1291 * AFS Linux inode operations
1292 **********************************************************************/
1296 * Merely need to set enough of vattr to get us through the create. Note
1297 * that the higher level code (open_namei) will take care of any tuncation
1298 * explicitly. Exclusive open is also taken care of in open_namei.
1300 * name is in kernel space at this point.
1303 #if defined(IOP_CREATE_TAKES_BOOL)
1304 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1306 #elif defined(IOP_CREATE_TAKES_UMODE_T)
1307 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1308 struct nameidata *nd)
1309 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
1310 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1311 struct nameidata *nd)
1313 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1317 cred_t *credp = crref();
1318 const char *name = dp->d_name.name;
1323 vattr.va_mode = mode;
1324 vattr.va_type = mode & S_IFMT;
1327 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1331 struct inode *ip = AFSTOV(vcp);
1333 afs_getattr(vcp, &vattr, credp);
1334 afs_fill_inode(ip, &vattr);
1335 insert_inode_hash(ip);
1336 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1337 dp->d_op = &afs_dentry_operations;
1339 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1340 d_instantiate(dp, ip);
1345 return afs_convert_code(code);
1348 /* afs_linux_lookup */
1349 static struct dentry *
1350 #if defined(IOP_LOOKUP_TAKES_UNSIGNED)
1351 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1353 #elif defined(IOP_LOOKUP_TAKES_NAMEIDATA)
1354 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1355 struct nameidata *nd)
1357 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1360 cred_t *credp = crref();
1361 struct vcache *vcp = NULL;
1362 const char *comp = dp->d_name.name;
1363 struct inode *ip = NULL;
1364 struct dentry *newdp = NULL;
1368 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1372 struct vcache *parent_vc = VTOAFS(dip);
1374 if (parent_vc == vcp) {
1375 /* This is possible if the parent dir is a mountpoint to a volume,
1376 * and the dir entry we looked up is a mountpoint to the same
1377 * volume. Linux cannot cope with this, so return an error instead
1378 * of risking a deadlock or panic. */
1386 afs_getattr(vcp, &vattr, credp);
1387 afs_fill_inode(ip, &vattr);
1388 if (hlist_unhashed(&ip->i_hash))
1389 insert_inode_hash(ip);
1391 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1392 dp->d_op = &afs_dentry_operations;
1394 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1397 if (ip && S_ISDIR(ip->i_mode)) {
1399 struct dentry *alias;
1404 /* Try to invalidate an existing alias in favor of our new one */
1405 alias = d_find_alias(ip);
1406 /* But not if it's disconnected; then we want d_splice_alias below */
1407 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1408 if (d_invalidate(alias) == 0) {
1409 /* there may be more aliases; try again until we run out */
1417 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1418 ip->i_flags |= S_AUTOMOUNT;
1421 newdp = d_splice_alias(ip, dp);
1426 /* It's ok for the file to not be found. That's noted by the caller by
1427 * seeing that the dp->d_inode field is NULL.
1429 if (!code || code == ENOENT)
1432 return ERR_PTR(afs_convert_code(code));
1436 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1439 cred_t *credp = crref();
1440 const char *name = newdp->d_name.name;
1441 struct inode *oldip = olddp->d_inode;
1443 /* If afs_link returned the vnode, we could instantiate the
1444 * dentry. Since it's not, we drop this one and do a new lookup.
1449 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1453 return afs_convert_code(code);
1456 /* We have to have a Linux specific sillyrename function, because we
1457 * also have to keep the dcache up to date when we're doing a silly
1458 * rename - so we don't want the generic vnodeops doing this behind our
1463 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1466 struct vcache *tvc = VTOAFS(dentry->d_inode);
1467 struct dentry *__dp = NULL;
1468 char *__name = NULL;
1471 if (afs_linux_nfsfs_renamed(dentry))
1479 osi_FreeSmallSpace(__name);
1480 __name = afs_newname();
1483 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1486 osi_FreeSmallSpace(__name);
1489 } while (__dp->d_inode != NULL);
1492 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1493 VTOAFS(dir), (char *)__dp->d_name.name,
1496 tvc->mvid = (void *) __name;
1499 crfree(tvc->uncred);
1501 tvc->uncred = credp;
1502 tvc->f.states |= CUnlinked;
1503 afs_linux_set_nfsfs_renamed(dentry);
1505 osi_FreeSmallSpace(__name);
1510 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1511 d_move(dentry, __dp);
1520 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1523 cred_t *credp = crref();
1524 const char *name = dp->d_name.name;
1525 struct vcache *tvc = VTOAFS(dp->d_inode);
1527 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1528 && !(tvc->f.states & CUnlinked)) {
1530 code = afs_linux_sillyrename(dip, dp, credp);
1533 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1540 return afs_convert_code(code);
1545 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1548 cred_t *credp = crref();
1550 const char *name = dp->d_name.name;
1552 /* If afs_symlink returned the vnode, we could instantiate the
1553 * dentry. Since it's not, we drop this one and do a new lookup.
1559 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1562 return afs_convert_code(code);
1566 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1567 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1569 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1573 cred_t *credp = crref();
1574 struct vcache *tvcp = NULL;
1576 const char *name = dp->d_name.name;
1579 vattr.va_mask = ATTR_MODE;
1580 vattr.va_mode = mode;
1582 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1585 struct inode *ip = AFSTOV(tvcp);
1587 afs_getattr(tvcp, &vattr, credp);
1588 afs_fill_inode(ip, &vattr);
1590 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1591 dp->d_op = &afs_dentry_operations;
1593 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1594 d_instantiate(dp, ip);
1599 return afs_convert_code(code);
1603 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1606 cred_t *credp = crref();
1607 const char *name = dp->d_name.name;
1609 /* locking kernel conflicts with glock? */
1612 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1615 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1616 * that failed because a directory is not empty. So, we map
1617 * EEXIST to ENOTEMPTY on linux.
1619 if (code == EEXIST) {
1628 return afs_convert_code(code);
1633 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1634 struct inode *newip, struct dentry *newdp)
1637 cred_t *credp = crref();
1638 const char *oldname = olddp->d_name.name;
1639 const char *newname = newdp->d_name.name;
1640 struct dentry *rehash = NULL;
1642 /* Prevent any new references during rename operation. */
1644 if (!d_unhashed(newdp)) {
1649 #if defined(D_COUNT_INT)
1650 spin_lock(&olddp->d_lock);
1651 if (olddp->d_count > 1) {
1652 spin_unlock(&olddp->d_lock);
1653 shrink_dcache_parent(olddp);
1655 spin_unlock(&olddp->d_lock);
1657 if (atomic_read(&olddp->d_count) > 1)
1658 shrink_dcache_parent(olddp);
1662 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1666 olddp->d_time = 0; /* force to revalidate */
1672 return afs_convert_code(code);
1676 /* afs_linux_ireadlink
1677 * Internal readlink which can return link contents to user or kernel space.
1678 * Note that the buffer is NOT supposed to be null-terminated.
1681 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1684 cred_t *credp = crref();
1688 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1689 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1693 return maxlen - tuio.uio_resid;
1695 return afs_convert_code(code);
1698 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1699 /* afs_linux_readlink
1700 * Fill target (which is in user space) with contents of symlink.
1703 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1706 struct inode *ip = dp->d_inode;
1709 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1715 /* afs_linux_follow_link
1716 * a file system dependent link following routine.
1718 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1723 name = kmalloc(PATH_MAX, GFP_NOFS);
1729 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1737 nd_set_link(nd, name);
1742 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1744 char *name = nd_get_link(nd);
1746 if (name && !IS_ERR(name))
1750 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1752 /* Populate a page by filling it from the cache file pointed at by cachefp
1753 * (which contains indicated chunk)
1754 * If task is NULL, the page copy occurs syncronously, and the routine
1755 * returns with page still locked. If task is non-NULL, then page copies
1756 * may occur in the background, and the page will be unlocked when it is
1760 afs_linux_read_cache(struct file *cachefp, struct page *page,
1761 int chunk, struct pagevec *lrupv,
1762 struct afs_pagecopy_task *task) {
1763 loff_t offset = page_offset(page);
1764 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1765 struct page *newpage, *cachepage;
1766 struct address_space *cachemapping;
1770 cachemapping = cacheinode->i_mapping;
1774 /* If we're trying to read a page that's past the end of the disk
1775 * cache file, then just return a zeroed page */
1776 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1777 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1778 SetPageUptodate(page);
1784 /* From our offset, we now need to work out which page in the disk
1785 * file it corresponds to. This will be fun ... */
1786 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1788 while (cachepage == NULL) {
1789 cachepage = find_get_page(cachemapping, pageindex);
1792 newpage = page_cache_alloc_cold(cachemapping);
1798 code = add_to_page_cache(newpage, cachemapping,
1799 pageindex, GFP_KERNEL);
1801 cachepage = newpage;
1804 page_cache_get(cachepage);
1805 if (!pagevec_add(lrupv, cachepage))
1806 __pagevec_lru_add_file(lrupv);
1809 page_cache_release(newpage);
1811 if (code != -EEXIST)
1815 lock_page(cachepage);
1819 if (!PageUptodate(cachepage)) {
1820 ClearPageError(cachepage);
1821 code = cachemapping->a_ops->readpage(NULL, cachepage);
1822 if (!code && !task) {
1823 wait_on_page_locked(cachepage);
1826 unlock_page(cachepage);
1830 if (PageUptodate(cachepage)) {
1831 copy_highpage(page, cachepage);
1832 flush_dcache_page(page);
1833 SetPageUptodate(page);
1838 afs_pagecopy_queue_page(task, cachepage, page);
1850 page_cache_release(cachepage);
1856 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1858 loff_t offset = page_offset(pp);
1859 struct inode *ip = FILE_INODE(fp);
1860 struct vcache *avc = VTOAFS(ip);
1862 struct file *cacheFp = NULL;
1865 struct pagevec lrupv;
1867 /* Not a UFS cache, don't do anything */
1868 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1871 /* Can't do anything if the vcache isn't statd , or if the read
1872 * crosses a chunk boundary.
1874 if (!(avc->f.states & CStatd) ||
1875 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1879 ObtainWriteLock(&avc->lock, 911);
1881 /* XXX - See if hinting actually makes things faster !!! */
1883 /* See if we have a suitable entry already cached */
1887 /* We need to lock xdcache, then dcache, to handle situations where
1888 * the hint is on the free list. However, we can't safely do this
1889 * according to the locking hierarchy. So, use a non blocking lock.
1891 ObtainReadLock(&afs_xdcache);
1892 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1894 if (dcLocked && (tdc->index != NULLIDX)
1895 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1896 && tdc->f.chunk == AFS_CHUNK(offset)
1897 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1898 /* Bonus - the hint was correct */
1901 /* Only destroy the hint if its actually invalid, not if there's
1902 * just been a locking failure */
1904 ReleaseReadLock(&tdc->lock);
1911 ReleaseReadLock(&afs_xdcache);
1914 /* No hint, or hint is no longer valid - see if we can get something
1915 * directly from the dcache
1918 tdc = afs_FindDCache(avc, offset);
1921 ReleaseWriteLock(&avc->lock);
1926 ObtainReadLock(&tdc->lock);
1928 /* Is the dcache we've been given currently up to date */
1929 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1930 (tdc->dflags & DFFetching)) {
1931 ReleaseWriteLock(&avc->lock);
1932 ReleaseReadLock(&tdc->lock);
1937 /* Update our hint for future abuse */
1940 /* Okay, so we've now got a cache file that is up to date */
1942 /* XXX - I suspect we should be locking the inodes before we use them! */
1944 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1945 pagevec_init(&lrupv, 0);
1947 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1949 if (pagevec_count(&lrupv))
1950 __pagevec_lru_add_file(&lrupv);
1952 filp_close(cacheFp, NULL);
1955 ReleaseReadLock(&tdc->lock);
1956 ReleaseWriteLock(&avc->lock);
1963 /* afs_linux_readpage
1965 * This function is split into two, because prepare_write/begin_write
1966 * require a readpage call which doesn't unlock the resulting page upon
1970 afs_linux_fillpage(struct file *fp, struct page *pp)
1975 struct iovec *iovecp;
1976 struct inode *ip = FILE_INODE(fp);
1977 afs_int32 cnt = page_count(pp);
1978 struct vcache *avc = VTOAFS(ip);
1979 afs_offs_t offset = page_offset(pp);
1983 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1993 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1994 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
1996 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
2001 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2002 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2003 99999); /* not a possible code value */
2005 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
2007 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2008 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2010 AFS_DISCON_UNLOCK();
2013 /* XXX valid for no-cache also? Check last bits of files... :)
2014 * Cognate code goes in afs_NoCacheFetchProc. */
2015 if (auio->uio_resid) /* zero remainder of page */
2016 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
2019 flush_dcache_page(pp);
2020 SetPageUptodate(pp);
2029 return afs_convert_code(code);
2033 afs_linux_prefetch(struct file *fp, struct page *pp)
2036 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2037 afs_offs_t offset = page_offset(pp);
2039 if (AFS_CHUNKOFFSET(offset) == 0) {
2041 struct vrequest treq;
2046 code = afs_InitReq(&treq, credp);
2047 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2048 tdc = afs_FindDCache(avc, offset);
2050 if (!(tdc->mflags & DFNextStarted))
2051 afs_PrefetchChunk(avc, tdc, credp, &treq);
2054 ReleaseWriteLock(&avc->lock);
2059 return afs_convert_code(code);
2064 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2065 struct list_head *page_list, unsigned num_pages)
2070 struct iovec* iovecp;
2071 struct nocache_read_request *ancr;
2073 struct pagevec lrupv;
2077 struct inode *ip = FILE_INODE(fp);
2078 struct vcache *avc = VTOAFS(ip);
2079 afs_int32 base_index = 0;
2080 afs_int32 page_count = 0;
2083 /* background thread must free: iovecp, auio, ancr */
2084 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2086 auio = osi_Alloc(sizeof(struct uio));
2087 auio->uio_iov = iovecp;
2088 auio->uio_iovcnt = num_pages;
2089 auio->uio_flag = UIO_READ;
2090 auio->uio_seg = AFS_UIOSYS;
2091 auio->uio_resid = num_pages * PAGE_SIZE;
2093 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2095 ancr->offset = auio->uio_offset;
2096 ancr->length = auio->uio_resid;
2098 pagevec_init(&lrupv, 0);
2100 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2102 if(list_empty(page_list))
2105 pp = list_entry(page_list->prev, struct page, lru);
2106 /* If we allocate a page and don't remove it from page_list,
2107 * the page cache gets upset. */
2109 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2110 if(pp->index > isize) {
2117 offset = page_offset(pp);
2118 auio->uio_offset = offset;
2119 base_index = pp->index;
2121 iovecp[page_ix].iov_len = PAGE_SIZE;
2122 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2123 if(base_index != pp->index) {
2126 page_cache_release(pp);
2127 iovecp[page_ix].iov_base = (void *) 0;
2129 ancr->length -= PAGE_SIZE;
2136 page_cache_release(pp);
2137 iovecp[page_ix].iov_base = (void *) 0;
2140 if(!PageLocked(pp)) {
2144 /* increment page refcount--our original design assumed
2145 * that locking it would effectively pin it; protect
2146 * ourselves from the possiblity that this assumption is
2147 * is faulty, at low cost (provided we do not fail to
2148 * do the corresponding decref on the other side) */
2151 /* save the page for background map */
2152 iovecp[page_ix].iov_base = (void*) pp;
2154 /* and put it on the LRU cache */
2155 if (!pagevec_add(&lrupv, pp))
2156 __pagevec_lru_add_file(&lrupv);
2160 /* If there were useful pages in the page list, make sure all pages
2161 * are in the LRU cache, then schedule the read */
2163 if (pagevec_count(&lrupv))
2164 __pagevec_lru_add_file(&lrupv);
2166 code = afs_ReadNoCache(avc, ancr, credp);
2169 /* If there is nothing for the background thread to handle,
2170 * it won't be freeing the things that we never gave it */
2171 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2172 osi_Free(auio, sizeof(struct uio));
2173 osi_Free(ancr, sizeof(struct nocache_read_request));
2175 /* we do not flush, release, or unmap pages--that will be
2176 * done for us by the background thread as each page comes in
2177 * from the fileserver */
2178 return afs_convert_code(code);
2183 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2185 cred_t *credp = NULL;
2187 struct iovec *iovecp;
2188 struct nocache_read_request *ancr;
2192 * Special case: if page is at or past end of file, just zero it and set
2195 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2196 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2197 SetPageUptodate(pp);
2204 /* receiver frees */
2205 auio = osi_Alloc(sizeof(struct uio));
2206 iovecp = osi_Alloc(sizeof(struct iovec));
2208 /* address can be NULL, because we overwrite it with 'pp', below */
2209 setup_uio(auio, iovecp, NULL, page_offset(pp),
2210 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2212 /* save the page for background map */
2213 get_page(pp); /* see above */
2214 auio->uio_iov->iov_base = (void*) pp;
2215 /* the background thread will free this */
2216 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2218 ancr->offset = page_offset(pp);
2219 ancr->length = PAGE_SIZE;
2222 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2225 return afs_convert_code(code);
2229 afs_linux_can_bypass(struct inode *ip) {
2230 switch(cache_bypass_strategy) {
2231 case NEVER_BYPASS_CACHE:
2233 case ALWAYS_BYPASS_CACHE:
2235 case LARGE_FILES_BYPASS_CACHE:
2236 if(i_size_read(ip) > cache_bypass_threshold)
2243 /* Check if a file is permitted to bypass the cache by policy, and modify
2244 * the cache bypass state recorded for that file */
2247 afs_linux_bypass_check(struct inode *ip) {
2250 int bypass = afs_linux_can_bypass(ip);
2253 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2261 afs_linux_readpage(struct file *fp, struct page *pp)
2265 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2266 code = afs_linux_bypass_readpage(fp, pp);
2268 code = afs_linux_fillpage(fp, pp);
2270 code = afs_linux_prefetch(fp, pp);
2277 /* Readpages reads a number of pages for a particular file. We use
2278 * this to optimise the reading, by limiting the number of times upon which
2279 * we have to lookup, lock and open vcaches and dcaches
2283 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2284 struct list_head *page_list, unsigned int num_pages)
2286 struct inode *inode = mapping->host;
2287 struct vcache *avc = VTOAFS(inode);
2289 struct file *cacheFp = NULL;
2291 unsigned int page_idx;
2293 struct pagevec lrupv;
2294 struct afs_pagecopy_task *task;
2296 if (afs_linux_bypass_check(inode))
2297 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2299 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2303 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2308 ObtainWriteLock(&avc->lock, 912);
2311 task = afs_pagecopy_init_task();
2314 pagevec_init(&lrupv, 0);
2315 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2316 struct page *page = list_entry(page_list->prev, struct page, lru);
2317 list_del(&page->lru);
2318 offset = page_offset(page);
2320 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2322 ReleaseReadLock(&tdc->lock);
2327 filp_close(cacheFp, NULL);
2332 if ((tdc = afs_FindDCache(avc, offset))) {
2333 ObtainReadLock(&tdc->lock);
2334 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2335 (tdc->dflags & DFFetching)) {
2336 ReleaseReadLock(&tdc->lock);
2343 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2346 if (tdc && !add_to_page_cache(page, mapping, page->index,
2348 page_cache_get(page);
2349 if (!pagevec_add(&lrupv, page))
2350 __pagevec_lru_add_file(&lrupv);
2352 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2354 page_cache_release(page);
2356 if (pagevec_count(&lrupv))
2357 __pagevec_lru_add_file(&lrupv);
2360 filp_close(cacheFp, NULL);
2362 afs_pagecopy_put_task(task);
2366 ReleaseReadLock(&tdc->lock);
2370 ReleaseWriteLock(&avc->lock);
2375 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2378 afs_linux_prepare_writeback(struct vcache *avc) {
2379 if (avc->f.states & CPageWrite) {
2380 return AOP_WRITEPAGE_ACTIVATE;
2382 avc->f.states |= CPageWrite;
2387 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2388 struct vrequest treq;
2391 if (!afs_InitReq(&treq, credp))
2392 code = afs_DoPartialWrite(avc, &treq);
2394 return afs_convert_code(code);
2398 afs_linux_complete_writeback(struct vcache *avc) {
2399 avc->f.states &= ~CPageWrite;
2402 /* Writeback a given page syncronously. Called with no AFS locks held */
2404 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2405 unsigned long offset, unsigned int count,
2408 struct vcache *vcp = VTOAFS(ip);
2416 buffer = kmap(pp) + offset;
2417 base = page_offset(pp) + offset;
2420 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2421 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2422 ICL_TYPE_INT32, 99999);
2424 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2426 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2428 i_size_write(ip, vcp->f.m.Length);
2429 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2431 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
2433 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2434 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2435 ICL_TYPE_INT32, code);
2444 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2445 unsigned long offset, unsigned int count)
2449 struct vcache *vcp = VTOAFS(ip);
2452 /* Catch recursive writeback. This occurs if the kernel decides
2453 * writeback is required whilst we are writing to the cache, or
2454 * flushing to the server. When we're running syncronously (as
2455 * opposed to from writepage) we can't actually do anything about
2456 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2459 ObtainWriteLock(&vcp->lock, 532);
2460 afs_linux_prepare_writeback(vcp);
2461 ReleaseWriteLock(&vcp->lock);
2465 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2468 ObtainWriteLock(&vcp->lock, 533);
2470 code1 = afs_linux_dopartialwrite(vcp, credp);
2471 afs_linux_complete_writeback(vcp);
2472 ReleaseWriteLock(&vcp->lock);
2483 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2484 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2486 afs_linux_writepage(struct page *pp)
2489 struct address_space *mapping = pp->mapping;
2490 struct inode *inode;
2493 unsigned int to = PAGE_CACHE_SIZE;
2498 if (PageReclaim(pp)) {
2499 return AOP_WRITEPAGE_ACTIVATE;
2500 /* XXX - Do we need to redirty the page here? */
2505 inode = mapping->host;
2506 vcp = VTOAFS(inode);
2507 isize = i_size_read(inode);
2509 /* Don't defeat an earlier truncate */
2510 if (page_offset(pp) > isize) {
2511 set_page_writeback(pp);
2517 ObtainWriteLock(&vcp->lock, 537);
2518 code = afs_linux_prepare_writeback(vcp);
2519 if (code == AOP_WRITEPAGE_ACTIVATE) {
2520 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2521 * to return with the page still locked */
2522 ReleaseWriteLock(&vcp->lock);
2527 /* Grab the creds structure currently held in the vnode, and
2528 * get a reference to it, in case it goes away ... */
2534 ReleaseWriteLock(&vcp->lock);
2537 set_page_writeback(pp);
2539 SetPageUptodate(pp);
2541 /* We can unlock the page here, because it's protected by the
2542 * page_writeback flag. This should make us less vulnerable to
2543 * deadlocking in afs_write and afs_DoPartialWrite
2547 /* If this is the final page, then just write the number of bytes that
2548 * are actually in it */
2549 if ((isize - page_offset(pp)) < to )
2550 to = isize - page_offset(pp);
2552 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2555 ObtainWriteLock(&vcp->lock, 538);
2557 /* As much as we might like to ignore a file server error here,
2558 * and just try again when we close(), unfortunately StoreAllSegments
2559 * will invalidate our chunks if the server returns a permanent error,
2560 * so we need to at least try and get that error back to the user
2563 code1 = afs_linux_dopartialwrite(vcp, credp);
2565 afs_linux_complete_writeback(vcp);
2566 ReleaseWriteLock(&vcp->lock);
2571 end_page_writeback(pp);
2572 page_cache_release(pp);
2583 /* afs_linux_permission
2584 * Check access rights - returns error if can't check or permission denied.
2587 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2588 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2589 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2590 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2592 afs_linux_permission(struct inode *ip, int mode)
2599 /* Check for RCU path walking */
2600 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2601 if (flags & IPERM_FLAG_RCU)
2603 #elif defined(MAY_NOT_BLOCK)
2604 if (mode & MAY_NOT_BLOCK)
2610 if (mode & MAY_EXEC)
2612 if (mode & MAY_READ)
2614 if (mode & MAY_WRITE)
2616 code = afs_access(VTOAFS(ip), tmp, credp);
2620 return afs_convert_code(code);
2624 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2628 struct inode *inode = FILE_INODE(file);
2629 loff_t pagebase = page_offset(page);
2631 if (i_size_read(inode) < (pagebase + offset))
2632 i_size_write(inode, pagebase + offset);
2634 if (PageChecked(page)) {
2635 SetPageUptodate(page);
2636 ClearPageChecked(page);
2639 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2645 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2649 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2650 * prepare_write. Essentially, if the page exists within the file,
2651 * and is not being fully written, then we should populate it.
2654 if (!PageUptodate(page)) {
2655 loff_t pagebase = page_offset(page);
2656 loff_t isize = i_size_read(page->mapping->host);
2658 /* Is the location we are writing to beyond the end of the file? */
2659 if (pagebase >= isize ||
2660 ((from == 0) && (pagebase + to) >= isize)) {
2661 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2662 SetPageChecked(page);
2663 /* Are we we writing a full page */
2664 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2665 SetPageChecked(page);
2666 /* Is the page readable, if it's wronly, we don't care, because we're
2667 * not actually going to read from it ... */
2668 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2669 /* We don't care if fillpage fails, because if it does the page
2670 * won't be marked as up to date
2672 afs_linux_fillpage(file, page);
2678 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2680 afs_linux_write_end(struct file *file, struct address_space *mapping,
2681 loff_t pos, unsigned len, unsigned copied,
2682 struct page *page, void *fsdata)
2685 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2687 code = afs_linux_commit_write(file, page, from, from + len);
2690 page_cache_release(page);
2695 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2696 loff_t pos, unsigned len, unsigned flags,
2697 struct page **pagep, void **fsdata)
2700 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2701 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2704 page = grab_cache_page_write_begin(mapping, index, flags);
2707 code = afs_linux_prepare_write(file, page, from, from + len);
2710 page_cache_release(page);
2717 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2719 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2721 struct dentry **dpp;
2722 struct dentry *target;
2724 target = canonical_dentry(dentry->d_inode);
2726 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2727 dpp = &nd->path.dentry;
2737 *dpp = dget(dentry);
2742 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2745 static struct inode_operations afs_file_iops = {
2746 .permission = afs_linux_permission,
2747 .getattr = afs_linux_getattr,
2748 .setattr = afs_notify_change,
2751 static struct address_space_operations afs_file_aops = {
2752 .readpage = afs_linux_readpage,
2753 .readpages = afs_linux_readpages,
2754 .writepage = afs_linux_writepage,
2755 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2756 .write_begin = afs_linux_write_begin,
2757 .write_end = afs_linux_write_end,
2759 .commit_write = afs_linux_commit_write,
2760 .prepare_write = afs_linux_prepare_write,
2765 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2766 * by what sort of operation is allowed.....
2769 static struct inode_operations afs_dir_iops = {
2770 .setattr = afs_notify_change,
2771 .create = afs_linux_create,
2772 .lookup = afs_linux_lookup,
2773 .link = afs_linux_link,
2774 .unlink = afs_linux_unlink,
2775 .symlink = afs_linux_symlink,
2776 .mkdir = afs_linux_mkdir,
2777 .rmdir = afs_linux_rmdir,
2778 .rename = afs_linux_rename,
2779 .getattr = afs_linux_getattr,
2780 .permission = afs_linux_permission,
2781 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2782 .follow_link = afs_linux_dir_follow_link,
2786 /* We really need a separate symlink set of ops, since do_follow_link()
2787 * determines if it _is_ a link by checking if the follow_link op is set.
2789 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2791 afs_symlink_filler(struct file *file, struct page *page)
2793 struct inode *ip = (struct inode *)page->mapping->host;
2794 char *p = (char *)kmap(page);
2798 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2803 p[code] = '\0'; /* null terminate? */
2805 SetPageUptodate(page);
2817 static struct address_space_operations afs_symlink_aops = {
2818 .readpage = afs_symlink_filler
2820 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2822 static struct inode_operations afs_symlink_iops = {
2823 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2824 .readlink = page_readlink,
2825 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2826 .follow_link = page_follow_link,
2828 .follow_link = page_follow_link_light,
2829 .put_link = page_put_link,
2831 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2832 .readlink = afs_linux_readlink,
2833 .follow_link = afs_linux_follow_link,
2834 .put_link = afs_linux_put_link,
2835 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2836 .setattr = afs_notify_change,
2840 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2844 vattr2inode(ip, vattr);
2846 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2847 /* Reset ops if symlink or directory. */
2848 if (S_ISREG(ip->i_mode)) {
2849 ip->i_op = &afs_file_iops;
2850 ip->i_fop = &afs_file_fops;
2851 ip->i_data.a_ops = &afs_file_aops;
2853 } else if (S_ISDIR(ip->i_mode)) {
2854 ip->i_op = &afs_dir_iops;
2855 ip->i_fop = &afs_dir_fops;
2857 } else if (S_ISLNK(ip->i_mode)) {
2858 ip->i_op = &afs_symlink_iops;
2859 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2860 ip->i_data.a_ops = &afs_symlink_aops;
2861 ip->i_mapping = &ip->i_data;