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>
35 #include <linux/aio.h>
37 #include "afs/afs_bypasscache.h"
39 #include "osi_compat.h"
40 #include "osi_pagecopy.h"
42 #ifndef HAVE_LINUX_PAGEVEC_LRU_ADD_FILE
43 #define __pagevec_lru_add_file __pagevec_lru_add
47 #define MAX_ERRNO 1000L
50 extern struct backing_dev_info *afs_backing_dev_info;
52 extern struct vcache *afs_globalVp;
54 /* This function converts a positive error code from AFS into a negative
55 * code suitable for passing into the Linux VFS layer. It checks that the
56 * error code is within the permissable bounds for the ERR_PTR mechanism.
58 * _All_ error codes which come from the AFS layer should be passed through
59 * this function before being returned to the kernel.
63 afs_convert_code(int code) {
64 if ((code >= 0) && (code <= MAX_ERRNO))
70 /* Linux doesn't require a credp for many functions, and crref is an expensive
71 * operation. This helper function avoids obtaining it for VerifyVCache calls
75 afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
80 if (avc->f.states & CStatd) {
88 code = afs_InitReq(&treq, credp);
90 code = afs_VerifyVCache2(avc, &treq);
97 return afs_convert_code(code);
100 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
101 # ifdef LINUX_HAS_NONVECTOR_AIO
103 afs_linux_aio_read(struct kiocb *iocb, char __user *buf, size_t bufsize,
107 afs_linux_aio_read(struct kiocb *iocb, const struct iovec *buf,
108 unsigned long bufsize, loff_t pos)
111 struct file *fp = iocb->ki_filp;
113 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
116 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
117 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
118 (afs_int32)bufsize, ICL_TYPE_INT32, 99999);
119 code = afs_linux_VerifyVCache(vcp, NULL);
122 /* Linux's FlushPages implementation doesn't ever use credp,
123 * so we optimise by not using it */
124 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
126 code = generic_file_aio_read(iocb, buf, bufsize, pos);
130 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
131 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
132 (afs_int32)bufsize, ICL_TYPE_INT32, code);
138 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
141 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
144 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
145 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
147 code = afs_linux_VerifyVCache(vcp, NULL);
150 /* Linux's FlushPages implementation doesn't ever use credp,
151 * so we optimise by not using it */
152 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
154 code = do_sync_read(fp, buf, count, offp);
158 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
159 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
167 /* Now we have integrated VM for writes as well as reads. the generic write operations
168 * also take care of re-positioning the pointer if file is open in append
169 * mode. Call fake open/close to ensure we do writes of core dumps.
171 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
172 # ifdef LINUX_HAS_NONVECTOR_AIO
174 afs_linux_aio_write(struct kiocb *iocb, const char __user *buf, size_t bufsize,
178 afs_linux_aio_write(struct kiocb *iocb, const struct iovec *buf,
179 unsigned long bufsize, loff_t pos)
183 struct vcache *vcp = VTOAFS(iocb->ki_filp->f_dentry->d_inode);
188 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
189 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
190 (afs_int32)bufsize, ICL_TYPE_INT32,
191 (iocb->ki_filp->f_flags & O_APPEND) ? 99998 : 99999);
193 code = afs_linux_VerifyVCache(vcp, &credp);
195 ObtainWriteLock(&vcp->lock, 529);
197 ReleaseWriteLock(&vcp->lock);
200 code = generic_file_aio_write(iocb, buf, bufsize, pos);
204 ObtainWriteLock(&vcp->lock, 530);
206 if (vcp->execsOrWriters == 1 && !credp)
209 afs_FakeClose(vcp, credp);
210 ReleaseWriteLock(&vcp->lock);
212 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
213 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32,
214 (afs_int32)bufsize, ICL_TYPE_INT32, code);
223 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
226 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
231 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
232 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
233 (fp->f_flags & O_APPEND) ? 99998 : 99999);
235 code = afs_linux_VerifyVCache(vcp, &credp);
237 ObtainWriteLock(&vcp->lock, 529);
239 ReleaseWriteLock(&vcp->lock);
242 code = do_sync_write(fp, buf, count, offp);
246 ObtainWriteLock(&vcp->lock, 530);
248 if (vcp->execsOrWriters == 1 && !credp)
251 afs_FakeClose(vcp, credp);
252 ReleaseWriteLock(&vcp->lock);
254 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
255 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
265 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
267 /* This is a complete rewrite of afs_readdir, since we can make use of
268 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
269 * handling and use of bulkstats will need to be reflected here as well.
272 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
274 struct vcache *avc = VTOAFS(FILE_INODE(fp));
275 struct vrequest treq;
281 struct DirBuffer entry;
284 afs_size_t origOffset, tlen;
285 cred_t *credp = crref();
286 struct afs_fakestat_state fakestat;
289 AFS_STATCNT(afs_readdir);
291 code = afs_convert_code(afs_InitReq(&treq, credp));
296 afs_InitFakeStat(&fakestat);
297 code = afs_convert_code(afs_EvalFakeStat(&avc, &fakestat, &treq));
301 /* update the cache entry */
303 code = afs_convert_code(afs_VerifyVCache2(avc, &treq));
307 /* get a reference to the entire directory */
308 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
314 ObtainWriteLock(&avc->lock, 811);
315 ObtainReadLock(&tdc->lock);
317 * Make sure that the data in the cache is current. There are two
318 * cases we need to worry about:
319 * 1. The cache data is being fetched by another process.
320 * 2. The cache data is no longer valid
322 while ((avc->f.states & CStatd)
323 && (tdc->dflags & DFFetching)
324 && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
325 ReleaseReadLock(&tdc->lock);
326 ReleaseWriteLock(&avc->lock);
327 afs_osi_Sleep(&tdc->validPos);
328 ObtainWriteLock(&avc->lock, 812);
329 ObtainReadLock(&tdc->lock);
331 if (!(avc->f.states & CStatd)
332 || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
333 ReleaseReadLock(&tdc->lock);
334 ReleaseWriteLock(&avc->lock);
339 /* Set the readdir-in-progress flag, and downgrade the lock
340 * to shared so others will be able to acquire a read lock.
342 avc->f.states |= CReadDir;
343 avc->dcreaddir = tdc;
344 avc->readdir_pid = MyPidxx2Pid(MyPidxx);
345 ConvertWToSLock(&avc->lock);
347 /* Fill in until we get an error or we're done. This implementation
348 * takes an offset in units of blobs, rather than bytes.
351 offset = (int) fp->f_pos;
353 dirpos = BlobScan(tdc, offset);
357 code = afs_dir_GetVerifiedBlob(tdc, dirpos, &entry);
359 afs_warn("Corrupt directory (inode %lx, dirpos %d)",
360 (unsigned long)&tdc->f.inode, dirpos);
361 ReleaseSharedLock(&avc->lock);
367 de = (struct DirEntry *)entry.data;
368 ino = afs_calc_inum (avc->f.fid.Cell, avc->f.fid.Fid.Volume,
369 ntohl(de->fid.vnode));
370 len = strlen(de->name);
372 /* filldir returns -EINVAL when the buffer is full. */
374 unsigned int type = DT_UNKNOWN;
375 struct VenusFid afid;
378 afid.Cell = avc->f.fid.Cell;
379 afid.Fid.Volume = avc->f.fid.Fid.Volume;
380 afid.Fid.Vnode = ntohl(de->fid.vnode);
381 afid.Fid.Unique = ntohl(de->fid.vunique);
382 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
384 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
387 } else if (((tvc->f.states) & (CStatd | CTruth))) {
388 /* CTruth will be set if the object has
393 else if (vtype == VREG)
395 /* Don't do this until we're sure it can't be a mtpt */
396 /* else if (vtype == VLNK)
398 /* what other types does AFS support? */
400 /* clean up from afs_FindVCache */
404 * If this is NFS readdirplus, then the filler is going to
405 * call getattr on this inode, which will deadlock if we're
409 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
415 offset = dirpos + 1 + ((len + 16) >> 5);
417 /* If filldir didn't fill in the last one this is still pointing to that
420 fp->f_pos = (loff_t) offset;
422 ReleaseReadLock(&tdc->lock);
424 UpgradeSToWLock(&avc->lock, 813);
425 avc->f.states &= ~CReadDir;
427 avc->readdir_pid = 0;
428 ReleaseSharedLock(&avc->lock);
432 afs_PutFakeStat(&fakestat);
439 /* in afs_pioctl.c */
440 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
443 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
444 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
446 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
453 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
455 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
459 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
460 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
461 vmap->vm_end - vmap->vm_start);
463 /* get a validated vcache entry */
464 code = afs_linux_VerifyVCache(vcp, NULL);
467 /* Linux's Flushpage implementation doesn't use credp, so optimise
468 * our code to not need to crref() it */
469 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
471 code = generic_file_mmap(fp, vmap);
474 vcp->f.states |= CMAPPED;
482 afs_linux_open(struct inode *ip, struct file *fp)
484 struct vcache *vcp = VTOAFS(ip);
485 cred_t *credp = crref();
489 code = afs_open(&vcp, fp->f_flags, credp);
493 return afs_convert_code(code);
497 afs_linux_release(struct inode *ip, struct file *fp)
499 struct vcache *vcp = VTOAFS(ip);
500 cred_t *credp = crref();
504 code = afs_close(vcp, fp->f_flags, credp);
505 ObtainWriteLock(&vcp->lock, 807);
510 ReleaseWriteLock(&vcp->lock);
514 return afs_convert_code(code);
518 #if defined(FOP_FSYNC_TAKES_DENTRY)
519 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
520 #elif defined(FOP_FSYNC_TAKES_RANGE)
521 afs_linux_fsync(struct file *fp, loff_t start, loff_t end, int datasync)
523 afs_linux_fsync(struct file *fp, int datasync)
527 struct inode *ip = FILE_INODE(fp);
528 cred_t *credp = crref();
530 #if defined(FOP_FSYNC_TAKES_RANGE)
531 mutex_lock(&ip->i_mutex);
534 code = afs_fsync(VTOAFS(ip), credp);
536 #if defined(FOP_FSYNC_TAKES_RANGE)
537 mutex_unlock(&ip->i_mutex);
540 return afs_convert_code(code);
546 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
549 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
550 cred_t *credp = crref();
551 struct AFS_FLOCK flock;
553 /* Convert to a lock format afs_lockctl understands. */
554 memset(&flock, 0, sizeof(flock));
555 flock.l_type = flp->fl_type;
556 flock.l_pid = flp->fl_pid;
558 flock.l_start = flp->fl_start;
559 if (flp->fl_end == OFFSET_MAX)
560 flock.l_len = 0; /* Lock to end of file */
562 flock.l_len = flp->fl_end - flp->fl_start + 1;
564 /* Safe because there are no large files, yet */
565 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
566 if (cmd == F_GETLK64)
568 else if (cmd == F_SETLK64)
570 else if (cmd == F_SETLKW64)
572 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
575 if ((vcp->f.states & CRO)) {
576 if (flp->fl_type == F_WRLCK) {
585 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
588 if ((code == 0 || flp->fl_type == F_UNLCK) &&
589 (cmd == F_SETLK || cmd == F_SETLKW)) {
590 code = afs_posix_lock_file(fp, flp);
591 if (code && flp->fl_type != F_UNLCK) {
592 struct AFS_FLOCK flock2;
594 flock2.l_type = F_UNLCK;
596 afs_lockctl(vcp, &flock2, F_SETLK, credp);
600 /* If lockctl says there are no conflicting locks, then also check with the
601 * kernel, as lockctl knows nothing about byte range locks
603 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
604 afs_posix_test_lock(fp, flp);
605 /* If we found a lock in the kernel's structure, return it */
606 if (flp->fl_type != F_UNLCK) {
612 /* Convert flock back to Linux's file_lock */
613 flp->fl_type = flock.l_type;
614 flp->fl_pid = flock.l_pid;
615 flp->fl_start = flock.l_start;
616 if (flock.l_len == 0)
617 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
619 flp->fl_end = flock.l_start + flock.l_len - 1;
625 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
627 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
629 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
630 cred_t *credp = crref();
631 struct AFS_FLOCK flock;
632 /* Convert to a lock format afs_lockctl understands. */
633 memset(&flock, 0, sizeof(flock));
634 flock.l_type = flp->fl_type;
635 flock.l_pid = flp->fl_pid;
640 /* Safe because there are no large files, yet */
641 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
642 if (cmd == F_GETLK64)
644 else if (cmd == F_SETLK64)
646 else if (cmd == F_SETLKW64)
648 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
651 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
654 if ((code == 0 || flp->fl_type == F_UNLCK) &&
655 (cmd == F_SETLK || cmd == F_SETLKW)) {
656 flp->fl_flags &=~ FL_SLEEP;
657 code = flock_lock_file_wait(fp, flp);
658 if (code && flp->fl_type != F_UNLCK) {
659 struct AFS_FLOCK flock2;
661 flock2.l_type = F_UNLCK;
663 afs_lockctl(vcp, &flock2, F_SETLK, credp);
667 /* Convert flock back to Linux's file_lock */
668 flp->fl_type = flock.l_type;
669 flp->fl_pid = flock.l_pid;
677 * essentially the same as afs_fsync() but we need to get the return
678 * code for the sys_close() here, not afs_linux_release(), so call
679 * afs_StoreAllSegments() with AFS_LASTSTORE
682 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
683 afs_linux_flush(struct file *fp, fl_owner_t id)
685 afs_linux_flush(struct file *fp)
688 struct vrequest treq;
696 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
704 vcp = VTOAFS(FILE_INODE(fp));
706 code = afs_InitReq(&treq, credp);
709 /* If caching is bypassed for this file, or globally, just return 0 */
710 if (cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
713 ObtainReadLock(&vcp->lock);
714 if (vcp->cachingStates & FCSBypass)
716 ReleaseReadLock(&vcp->lock);
719 /* future proof: don't rely on 0 return from afs_InitReq */
724 ObtainSharedLock(&vcp->lock, 535);
725 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
726 UpgradeSToWLock(&vcp->lock, 536);
727 if (!AFS_IS_DISCONNECTED) {
728 code = afs_StoreAllSegments(vcp,
730 AFS_SYNC | AFS_LASTSTORE);
732 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
734 ConvertWToSLock(&vcp->lock);
736 code = afs_CheckCode(code, &treq, 54);
737 ReleaseSharedLock(&vcp->lock);
744 return afs_convert_code(code);
747 struct file_operations afs_dir_fops = {
748 .read = generic_read_dir,
749 .readdir = afs_linux_readdir,
750 #ifdef HAVE_UNLOCKED_IOCTL
751 .unlocked_ioctl = afs_unlocked_xioctl,
755 #ifdef HAVE_COMPAT_IOCTL
756 .compat_ioctl = afs_unlocked_xioctl,
758 .open = afs_linux_open,
759 .release = afs_linux_release,
760 .llseek = default_llseek,
761 #ifdef HAVE_LINUX_NOOP_FSYNC
764 .fsync = simple_sync_file,
768 struct file_operations afs_file_fops = {
769 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
770 .aio_read = afs_linux_aio_read,
771 .aio_write = afs_linux_aio_write,
773 .read = afs_linux_read,
774 .write = afs_linux_write,
776 #ifdef HAVE_UNLOCKED_IOCTL
777 .unlocked_ioctl = afs_unlocked_xioctl,
781 #ifdef HAVE_COMPAT_IOCTL
782 .compat_ioctl = afs_unlocked_xioctl,
784 .mmap = afs_linux_mmap,
785 .open = afs_linux_open,
786 .flush = afs_linux_flush,
787 #if defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
788 .sendfile = generic_file_sendfile,
790 #if defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
791 .splice_write = generic_file_splice_write,
792 .splice_read = generic_file_splice_read,
794 .release = afs_linux_release,
795 .fsync = afs_linux_fsync,
796 .lock = afs_linux_lock,
797 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
798 .flock = afs_linux_flock,
800 .llseek = default_llseek,
803 static struct dentry *
804 canonical_dentry(struct inode *ip)
806 struct vcache *vcp = VTOAFS(ip);
807 struct dentry *first = NULL, *ret = NULL, *cur;
808 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
809 struct hlist_node *p;
813 * if vcp->target_link is set, and can be found in ip->i_dentry, use that.
814 * otherwise, use the first dentry in ip->i_dentry.
815 * if ip->i_dentry is empty, use the 'dentry' argument we were given.
817 /* note that vcp->target_link specifies which dentry to use, but we have
818 * no reference held on that dentry. so, we cannot use or dereference
819 * vcp->target_link itself, since it may have been freed. instead, we only
820 * use it to compare to pointers in the ip->i_dentry list. */
824 # ifdef HAVE_DCACHE_LOCK
825 spin_lock(&dcache_lock);
827 spin_lock(&ip->i_lock);
830 #if defined(D_ALIAS_IS_HLIST)
831 # if defined(HLIST_ITERATOR_NO_NODE)
832 hlist_for_each_entry(cur, &ip->i_dentry, d_alias) {
834 hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
837 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
840 if (!vcp->target_link || cur == vcp->target_link) {
853 vcp->target_link = ret;
855 # ifdef HAVE_DCACHE_LOCK
859 spin_unlock(&dcache_lock);
864 spin_unlock(&ip->i_lock);
870 /**********************************************************************
871 * AFS Linux dentry operations
872 **********************************************************************/
874 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
875 * that has its mvid (parent dir's fid) pointer set to the wrong directory
876 * due to being mounted in multiple points at once. fix_bad_parent()
877 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
878 * dotdotfid and mtpoint fid members.
880 * dp - dentry to be checked.
881 * credp - credentials
882 * vcp, pvc - item's and parent's vcache pointer
886 * This dentry's vcache's mvid will be set to the correct parent directory's
888 * This root vnode's volume will have its dotdotfid and mtpoint fids set
889 * to the correct parent and mountpoint fids.
893 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
895 struct vcache *avc = NULL;
897 /* force a lookup, so vcp->mvid is fixed up */
898 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
899 if (!avc || vcp != avc) { /* bad, very bad.. */
900 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
901 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
902 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
903 ICL_TYPE_POINTER, dp);
906 AFS_RELE(AFSTOV(avc));
911 /* afs_linux_revalidate
912 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
915 afs_linux_revalidate(struct dentry *dp)
918 struct vcache *vcp = VTOAFS(dp->d_inode);
922 if (afs_shuttingdown)
928 /* Make this a fast path (no crref), since it's called so often. */
929 if (vcp->states & CStatd) {
930 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
932 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
933 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
936 fix_bad_parent(dp); /* check and correct mvid */
945 /* This avoids the crref when we don't have to do it. Watch for
946 * changes in afs_getattr that don't get replicated here!
948 if (vcp->f.states & CStatd &&
949 (!afs_fakestat_enable || vcp->mvstat != 1) &&
951 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
952 code = afs_CopyOutAttrs(vcp, &vattr);
955 code = afs_getattr(vcp, &vattr, credp);
960 afs_fill_inode(AFSTOV(vcp), &vattr);
964 return afs_convert_code(code);
968 * Set iattr data into vattr. Assume vattr cleared before call.
971 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
973 vattrp->va_mask = iattrp->ia_valid;
974 if (iattrp->ia_valid & ATTR_MODE)
975 vattrp->va_mode = iattrp->ia_mode;
976 if (iattrp->ia_valid & ATTR_UID)
977 vattrp->va_uid = iattrp->ia_uid;
978 if (iattrp->ia_valid & ATTR_GID)
979 vattrp->va_gid = iattrp->ia_gid;
980 if (iattrp->ia_valid & ATTR_SIZE)
981 vattrp->va_size = iattrp->ia_size;
982 if (iattrp->ia_valid & ATTR_ATIME) {
983 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
984 vattrp->va_atime.tv_usec = 0;
986 if (iattrp->ia_valid & ATTR_MTIME) {
987 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
988 vattrp->va_mtime.tv_usec = 0;
990 if (iattrp->ia_valid & ATTR_CTIME) {
991 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
992 vattrp->va_ctime.tv_usec = 0;
997 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
1000 vattr2inode(struct inode *ip, struct vattr *vp)
1002 ip->i_ino = vp->va_nodeid;
1003 #ifdef HAVE_LINUX_SET_NLINK
1004 set_nlink(ip, vp->va_nlink);
1006 ip->i_nlink = vp->va_nlink;
1008 ip->i_blocks = vp->va_blocks;
1009 #ifdef STRUCT_INODE_HAS_I_BLKBITS
1010 ip->i_blkbits = AFS_BLKBITS;
1012 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
1013 ip->i_blksize = vp->va_blocksize;
1015 ip->i_rdev = vp->va_rdev;
1016 ip->i_mode = vp->va_mode;
1017 ip->i_uid = vp->va_uid;
1018 ip->i_gid = vp->va_gid;
1019 i_size_write(ip, vp->va_size);
1020 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
1021 ip->i_atime.tv_nsec = 0;
1022 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
1023 /* Set the mtime nanoseconds to the sysname generation number.
1024 * This convinces NFS clients that all directories have changed
1025 * any time the sysname list changes.
1027 ip->i_mtime.tv_nsec = afs_sysnamegen;
1028 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
1029 ip->i_ctime.tv_nsec = 0;
1032 /* afs_notify_change
1033 * Linux version of setattr call. What to change is in the iattr struct.
1034 * We need to set bits in both the Linux inode as well as the vcache.
1037 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1040 cred_t *credp = crref();
1041 struct inode *ip = dp->d_inode;
1045 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1048 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1050 afs_getattr(VTOAFS(ip), &vattr, credp);
1051 vattr2inode(ip, &vattr);
1055 return afs_convert_code(code);
1059 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1061 int err = afs_linux_revalidate(dentry);
1063 generic_fillattr(dentry->d_inode, stat);
1068 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1069 * In kernels 2.2.10 and above, we are passed an additional flags var which
1070 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1071 * we are advised to follow the entry if it is a link or to make sure that
1072 * it is a directory. But since the kernel itself checks these possibilities
1073 * later on, we shouldn't have to do it until later. Perhaps in the future..
1075 * The code here assumes that on entry the global lock is not held
1078 #if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1079 afs_linux_dentry_revalidate(struct dentry *dp, unsigned int flags)
1080 #elif defined(DOP_REVALIDATE_TAKES_NAMEIDATA)
1081 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1083 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1087 cred_t *credp = NULL;
1088 struct vcache *vcp, *pvcp, *tvc = NULL;
1089 struct dentry *parent;
1091 struct afs_fakestat_state fakestate;
1095 /* We don't support RCU path walking */
1096 # if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1097 if (flags & LOOKUP_RCU)
1099 if (nd->flags & LOOKUP_RCU)
1104 afs_InitFakeStat(&fakestate);
1107 vcp = VTOAFS(dp->d_inode);
1109 if (vcp == afs_globalVp)
1112 parent = dget_parent(dp);
1113 pvcp = VTOAFS(parent->d_inode);
1115 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1121 if (locked && vcp->mvstat == 1) { /* mount point */
1122 if (vcp->mvid && (vcp->f.states & CMValid)) {
1123 int tryEvalOnly = 0;
1125 struct vrequest treq;
1127 code = afs_InitReq(&treq, credp);
1129 (strcmp(dp->d_name.name, ".directory") == 0)) {
1133 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1135 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1136 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1137 /* a mount point, not yet replaced by its directory */
1143 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1144 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1145 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1150 /* If the last looker changes, we should make sure the current
1151 * looker still has permission to examine this file. This would
1152 * always require a crref() which would be "slow".
1154 if (vcp->last_looker != treq.uid) {
1155 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) {
1160 vcp->last_looker = treq.uid;
1165 /* If the parent's DataVersion has changed or the vnode
1166 * is longer valid, we need to do a full lookup. VerifyVCache
1167 * isn't enough since the vnode may have been renamed.
1170 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1176 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1177 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1178 if (!tvc || tvc != vcp) {
1183 if (afs_getattr(vcp, &vattr, credp)) {
1188 vattr2inode(AFSTOV(vcp), &vattr);
1189 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1192 /* should we always update the attributes at this point? */
1193 /* unlikely--the vcache entry hasn't changed */
1198 /* If this code is ever enabled, we should use dget_parent to handle
1199 * getting the parent, and dput() to dispose of it. See above for an
1201 pvcp = VTOAFS(dp->d_parent->d_inode);
1202 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1206 /* No change in parent's DataVersion so this negative
1207 * lookup is still valid. BUT, if a server is down a
1208 * negative lookup can result so there should be a
1209 * liftime as well. For now, always expire.
1222 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1224 /* we hold the global lock if we evaluated a mount point */
1231 shrink_dcache_parent(dp);
1237 if (have_submounts(dp))
1245 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1247 struct vcache *vcp = VTOAFS(ip);
1250 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1251 (void) afs_InactiveVCache(vcp, NULL);
1254 afs_linux_clear_nfsfs_renamed(dp);
1260 #if defined(DOP_D_DELETE_TAKES_CONST)
1261 afs_dentry_delete(const struct dentry *dp)
1263 afs_dentry_delete(struct dentry *dp)
1266 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1267 return 1; /* bad inode? */
1272 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1273 static struct vfsmount *
1274 afs_dentry_automount(afs_linux_path_t *path)
1276 struct dentry *target;
1278 /* avoid symlink resolution limits when resolving; we cannot contribute to
1279 * an infinite symlink loop */
1280 current->total_link_count--;
1282 target = canonical_dentry(path->dentry->d_inode);
1284 if (target == path->dentry) {
1291 path->dentry = target;
1294 spin_lock(&path->dentry->d_lock);
1295 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1296 spin_unlock(&path->dentry->d_lock);
1301 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1303 struct dentry_operations afs_dentry_operations = {
1304 .d_revalidate = afs_linux_dentry_revalidate,
1305 .d_delete = afs_dentry_delete,
1306 .d_iput = afs_dentry_iput,
1307 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1308 .d_automount = afs_dentry_automount,
1309 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1312 /**********************************************************************
1313 * AFS Linux inode operations
1314 **********************************************************************/
1318 * Merely need to set enough of vattr to get us through the create. Note
1319 * that the higher level code (open_namei) will take care of any tuncation
1320 * explicitly. Exclusive open is also taken care of in open_namei.
1322 * name is in kernel space at this point.
1325 #if defined(IOP_CREATE_TAKES_BOOL)
1326 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1328 #elif defined(IOP_CREATE_TAKES_UMODE_T)
1329 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1330 struct nameidata *nd)
1331 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
1332 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1333 struct nameidata *nd)
1335 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1339 cred_t *credp = crref();
1340 const char *name = dp->d_name.name;
1345 vattr.va_mode = mode;
1346 vattr.va_type = mode & S_IFMT;
1349 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1353 struct inode *ip = AFSTOV(vcp);
1355 afs_getattr(vcp, &vattr, credp);
1356 afs_fill_inode(ip, &vattr);
1357 insert_inode_hash(ip);
1358 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1359 dp->d_op = &afs_dentry_operations;
1361 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1362 d_instantiate(dp, ip);
1367 return afs_convert_code(code);
1370 /* afs_linux_lookup */
1371 static struct dentry *
1372 #if defined(IOP_LOOKUP_TAKES_UNSIGNED)
1373 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1375 #elif defined(IOP_LOOKUP_TAKES_NAMEIDATA)
1376 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1377 struct nameidata *nd)
1379 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1382 cred_t *credp = crref();
1383 struct vcache *vcp = NULL;
1384 const char *comp = dp->d_name.name;
1385 struct inode *ip = NULL;
1386 struct dentry *newdp = NULL;
1390 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1394 struct vcache *parent_vc = VTOAFS(dip);
1396 if (parent_vc == vcp) {
1397 /* This is possible if the parent dir is a mountpoint to a volume,
1398 * and the dir entry we looked up is a mountpoint to the same
1399 * volume. Linux cannot cope with this, so return an error instead
1400 * of risking a deadlock or panic. */
1408 afs_getattr(vcp, &vattr, credp);
1409 afs_fill_inode(ip, &vattr);
1410 if (hlist_unhashed(&ip->i_hash))
1411 insert_inode_hash(ip);
1413 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1414 dp->d_op = &afs_dentry_operations;
1416 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1419 if (ip && S_ISDIR(ip->i_mode)) {
1420 d_prune_aliases(ip);
1422 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1423 ip->i_flags |= S_AUTOMOUNT;
1426 newdp = d_splice_alias(ip, dp);
1431 /* It's ok for the file to not be found. That's noted by the caller by
1432 * seeing that the dp->d_inode field is NULL.
1434 if (!code || code == ENOENT)
1437 return ERR_PTR(afs_convert_code(code));
1441 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1444 cred_t *credp = crref();
1445 const char *name = newdp->d_name.name;
1446 struct inode *oldip = olddp->d_inode;
1448 /* If afs_link returned the vnode, we could instantiate the
1449 * dentry. Since it's not, we drop this one and do a new lookup.
1454 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1458 return afs_convert_code(code);
1461 /* We have to have a Linux specific sillyrename function, because we
1462 * also have to keep the dcache up to date when we're doing a silly
1463 * rename - so we don't want the generic vnodeops doing this behind our
1468 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1471 struct vcache *tvc = VTOAFS(dentry->d_inode);
1472 struct dentry *__dp = NULL;
1473 char *__name = NULL;
1476 if (afs_linux_nfsfs_renamed(dentry))
1484 osi_FreeSmallSpace(__name);
1485 __name = afs_newname();
1488 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1491 osi_FreeSmallSpace(__name);
1494 } while (__dp->d_inode != NULL);
1497 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1498 VTOAFS(dir), (char *)__dp->d_name.name,
1501 tvc->mvid = (void *) __name;
1504 crfree(tvc->uncred);
1506 tvc->uncred = credp;
1507 tvc->f.states |= CUnlinked;
1508 afs_linux_set_nfsfs_renamed(dentry);
1510 osi_FreeSmallSpace(__name);
1515 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1516 d_move(dentry, __dp);
1525 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1528 cred_t *credp = crref();
1529 const char *name = dp->d_name.name;
1530 struct vcache *tvc = VTOAFS(dp->d_inode);
1532 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1533 && !(tvc->f.states & CUnlinked)) {
1535 code = afs_linux_sillyrename(dip, dp, credp);
1538 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1545 return afs_convert_code(code);
1550 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1553 cred_t *credp = crref();
1555 const char *name = dp->d_name.name;
1557 /* If afs_symlink returned the vnode, we could instantiate the
1558 * dentry. Since it's not, we drop this one and do a new lookup.
1564 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1567 return afs_convert_code(code);
1571 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1572 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1574 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1578 cred_t *credp = crref();
1579 struct vcache *tvcp = NULL;
1581 const char *name = dp->d_name.name;
1584 vattr.va_mask = ATTR_MODE;
1585 vattr.va_mode = mode;
1587 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1590 struct inode *ip = AFSTOV(tvcp);
1592 afs_getattr(tvcp, &vattr, credp);
1593 afs_fill_inode(ip, &vattr);
1595 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1596 dp->d_op = &afs_dentry_operations;
1598 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1599 d_instantiate(dp, ip);
1604 return afs_convert_code(code);
1608 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1611 cred_t *credp = crref();
1612 const char *name = dp->d_name.name;
1614 /* locking kernel conflicts with glock? */
1617 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1620 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1621 * that failed because a directory is not empty. So, we map
1622 * EEXIST to ENOTEMPTY on linux.
1624 if (code == EEXIST) {
1633 return afs_convert_code(code);
1638 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1639 struct inode *newip, struct dentry *newdp)
1642 cred_t *credp = crref();
1643 const char *oldname = olddp->d_name.name;
1644 const char *newname = newdp->d_name.name;
1645 struct dentry *rehash = NULL;
1647 /* Prevent any new references during rename operation. */
1649 if (!d_unhashed(newdp)) {
1654 #if defined(D_COUNT_INT)
1655 spin_lock(&olddp->d_lock);
1656 if (olddp->d_count > 1) {
1657 spin_unlock(&olddp->d_lock);
1658 shrink_dcache_parent(olddp);
1660 spin_unlock(&olddp->d_lock);
1662 if (atomic_read(&olddp->d_count) > 1)
1663 shrink_dcache_parent(olddp);
1667 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1671 olddp->d_time = 0; /* force to revalidate */
1677 return afs_convert_code(code);
1681 /* afs_linux_ireadlink
1682 * Internal readlink which can return link contents to user or kernel space.
1683 * Note that the buffer is NOT supposed to be null-terminated.
1686 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1689 cred_t *credp = crref();
1693 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1694 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1698 return maxlen - tuio.uio_resid;
1700 return afs_convert_code(code);
1703 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1704 /* afs_linux_readlink
1705 * Fill target (which is in user space) with contents of symlink.
1708 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1711 struct inode *ip = dp->d_inode;
1714 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1720 /* afs_linux_follow_link
1721 * a file system dependent link following routine.
1723 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1728 name = kmalloc(PATH_MAX, GFP_NOFS);
1734 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1742 nd_set_link(nd, name);
1747 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1749 char *name = nd_get_link(nd);
1751 if (name && !IS_ERR(name))
1755 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1757 /* Populate a page by filling it from the cache file pointed at by cachefp
1758 * (which contains indicated chunk)
1759 * If task is NULL, the page copy occurs syncronously, and the routine
1760 * returns with page still locked. If task is non-NULL, then page copies
1761 * may occur in the background, and the page will be unlocked when it is
1765 afs_linux_read_cache(struct file *cachefp, struct page *page,
1766 int chunk, struct pagevec *lrupv,
1767 struct afs_pagecopy_task *task) {
1768 loff_t offset = page_offset(page);
1769 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1770 struct page *newpage, *cachepage;
1771 struct address_space *cachemapping;
1775 cachemapping = cacheinode->i_mapping;
1779 /* If we're trying to read a page that's past the end of the disk
1780 * cache file, then just return a zeroed page */
1781 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1782 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1783 SetPageUptodate(page);
1789 /* From our offset, we now need to work out which page in the disk
1790 * file it corresponds to. This will be fun ... */
1791 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1793 while (cachepage == NULL) {
1794 cachepage = find_get_page(cachemapping, pageindex);
1797 newpage = page_cache_alloc_cold(cachemapping);
1803 code = add_to_page_cache(newpage, cachemapping,
1804 pageindex, GFP_KERNEL);
1806 cachepage = newpage;
1809 page_cache_get(cachepage);
1810 if (!pagevec_add(lrupv, cachepage))
1811 __pagevec_lru_add_file(lrupv);
1814 page_cache_release(newpage);
1816 if (code != -EEXIST)
1820 lock_page(cachepage);
1824 if (!PageUptodate(cachepage)) {
1825 ClearPageError(cachepage);
1826 code = cachemapping->a_ops->readpage(NULL, cachepage);
1827 if (!code && !task) {
1828 wait_on_page_locked(cachepage);
1831 unlock_page(cachepage);
1835 if (PageUptodate(cachepage)) {
1836 copy_highpage(page, cachepage);
1837 flush_dcache_page(page);
1838 SetPageUptodate(page);
1843 afs_pagecopy_queue_page(task, cachepage, page);
1855 page_cache_release(cachepage);
1861 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1863 loff_t offset = page_offset(pp);
1864 struct inode *ip = FILE_INODE(fp);
1865 struct vcache *avc = VTOAFS(ip);
1867 struct file *cacheFp = NULL;
1870 struct pagevec lrupv;
1872 /* Not a UFS cache, don't do anything */
1873 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1876 /* Can't do anything if the vcache isn't statd , or if the read
1877 * crosses a chunk boundary.
1879 if (!(avc->f.states & CStatd) ||
1880 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1884 ObtainWriteLock(&avc->lock, 911);
1886 /* XXX - See if hinting actually makes things faster !!! */
1888 /* See if we have a suitable entry already cached */
1892 /* We need to lock xdcache, then dcache, to handle situations where
1893 * the hint is on the free list. However, we can't safely do this
1894 * according to the locking hierarchy. So, use a non blocking lock.
1896 ObtainReadLock(&afs_xdcache);
1897 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1899 if (dcLocked && (tdc->index != NULLIDX)
1900 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1901 && tdc->f.chunk == AFS_CHUNK(offset)
1902 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1903 /* Bonus - the hint was correct */
1906 /* Only destroy the hint if its actually invalid, not if there's
1907 * just been a locking failure */
1909 ReleaseReadLock(&tdc->lock);
1916 ReleaseReadLock(&afs_xdcache);
1919 /* No hint, or hint is no longer valid - see if we can get something
1920 * directly from the dcache
1923 tdc = afs_FindDCache(avc, offset);
1926 ReleaseWriteLock(&avc->lock);
1931 ObtainReadLock(&tdc->lock);
1933 /* Is the dcache we've been given currently up to date */
1934 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1935 (tdc->dflags & DFFetching)) {
1936 ReleaseWriteLock(&avc->lock);
1937 ReleaseReadLock(&tdc->lock);
1942 /* Update our hint for future abuse */
1945 /* Okay, so we've now got a cache file that is up to date */
1947 /* XXX - I suspect we should be locking the inodes before we use them! */
1949 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1950 pagevec_init(&lrupv, 0);
1952 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1954 if (pagevec_count(&lrupv))
1955 __pagevec_lru_add_file(&lrupv);
1957 filp_close(cacheFp, NULL);
1960 ReleaseReadLock(&tdc->lock);
1961 ReleaseWriteLock(&avc->lock);
1968 /* afs_linux_readpage
1970 * This function is split into two, because prepare_write/begin_write
1971 * require a readpage call which doesn't unlock the resulting page upon
1975 afs_linux_fillpage(struct file *fp, struct page *pp)
1980 struct iovec *iovecp;
1981 struct inode *ip = FILE_INODE(fp);
1982 afs_int32 cnt = page_count(pp);
1983 struct vcache *avc = VTOAFS(ip);
1984 afs_offs_t offset = page_offset(pp);
1988 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1998 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1999 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
2001 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
2006 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2007 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2008 99999); /* not a possible code value */
2010 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
2012 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2013 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2015 AFS_DISCON_UNLOCK();
2018 /* XXX valid for no-cache also? Check last bits of files... :)
2019 * Cognate code goes in afs_NoCacheFetchProc. */
2020 if (auio->uio_resid) /* zero remainder of page */
2021 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
2024 flush_dcache_page(pp);
2025 SetPageUptodate(pp);
2034 return afs_convert_code(code);
2038 afs_linux_prefetch(struct file *fp, struct page *pp)
2041 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2042 afs_offs_t offset = page_offset(pp);
2044 if (AFS_CHUNKOFFSET(offset) == 0) {
2046 struct vrequest treq;
2051 code = afs_InitReq(&treq, credp);
2052 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2053 tdc = afs_FindDCache(avc, offset);
2055 if (!(tdc->mflags & DFNextStarted))
2056 afs_PrefetchChunk(avc, tdc, credp, &treq);
2059 ReleaseWriteLock(&avc->lock);
2064 return afs_convert_code(code);
2069 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2070 struct list_head *page_list, unsigned num_pages)
2075 struct iovec* iovecp;
2076 struct nocache_read_request *ancr;
2078 struct pagevec lrupv;
2082 struct inode *ip = FILE_INODE(fp);
2083 struct vcache *avc = VTOAFS(ip);
2084 afs_int32 base_index = 0;
2085 afs_int32 page_count = 0;
2088 /* background thread must free: iovecp, auio, ancr */
2089 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2091 auio = osi_Alloc(sizeof(struct uio));
2092 auio->uio_iov = iovecp;
2093 auio->uio_iovcnt = num_pages;
2094 auio->uio_flag = UIO_READ;
2095 auio->uio_seg = AFS_UIOSYS;
2096 auio->uio_resid = num_pages * PAGE_SIZE;
2098 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2100 ancr->offset = auio->uio_offset;
2101 ancr->length = auio->uio_resid;
2103 pagevec_init(&lrupv, 0);
2105 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2107 if(list_empty(page_list))
2110 pp = list_entry(page_list->prev, struct page, lru);
2111 /* If we allocate a page and don't remove it from page_list,
2112 * the page cache gets upset. */
2114 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2115 if(pp->index > isize) {
2122 offset = page_offset(pp);
2123 ancr->offset = auio->uio_offset = offset;
2124 base_index = pp->index;
2126 iovecp[page_ix].iov_len = PAGE_SIZE;
2127 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2128 if(base_index != pp->index) {
2131 page_cache_release(pp);
2132 iovecp[page_ix].iov_base = (void *) 0;
2134 ancr->length -= PAGE_SIZE;
2141 page_cache_release(pp);
2142 iovecp[page_ix].iov_base = (void *) 0;
2145 if(!PageLocked(pp)) {
2149 /* increment page refcount--our original design assumed
2150 * that locking it would effectively pin it; protect
2151 * ourselves from the possiblity that this assumption is
2152 * is faulty, at low cost (provided we do not fail to
2153 * do the corresponding decref on the other side) */
2156 /* save the page for background map */
2157 iovecp[page_ix].iov_base = (void*) pp;
2159 /* and put it on the LRU cache */
2160 if (!pagevec_add(&lrupv, pp))
2161 __pagevec_lru_add_file(&lrupv);
2165 /* If there were useful pages in the page list, make sure all pages
2166 * are in the LRU cache, then schedule the read */
2168 if (pagevec_count(&lrupv))
2169 __pagevec_lru_add_file(&lrupv);
2171 code = afs_ReadNoCache(avc, ancr, credp);
2174 /* If there is nothing for the background thread to handle,
2175 * it won't be freeing the things that we never gave it */
2176 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2177 osi_Free(auio, sizeof(struct uio));
2178 osi_Free(ancr, sizeof(struct nocache_read_request));
2180 /* we do not flush, release, or unmap pages--that will be
2181 * done for us by the background thread as each page comes in
2182 * from the fileserver */
2183 return afs_convert_code(code);
2188 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2190 cred_t *credp = NULL;
2192 struct iovec *iovecp;
2193 struct nocache_read_request *ancr;
2197 * Special case: if page is at or past end of file, just zero it and set
2200 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2201 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2202 SetPageUptodate(pp);
2209 /* receiver frees */
2210 auio = osi_Alloc(sizeof(struct uio));
2211 iovecp = osi_Alloc(sizeof(struct iovec));
2213 /* address can be NULL, because we overwrite it with 'pp', below */
2214 setup_uio(auio, iovecp, NULL, page_offset(pp),
2215 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2217 /* save the page for background map */
2218 get_page(pp); /* see above */
2219 auio->uio_iov->iov_base = (void*) pp;
2220 /* the background thread will free this */
2221 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2223 ancr->offset = page_offset(pp);
2224 ancr->length = PAGE_SIZE;
2227 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2230 return afs_convert_code(code);
2234 afs_linux_can_bypass(struct inode *ip) {
2236 switch(cache_bypass_strategy) {
2237 case NEVER_BYPASS_CACHE:
2239 case ALWAYS_BYPASS_CACHE:
2241 case LARGE_FILES_BYPASS_CACHE:
2242 if (i_size_read(ip) > cache_bypass_threshold)
2249 /* Check if a file is permitted to bypass the cache by policy, and modify
2250 * the cache bypass state recorded for that file */
2253 afs_linux_bypass_check(struct inode *ip) {
2256 int bypass = afs_linux_can_bypass(ip);
2259 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2267 afs_linux_readpage(struct file *fp, struct page *pp)
2271 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2272 code = afs_linux_bypass_readpage(fp, pp);
2274 code = afs_linux_fillpage(fp, pp);
2276 code = afs_linux_prefetch(fp, pp);
2283 /* Readpages reads a number of pages for a particular file. We use
2284 * this to optimise the reading, by limiting the number of times upon which
2285 * we have to lookup, lock and open vcaches and dcaches
2289 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2290 struct list_head *page_list, unsigned int num_pages)
2292 struct inode *inode = mapping->host;
2293 struct vcache *avc = VTOAFS(inode);
2295 struct file *cacheFp = NULL;
2297 unsigned int page_idx;
2299 struct pagevec lrupv;
2300 struct afs_pagecopy_task *task;
2302 if (afs_linux_bypass_check(inode))
2303 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2305 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2309 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2314 ObtainWriteLock(&avc->lock, 912);
2317 task = afs_pagecopy_init_task();
2320 pagevec_init(&lrupv, 0);
2321 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2322 struct page *page = list_entry(page_list->prev, struct page, lru);
2323 list_del(&page->lru);
2324 offset = page_offset(page);
2326 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2328 ReleaseReadLock(&tdc->lock);
2333 filp_close(cacheFp, NULL);
2338 if ((tdc = afs_FindDCache(avc, offset))) {
2339 ObtainReadLock(&tdc->lock);
2340 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2341 (tdc->dflags & DFFetching)) {
2342 ReleaseReadLock(&tdc->lock);
2349 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2352 if (tdc && !add_to_page_cache(page, mapping, page->index,
2354 page_cache_get(page);
2355 if (!pagevec_add(&lrupv, page))
2356 __pagevec_lru_add_file(&lrupv);
2358 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2360 page_cache_release(page);
2362 if (pagevec_count(&lrupv))
2363 __pagevec_lru_add_file(&lrupv);
2366 filp_close(cacheFp, NULL);
2368 afs_pagecopy_put_task(task);
2372 ReleaseReadLock(&tdc->lock);
2376 ReleaseWriteLock(&avc->lock);
2381 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2384 afs_linux_prepare_writeback(struct vcache *avc) {
2385 if (avc->f.states & CPageWrite) {
2386 return AOP_WRITEPAGE_ACTIVATE;
2388 avc->f.states |= CPageWrite;
2393 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2394 struct vrequest treq;
2397 if (!afs_InitReq(&treq, credp))
2398 code = afs_DoPartialWrite(avc, &treq);
2400 return afs_convert_code(code);
2404 afs_linux_complete_writeback(struct vcache *avc) {
2405 avc->f.states &= ~CPageWrite;
2408 /* Writeback a given page syncronously. Called with no AFS locks held */
2410 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2411 unsigned long offset, unsigned int count,
2414 struct vcache *vcp = VTOAFS(ip);
2422 buffer = kmap(pp) + offset;
2423 base = page_offset(pp) + offset;
2426 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2427 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2428 ICL_TYPE_INT32, 99999);
2430 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2432 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2434 i_size_write(ip, vcp->f.m.Length);
2435 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2437 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
2439 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2440 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2441 ICL_TYPE_INT32, code);
2450 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2451 unsigned long offset, unsigned int count)
2455 struct vcache *vcp = VTOAFS(ip);
2458 /* Catch recursive writeback. This occurs if the kernel decides
2459 * writeback is required whilst we are writing to the cache, or
2460 * flushing to the server. When we're running syncronously (as
2461 * opposed to from writepage) we can't actually do anything about
2462 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2465 ObtainWriteLock(&vcp->lock, 532);
2466 afs_linux_prepare_writeback(vcp);
2467 ReleaseWriteLock(&vcp->lock);
2471 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2474 ObtainWriteLock(&vcp->lock, 533);
2476 code1 = afs_linux_dopartialwrite(vcp, credp);
2477 afs_linux_complete_writeback(vcp);
2478 ReleaseWriteLock(&vcp->lock);
2489 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2490 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2492 afs_linux_writepage(struct page *pp)
2495 struct address_space *mapping = pp->mapping;
2496 struct inode *inode;
2499 unsigned int to = PAGE_CACHE_SIZE;
2504 if (PageReclaim(pp)) {
2505 return AOP_WRITEPAGE_ACTIVATE;
2506 /* XXX - Do we need to redirty the page here? */
2511 inode = mapping->host;
2512 vcp = VTOAFS(inode);
2513 isize = i_size_read(inode);
2515 /* Don't defeat an earlier truncate */
2516 if (page_offset(pp) > isize) {
2517 set_page_writeback(pp);
2523 ObtainWriteLock(&vcp->lock, 537);
2524 code = afs_linux_prepare_writeback(vcp);
2525 if (code == AOP_WRITEPAGE_ACTIVATE) {
2526 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2527 * to return with the page still locked */
2528 ReleaseWriteLock(&vcp->lock);
2533 /* Grab the creds structure currently held in the vnode, and
2534 * get a reference to it, in case it goes away ... */
2540 ReleaseWriteLock(&vcp->lock);
2543 set_page_writeback(pp);
2545 SetPageUptodate(pp);
2547 /* We can unlock the page here, because it's protected by the
2548 * page_writeback flag. This should make us less vulnerable to
2549 * deadlocking in afs_write and afs_DoPartialWrite
2553 /* If this is the final page, then just write the number of bytes that
2554 * are actually in it */
2555 if ((isize - page_offset(pp)) < to )
2556 to = isize - page_offset(pp);
2558 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2561 ObtainWriteLock(&vcp->lock, 538);
2563 /* As much as we might like to ignore a file server error here,
2564 * and just try again when we close(), unfortunately StoreAllSegments
2565 * will invalidate our chunks if the server returns a permanent error,
2566 * so we need to at least try and get that error back to the user
2569 code1 = afs_linux_dopartialwrite(vcp, credp);
2571 afs_linux_complete_writeback(vcp);
2572 ReleaseWriteLock(&vcp->lock);
2577 end_page_writeback(pp);
2578 page_cache_release(pp);
2589 /* afs_linux_permission
2590 * Check access rights - returns error if can't check or permission denied.
2593 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2594 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2595 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2596 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2598 afs_linux_permission(struct inode *ip, int mode)
2605 /* Check for RCU path walking */
2606 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2607 if (flags & IPERM_FLAG_RCU)
2609 #elif defined(MAY_NOT_BLOCK)
2610 if (mode & MAY_NOT_BLOCK)
2616 if (mode & MAY_EXEC)
2618 if (mode & MAY_READ)
2620 if (mode & MAY_WRITE)
2622 code = afs_access(VTOAFS(ip), tmp, credp);
2626 return afs_convert_code(code);
2630 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2634 struct inode *inode = FILE_INODE(file);
2635 loff_t pagebase = page_offset(page);
2637 if (i_size_read(inode) < (pagebase + offset))
2638 i_size_write(inode, pagebase + offset);
2640 if (PageChecked(page)) {
2641 SetPageUptodate(page);
2642 ClearPageChecked(page);
2645 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2651 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2655 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2656 * prepare_write. Essentially, if the page exists within the file,
2657 * and is not being fully written, then we should populate it.
2660 if (!PageUptodate(page)) {
2661 loff_t pagebase = page_offset(page);
2662 loff_t isize = i_size_read(page->mapping->host);
2664 /* Is the location we are writing to beyond the end of the file? */
2665 if (pagebase >= isize ||
2666 ((from == 0) && (pagebase + to) >= isize)) {
2667 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2668 SetPageChecked(page);
2669 /* Are we we writing a full page */
2670 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2671 SetPageChecked(page);
2672 /* Is the page readable, if it's wronly, we don't care, because we're
2673 * not actually going to read from it ... */
2674 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2675 /* We don't care if fillpage fails, because if it does the page
2676 * won't be marked as up to date
2678 afs_linux_fillpage(file, page);
2684 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2686 afs_linux_write_end(struct file *file, struct address_space *mapping,
2687 loff_t pos, unsigned len, unsigned copied,
2688 struct page *page, void *fsdata)
2691 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2693 code = afs_linux_commit_write(file, page, from, from + len);
2696 page_cache_release(page);
2701 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2702 loff_t pos, unsigned len, unsigned flags,
2703 struct page **pagep, void **fsdata)
2706 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2707 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2710 page = grab_cache_page_write_begin(mapping, index, flags);
2713 code = afs_linux_prepare_write(file, page, from, from + len);
2716 page_cache_release(page);
2723 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2725 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2727 struct dentry **dpp;
2728 struct dentry *target;
2730 if (current->total_link_count > 0) {
2731 /* avoid symlink resolution limits when resolving; we cannot contribute to
2732 * an infinite symlink loop */
2733 /* only do this for follow_link when total_link_count is positive to be
2734 * on the safe side; there is at least one code path in the Linux
2735 * kernel where it seems like it may be possible to get here without
2736 * total_link_count getting incremented. it is not clear on how that
2737 * path is actually reached, but guard against it just to be safe */
2738 current->total_link_count--;
2741 target = canonical_dentry(dentry->d_inode);
2743 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2744 dpp = &nd->path.dentry;
2754 *dpp = dget(dentry);
2757 nd->last_type = LAST_BIND;
2761 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2764 static struct inode_operations afs_file_iops = {
2765 .permission = afs_linux_permission,
2766 .getattr = afs_linux_getattr,
2767 .setattr = afs_notify_change,
2770 static struct address_space_operations afs_file_aops = {
2771 .readpage = afs_linux_readpage,
2772 .readpages = afs_linux_readpages,
2773 .writepage = afs_linux_writepage,
2774 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2775 .write_begin = afs_linux_write_begin,
2776 .write_end = afs_linux_write_end,
2778 .commit_write = afs_linux_commit_write,
2779 .prepare_write = afs_linux_prepare_write,
2784 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2785 * by what sort of operation is allowed.....
2788 static struct inode_operations afs_dir_iops = {
2789 .setattr = afs_notify_change,
2790 .create = afs_linux_create,
2791 .lookup = afs_linux_lookup,
2792 .link = afs_linux_link,
2793 .unlink = afs_linux_unlink,
2794 .symlink = afs_linux_symlink,
2795 .mkdir = afs_linux_mkdir,
2796 .rmdir = afs_linux_rmdir,
2797 .rename = afs_linux_rename,
2798 .getattr = afs_linux_getattr,
2799 .permission = afs_linux_permission,
2800 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2801 .follow_link = afs_linux_dir_follow_link,
2805 /* We really need a separate symlink set of ops, since do_follow_link()
2806 * determines if it _is_ a link by checking if the follow_link op is set.
2808 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2810 afs_symlink_filler(struct file *file, struct page *page)
2812 struct inode *ip = (struct inode *)page->mapping->host;
2813 char *p = (char *)kmap(page);
2817 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2822 p[code] = '\0'; /* null terminate? */
2824 SetPageUptodate(page);
2836 static struct address_space_operations afs_symlink_aops = {
2837 .readpage = afs_symlink_filler
2839 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2841 static struct inode_operations afs_symlink_iops = {
2842 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2843 .readlink = page_readlink,
2844 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2845 .follow_link = page_follow_link,
2847 .follow_link = page_follow_link_light,
2848 .put_link = page_put_link,
2850 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2851 .readlink = afs_linux_readlink,
2852 .follow_link = afs_linux_follow_link,
2853 .put_link = afs_linux_put_link,
2854 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2855 .setattr = afs_notify_change,
2859 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2863 vattr2inode(ip, vattr);
2865 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2866 /* Reset ops if symlink or directory. */
2867 if (S_ISREG(ip->i_mode)) {
2868 ip->i_op = &afs_file_iops;
2869 ip->i_fop = &afs_file_fops;
2870 ip->i_data.a_ops = &afs_file_aops;
2872 } else if (S_ISDIR(ip->i_mode)) {
2873 ip->i_op = &afs_dir_iops;
2874 ip->i_fop = &afs_dir_fops;
2876 } else if (S_ISLNK(ip->i_mode)) {
2877 ip->i_op = &afs_symlink_iops;
2878 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2879 ip->i_data.a_ops = &afs_symlink_aops;
2880 ip->i_mapping = &ip->i_data;