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 if ((vcp->f.states & CRO)) {
575 if (flp->fl_type == F_WRLCK) {
584 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
587 if ((code == 0 || flp->fl_type == F_UNLCK) &&
588 (cmd == F_SETLK || cmd == F_SETLKW)) {
589 code = afs_posix_lock_file(fp, flp);
590 if (code && flp->fl_type != F_UNLCK) {
591 struct AFS_FLOCK flock2;
593 flock2.l_type = F_UNLCK;
595 afs_lockctl(vcp, &flock2, F_SETLK, credp);
599 /* If lockctl says there are no conflicting locks, then also check with the
600 * kernel, as lockctl knows nothing about byte range locks
602 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
603 afs_posix_test_lock(fp, flp);
604 /* If we found a lock in the kernel's structure, return it */
605 if (flp->fl_type != F_UNLCK) {
611 /* Convert flock back to Linux's file_lock */
612 flp->fl_type = flock.l_type;
613 flp->fl_pid = flock.l_pid;
614 flp->fl_start = flock.l_start;
615 if (flock.l_len == 0)
616 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
618 flp->fl_end = flock.l_start + flock.l_len - 1;
624 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
626 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
628 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
629 cred_t *credp = crref();
630 struct AFS_FLOCK flock;
631 /* Convert to a lock format afs_lockctl understands. */
632 memset(&flock, 0, sizeof(flock));
633 flock.l_type = flp->fl_type;
634 flock.l_pid = flp->fl_pid;
639 /* Safe because there are no large files, yet */
640 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
641 if (cmd == F_GETLK64)
643 else if (cmd == F_SETLK64)
645 else if (cmd == F_SETLKW64)
647 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
650 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
653 if ((code == 0 || flp->fl_type == F_UNLCK) &&
654 (cmd == F_SETLK || cmd == F_SETLKW)) {
655 flp->fl_flags &=~ FL_SLEEP;
656 code = flock_lock_file_wait(fp, flp);
657 if (code && flp->fl_type != F_UNLCK) {
658 struct AFS_FLOCK flock2;
660 flock2.l_type = F_UNLCK;
662 afs_lockctl(vcp, &flock2, F_SETLK, credp);
666 /* Convert flock back to Linux's file_lock */
667 flp->fl_type = flock.l_type;
668 flp->fl_pid = flock.l_pid;
676 * essentially the same as afs_fsync() but we need to get the return
677 * code for the sys_close() here, not afs_linux_release(), so call
678 * afs_StoreAllSegments() with AFS_LASTSTORE
681 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
682 afs_linux_flush(struct file *fp, fl_owner_t id)
684 afs_linux_flush(struct file *fp)
687 struct vrequest treq;
695 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
703 vcp = VTOAFS(FILE_INODE(fp));
705 code = afs_InitReq(&treq, credp);
708 /* If caching is bypassed for this file, or globally, just return 0 */
709 if (cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
712 ObtainReadLock(&vcp->lock);
713 if (vcp->cachingStates & FCSBypass)
715 ReleaseReadLock(&vcp->lock);
718 /* future proof: don't rely on 0 return from afs_InitReq */
723 ObtainSharedLock(&vcp->lock, 535);
724 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
725 UpgradeSToWLock(&vcp->lock, 536);
726 if (!AFS_IS_DISCONNECTED) {
727 code = afs_StoreAllSegments(vcp,
729 AFS_SYNC | AFS_LASTSTORE);
731 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
733 ConvertWToSLock(&vcp->lock);
735 code = afs_CheckCode(code, &treq, 54);
736 ReleaseSharedLock(&vcp->lock);
743 return afs_convert_code(code);
746 struct file_operations afs_dir_fops = {
747 .read = generic_read_dir,
748 .readdir = afs_linux_readdir,
749 #ifdef HAVE_UNLOCKED_IOCTL
750 .unlocked_ioctl = afs_unlocked_xioctl,
754 #ifdef HAVE_COMPAT_IOCTL
755 .compat_ioctl = afs_unlocked_xioctl,
757 .open = afs_linux_open,
758 .release = afs_linux_release,
759 .llseek = default_llseek,
760 #ifdef HAVE_LINUX_NOOP_FSYNC
763 .fsync = simple_sync_file,
767 struct file_operations afs_file_fops = {
768 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
769 .aio_read = afs_linux_aio_read,
770 .aio_write = afs_linux_aio_write,
772 .read = afs_linux_read,
773 .write = afs_linux_write,
775 #ifdef HAVE_UNLOCKED_IOCTL
776 .unlocked_ioctl = afs_unlocked_xioctl,
780 #ifdef HAVE_COMPAT_IOCTL
781 .compat_ioctl = afs_unlocked_xioctl,
783 .mmap = afs_linux_mmap,
784 .open = afs_linux_open,
785 .flush = afs_linux_flush,
786 #if defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
787 .sendfile = generic_file_sendfile,
789 #if defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
790 .splice_write = generic_file_splice_write,
791 .splice_read = generic_file_splice_read,
793 .release = afs_linux_release,
794 .fsync = afs_linux_fsync,
795 .lock = afs_linux_lock,
796 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
797 .flock = afs_linux_flock,
799 .llseek = default_llseek,
802 static struct dentry *
803 canonical_dentry(struct inode *ip)
805 struct vcache *vcp = VTOAFS(ip);
806 struct dentry *first = NULL, *ret = NULL, *cur;
807 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
808 struct hlist_node *p;
812 * if vcp->target_link is set, and can be found in ip->i_dentry, use that.
813 * otherwise, use the first dentry in ip->i_dentry.
814 * if ip->i_dentry is empty, use the 'dentry' argument we were given.
816 /* note that vcp->target_link specifies which dentry to use, but we have
817 * no reference held on that dentry. so, we cannot use or dereference
818 * vcp->target_link itself, since it may have been freed. instead, we only
819 * use it to compare to pointers in the ip->i_dentry list. */
823 # ifdef HAVE_DCACHE_LOCK
824 spin_lock(&dcache_lock);
826 spin_lock(&ip->i_lock);
829 #if defined(D_ALIAS_IS_HLIST)
830 # if defined(HLIST_ITERATOR_NO_NODE)
831 hlist_for_each_entry(cur, &ip->i_dentry, d_alias) {
833 hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
836 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
839 if (!vcp->target_link || cur == vcp->target_link) {
852 vcp->target_link = ret;
854 # ifdef HAVE_DCACHE_LOCK
858 spin_unlock(&dcache_lock);
863 spin_unlock(&ip->i_lock);
869 /**********************************************************************
870 * AFS Linux dentry operations
871 **********************************************************************/
873 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
874 * that has its mvid (parent dir's fid) pointer set to the wrong directory
875 * due to being mounted in multiple points at once. fix_bad_parent()
876 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
877 * dotdotfid and mtpoint fid members.
879 * dp - dentry to be checked.
880 * credp - credentials
881 * vcp, pvc - item's and parent's vcache pointer
885 * This dentry's vcache's mvid will be set to the correct parent directory's
887 * This root vnode's volume will have its dotdotfid and mtpoint fids set
888 * to the correct parent and mountpoint fids.
892 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
894 struct vcache *avc = NULL;
896 /* force a lookup, so vcp->mvid is fixed up */
897 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
898 if (!avc || vcp != avc) { /* bad, very bad.. */
899 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
900 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
901 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
902 ICL_TYPE_POINTER, dp);
905 AFS_RELE(AFSTOV(avc));
910 /* afs_linux_revalidate
911 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
914 afs_linux_revalidate(struct dentry *dp)
917 struct vcache *vcp = VTOAFS(dp->d_inode);
921 if (afs_shuttingdown)
927 /* Make this a fast path (no crref), since it's called so often. */
928 if (vcp->states & CStatd) {
929 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
931 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
932 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
935 fix_bad_parent(dp); /* check and correct mvid */
944 /* This avoids the crref when we don't have to do it. Watch for
945 * changes in afs_getattr that don't get replicated here!
947 if (vcp->f.states & CStatd &&
948 (!afs_fakestat_enable || vcp->mvstat != 1) &&
950 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
951 code = afs_CopyOutAttrs(vcp, &vattr);
954 code = afs_getattr(vcp, &vattr, credp);
959 afs_fill_inode(AFSTOV(vcp), &vattr);
963 return afs_convert_code(code);
967 * Set iattr data into vattr. Assume vattr cleared before call.
970 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
972 vattrp->va_mask = iattrp->ia_valid;
973 if (iattrp->ia_valid & ATTR_MODE)
974 vattrp->va_mode = iattrp->ia_mode;
975 if (iattrp->ia_valid & ATTR_UID)
976 vattrp->va_uid = iattrp->ia_uid;
977 if (iattrp->ia_valid & ATTR_GID)
978 vattrp->va_gid = iattrp->ia_gid;
979 if (iattrp->ia_valid & ATTR_SIZE)
980 vattrp->va_size = iattrp->ia_size;
981 if (iattrp->ia_valid & ATTR_ATIME) {
982 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
983 vattrp->va_atime.tv_usec = 0;
985 if (iattrp->ia_valid & ATTR_MTIME) {
986 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
987 vattrp->va_mtime.tv_usec = 0;
989 if (iattrp->ia_valid & ATTR_CTIME) {
990 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
991 vattrp->va_ctime.tv_usec = 0;
996 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
999 vattr2inode(struct inode *ip, struct vattr *vp)
1001 ip->i_ino = vp->va_nodeid;
1002 #ifdef HAVE_LINUX_SET_NLINK
1003 set_nlink(ip, vp->va_nlink);
1005 ip->i_nlink = vp->va_nlink;
1007 ip->i_blocks = vp->va_blocks;
1008 #ifdef STRUCT_INODE_HAS_I_BLKBITS
1009 ip->i_blkbits = AFS_BLKBITS;
1011 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
1012 ip->i_blksize = vp->va_blocksize;
1014 ip->i_rdev = vp->va_rdev;
1015 ip->i_mode = vp->va_mode;
1016 ip->i_uid = vp->va_uid;
1017 ip->i_gid = vp->va_gid;
1018 i_size_write(ip, vp->va_size);
1019 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
1020 ip->i_atime.tv_nsec = 0;
1021 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
1022 /* Set the mtime nanoseconds to the sysname generation number.
1023 * This convinces NFS clients that all directories have changed
1024 * any time the sysname list changes.
1026 ip->i_mtime.tv_nsec = afs_sysnamegen;
1027 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
1028 ip->i_ctime.tv_nsec = 0;
1031 /* afs_notify_change
1032 * Linux version of setattr call. What to change is in the iattr struct.
1033 * We need to set bits in both the Linux inode as well as the vcache.
1036 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1039 cred_t *credp = crref();
1040 struct inode *ip = dp->d_inode;
1044 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1047 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1049 afs_getattr(VTOAFS(ip), &vattr, credp);
1050 vattr2inode(ip, &vattr);
1054 return afs_convert_code(code);
1058 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1060 int err = afs_linux_revalidate(dentry);
1062 generic_fillattr(dentry->d_inode, stat);
1067 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1068 * In kernels 2.2.10 and above, we are passed an additional flags var which
1069 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1070 * we are advised to follow the entry if it is a link or to make sure that
1071 * it is a directory. But since the kernel itself checks these possibilities
1072 * later on, we shouldn't have to do it until later. Perhaps in the future..
1074 * The code here assumes that on entry the global lock is not held
1077 #if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1078 afs_linux_dentry_revalidate(struct dentry *dp, unsigned int flags)
1079 #elif defined(DOP_REVALIDATE_TAKES_NAMEIDATA)
1080 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1082 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1086 cred_t *credp = NULL;
1087 struct vcache *vcp, *pvcp, *tvc = NULL;
1088 struct dentry *parent;
1090 struct afs_fakestat_state fakestate;
1094 /* We don't support RCU path walking */
1095 # if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1096 if (flags & LOOKUP_RCU)
1098 if (nd->flags & LOOKUP_RCU)
1103 afs_InitFakeStat(&fakestate);
1106 vcp = VTOAFS(dp->d_inode);
1108 if (vcp == afs_globalVp)
1111 parent = dget_parent(dp);
1112 pvcp = VTOAFS(parent->d_inode);
1114 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1120 if (locked && vcp->mvstat == 1) { /* mount point */
1121 if (vcp->mvid && (vcp->f.states & CMValid)) {
1122 int tryEvalOnly = 0;
1124 struct vrequest treq;
1126 code = afs_InitReq(&treq, credp);
1128 (strcmp(dp->d_name.name, ".directory") == 0)) {
1132 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1134 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1135 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1136 /* a mount point, not yet replaced by its directory */
1141 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1142 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1143 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1148 /* If the last looker changes, we should make sure the current
1149 * looker still has permission to examine this file. This would
1150 * always require a crref() which would be "slow".
1152 if (vcp->last_looker != treq.uid) {
1153 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
1156 vcp->last_looker = treq.uid;
1161 /* If the parent's DataVersion has changed or the vnode
1162 * is longer valid, we need to do a full lookup. VerifyVCache
1163 * isn't enough since the vnode may have been renamed.
1166 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1172 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1173 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1174 if (!tvc || tvc != vcp) {
1179 if (afs_getattr(vcp, &vattr, credp)) {
1184 vattr2inode(AFSTOV(vcp), &vattr);
1185 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1188 /* should we always update the attributes at this point? */
1189 /* unlikely--the vcache entry hasn't changed */
1194 /* If this code is ever enabled, we should use dget_parent to handle
1195 * getting the parent, and dput() to dispose of it. See above for an
1197 pvcp = VTOAFS(dp->d_parent->d_inode);
1198 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1202 /* No change in parent's DataVersion so this negative
1203 * lookup is still valid. BUT, if a server is down a
1204 * negative lookup can result so there should be a
1205 * liftime as well. For now, always expire.
1218 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1220 /* we hold the global lock if we evaluated a mount point */
1227 shrink_dcache_parent(dp);
1233 if (have_submounts(dp))
1241 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1243 struct vcache *vcp = VTOAFS(ip);
1246 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1247 (void) afs_InactiveVCache(vcp, NULL);
1250 afs_linux_clear_nfsfs_renamed(dp);
1256 #if defined(DOP_D_DELETE_TAKES_CONST)
1257 afs_dentry_delete(const struct dentry *dp)
1259 afs_dentry_delete(struct dentry *dp)
1262 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1263 return 1; /* bad inode? */
1268 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1269 static struct vfsmount *
1270 afs_dentry_automount(afs_linux_path_t *path)
1272 struct dentry *target;
1274 /* avoid symlink resolution limits when resolving; we cannot contribute to
1275 * an infinite symlink loop */
1276 current->total_link_count--;
1278 target = canonical_dentry(path->dentry->d_inode);
1280 if (target == path->dentry) {
1287 path->dentry = target;
1290 spin_lock(&path->dentry->d_lock);
1291 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1292 spin_unlock(&path->dentry->d_lock);
1297 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1299 struct dentry_operations afs_dentry_operations = {
1300 .d_revalidate = afs_linux_dentry_revalidate,
1301 .d_delete = afs_dentry_delete,
1302 .d_iput = afs_dentry_iput,
1303 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1304 .d_automount = afs_dentry_automount,
1305 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1308 /**********************************************************************
1309 * AFS Linux inode operations
1310 **********************************************************************/
1314 * Merely need to set enough of vattr to get us through the create. Note
1315 * that the higher level code (open_namei) will take care of any tuncation
1316 * explicitly. Exclusive open is also taken care of in open_namei.
1318 * name is in kernel space at this point.
1321 #if defined(IOP_CREATE_TAKES_BOOL)
1322 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1324 #elif defined(IOP_CREATE_TAKES_UMODE_T)
1325 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1326 struct nameidata *nd)
1327 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
1328 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1329 struct nameidata *nd)
1331 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1335 cred_t *credp = crref();
1336 const char *name = dp->d_name.name;
1341 vattr.va_mode = mode;
1342 vattr.va_type = mode & S_IFMT;
1345 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1349 struct inode *ip = AFSTOV(vcp);
1351 afs_getattr(vcp, &vattr, credp);
1352 afs_fill_inode(ip, &vattr);
1353 insert_inode_hash(ip);
1354 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1355 dp->d_op = &afs_dentry_operations;
1357 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1358 d_instantiate(dp, ip);
1363 return afs_convert_code(code);
1366 /* afs_linux_lookup */
1367 static struct dentry *
1368 #if defined(IOP_LOOKUP_TAKES_UNSIGNED)
1369 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1371 #elif defined(IOP_LOOKUP_TAKES_NAMEIDATA)
1372 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1373 struct nameidata *nd)
1375 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1378 cred_t *credp = crref();
1379 struct vcache *vcp = NULL;
1380 const char *comp = dp->d_name.name;
1381 struct inode *ip = NULL;
1382 struct dentry *newdp = NULL;
1386 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1390 struct vcache *parent_vc = VTOAFS(dip);
1392 if (parent_vc == vcp) {
1393 /* This is possible if the parent dir is a mountpoint to a volume,
1394 * and the dir entry we looked up is a mountpoint to the same
1395 * volume. Linux cannot cope with this, so return an error instead
1396 * of risking a deadlock or panic. */
1404 afs_getattr(vcp, &vattr, credp);
1405 afs_fill_inode(ip, &vattr);
1406 if (hlist_unhashed(&ip->i_hash))
1407 insert_inode_hash(ip);
1409 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1410 dp->d_op = &afs_dentry_operations;
1412 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1415 if (ip && S_ISDIR(ip->i_mode)) {
1416 d_prune_aliases(ip);
1418 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1419 ip->i_flags |= S_AUTOMOUNT;
1422 newdp = d_splice_alias(ip, dp);
1427 /* It's ok for the file to not be found. That's noted by the caller by
1428 * seeing that the dp->d_inode field is NULL.
1430 if (!code || code == ENOENT)
1433 return ERR_PTR(afs_convert_code(code));
1437 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1440 cred_t *credp = crref();
1441 const char *name = newdp->d_name.name;
1442 struct inode *oldip = olddp->d_inode;
1444 /* If afs_link returned the vnode, we could instantiate the
1445 * dentry. Since it's not, we drop this one and do a new lookup.
1450 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1454 return afs_convert_code(code);
1457 /* We have to have a Linux specific sillyrename function, because we
1458 * also have to keep the dcache up to date when we're doing a silly
1459 * rename - so we don't want the generic vnodeops doing this behind our
1464 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1467 struct vcache *tvc = VTOAFS(dentry->d_inode);
1468 struct dentry *__dp = NULL;
1469 char *__name = NULL;
1472 if (afs_linux_nfsfs_renamed(dentry))
1480 osi_FreeSmallSpace(__name);
1481 __name = afs_newname();
1484 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1487 osi_FreeSmallSpace(__name);
1490 } while (__dp->d_inode != NULL);
1493 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1494 VTOAFS(dir), (char *)__dp->d_name.name,
1497 tvc->mvid = (void *) __name;
1500 crfree(tvc->uncred);
1502 tvc->uncred = credp;
1503 tvc->f.states |= CUnlinked;
1504 afs_linux_set_nfsfs_renamed(dentry);
1506 osi_FreeSmallSpace(__name);
1511 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1512 d_move(dentry, __dp);
1521 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1524 cred_t *credp = crref();
1525 const char *name = dp->d_name.name;
1526 struct vcache *tvc = VTOAFS(dp->d_inode);
1528 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1529 && !(tvc->f.states & CUnlinked)) {
1531 code = afs_linux_sillyrename(dip, dp, credp);
1534 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1541 return afs_convert_code(code);
1546 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1549 cred_t *credp = crref();
1551 const char *name = dp->d_name.name;
1553 /* If afs_symlink returned the vnode, we could instantiate the
1554 * dentry. Since it's not, we drop this one and do a new lookup.
1560 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1563 return afs_convert_code(code);
1567 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1568 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1570 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1574 cred_t *credp = crref();
1575 struct vcache *tvcp = NULL;
1577 const char *name = dp->d_name.name;
1580 vattr.va_mask = ATTR_MODE;
1581 vattr.va_mode = mode;
1583 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1586 struct inode *ip = AFSTOV(tvcp);
1588 afs_getattr(tvcp, &vattr, credp);
1589 afs_fill_inode(ip, &vattr);
1591 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1592 dp->d_op = &afs_dentry_operations;
1594 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1595 d_instantiate(dp, ip);
1600 return afs_convert_code(code);
1604 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1607 cred_t *credp = crref();
1608 const char *name = dp->d_name.name;
1610 /* locking kernel conflicts with glock? */
1613 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1616 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1617 * that failed because a directory is not empty. So, we map
1618 * EEXIST to ENOTEMPTY on linux.
1620 if (code == EEXIST) {
1629 return afs_convert_code(code);
1634 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1635 struct inode *newip, struct dentry *newdp)
1638 cred_t *credp = crref();
1639 const char *oldname = olddp->d_name.name;
1640 const char *newname = newdp->d_name.name;
1641 struct dentry *rehash = NULL;
1643 /* Prevent any new references during rename operation. */
1645 if (!d_unhashed(newdp)) {
1650 #if defined(D_COUNT_INT)
1651 spin_lock(&olddp->d_lock);
1652 if (olddp->d_count > 1) {
1653 spin_unlock(&olddp->d_lock);
1654 shrink_dcache_parent(olddp);
1656 spin_unlock(&olddp->d_lock);
1658 if (atomic_read(&olddp->d_count) > 1)
1659 shrink_dcache_parent(olddp);
1663 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1667 olddp->d_time = 0; /* force to revalidate */
1673 return afs_convert_code(code);
1677 /* afs_linux_ireadlink
1678 * Internal readlink which can return link contents to user or kernel space.
1679 * Note that the buffer is NOT supposed to be null-terminated.
1682 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1685 cred_t *credp = crref();
1689 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1690 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1694 return maxlen - tuio.uio_resid;
1696 return afs_convert_code(code);
1699 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1700 /* afs_linux_readlink
1701 * Fill target (which is in user space) with contents of symlink.
1704 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1707 struct inode *ip = dp->d_inode;
1710 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1716 /* afs_linux_follow_link
1717 * a file system dependent link following routine.
1719 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1724 name = kmalloc(PATH_MAX, GFP_NOFS);
1730 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1738 nd_set_link(nd, name);
1743 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1745 char *name = nd_get_link(nd);
1747 if (name && !IS_ERR(name))
1751 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1753 /* Populate a page by filling it from the cache file pointed at by cachefp
1754 * (which contains indicated chunk)
1755 * If task is NULL, the page copy occurs syncronously, and the routine
1756 * returns with page still locked. If task is non-NULL, then page copies
1757 * may occur in the background, and the page will be unlocked when it is
1761 afs_linux_read_cache(struct file *cachefp, struct page *page,
1762 int chunk, struct pagevec *lrupv,
1763 struct afs_pagecopy_task *task) {
1764 loff_t offset = page_offset(page);
1765 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1766 struct page *newpage, *cachepage;
1767 struct address_space *cachemapping;
1771 cachemapping = cacheinode->i_mapping;
1775 /* If we're trying to read a page that's past the end of the disk
1776 * cache file, then just return a zeroed page */
1777 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1778 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1779 SetPageUptodate(page);
1785 /* From our offset, we now need to work out which page in the disk
1786 * file it corresponds to. This will be fun ... */
1787 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1789 while (cachepage == NULL) {
1790 cachepage = find_get_page(cachemapping, pageindex);
1793 newpage = page_cache_alloc_cold(cachemapping);
1799 code = add_to_page_cache(newpage, cachemapping,
1800 pageindex, GFP_KERNEL);
1802 cachepage = newpage;
1805 page_cache_get(cachepage);
1806 if (!pagevec_add(lrupv, cachepage))
1807 __pagevec_lru_add_file(lrupv);
1810 page_cache_release(newpage);
1812 if (code != -EEXIST)
1816 lock_page(cachepage);
1820 if (!PageUptodate(cachepage)) {
1821 ClearPageError(cachepage);
1822 code = cachemapping->a_ops->readpage(NULL, cachepage);
1823 if (!code && !task) {
1824 wait_on_page_locked(cachepage);
1827 unlock_page(cachepage);
1831 if (PageUptodate(cachepage)) {
1832 copy_highpage(page, cachepage);
1833 flush_dcache_page(page);
1834 SetPageUptodate(page);
1839 afs_pagecopy_queue_page(task, cachepage, page);
1851 page_cache_release(cachepage);
1857 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1859 loff_t offset = page_offset(pp);
1860 struct inode *ip = FILE_INODE(fp);
1861 struct vcache *avc = VTOAFS(ip);
1863 struct file *cacheFp = NULL;
1866 struct pagevec lrupv;
1868 /* Not a UFS cache, don't do anything */
1869 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1872 /* Can't do anything if the vcache isn't statd , or if the read
1873 * crosses a chunk boundary.
1875 if (!(avc->f.states & CStatd) ||
1876 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1880 ObtainWriteLock(&avc->lock, 911);
1882 /* XXX - See if hinting actually makes things faster !!! */
1884 /* See if we have a suitable entry already cached */
1888 /* We need to lock xdcache, then dcache, to handle situations where
1889 * the hint is on the free list. However, we can't safely do this
1890 * according to the locking hierarchy. So, use a non blocking lock.
1892 ObtainReadLock(&afs_xdcache);
1893 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1895 if (dcLocked && (tdc->index != NULLIDX)
1896 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1897 && tdc->f.chunk == AFS_CHUNK(offset)
1898 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1899 /* Bonus - the hint was correct */
1902 /* Only destroy the hint if its actually invalid, not if there's
1903 * just been a locking failure */
1905 ReleaseReadLock(&tdc->lock);
1912 ReleaseReadLock(&afs_xdcache);
1915 /* No hint, or hint is no longer valid - see if we can get something
1916 * directly from the dcache
1919 tdc = afs_FindDCache(avc, offset);
1922 ReleaseWriteLock(&avc->lock);
1927 ObtainReadLock(&tdc->lock);
1929 /* Is the dcache we've been given currently up to date */
1930 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1931 (tdc->dflags & DFFetching)) {
1932 ReleaseWriteLock(&avc->lock);
1933 ReleaseReadLock(&tdc->lock);
1938 /* Update our hint for future abuse */
1941 /* Okay, so we've now got a cache file that is up to date */
1943 /* XXX - I suspect we should be locking the inodes before we use them! */
1945 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1946 pagevec_init(&lrupv, 0);
1948 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1950 if (pagevec_count(&lrupv))
1951 __pagevec_lru_add_file(&lrupv);
1953 filp_close(cacheFp, NULL);
1956 ReleaseReadLock(&tdc->lock);
1957 ReleaseWriteLock(&avc->lock);
1964 /* afs_linux_readpage
1966 * This function is split into two, because prepare_write/begin_write
1967 * require a readpage call which doesn't unlock the resulting page upon
1971 afs_linux_fillpage(struct file *fp, struct page *pp)
1976 struct iovec *iovecp;
1977 struct inode *ip = FILE_INODE(fp);
1978 afs_int32 cnt = page_count(pp);
1979 struct vcache *avc = VTOAFS(ip);
1980 afs_offs_t offset = page_offset(pp);
1984 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1994 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1995 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
1997 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
2002 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2003 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2004 99999); /* not a possible code value */
2006 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
2008 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2009 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2011 AFS_DISCON_UNLOCK();
2014 /* XXX valid for no-cache also? Check last bits of files... :)
2015 * Cognate code goes in afs_NoCacheFetchProc. */
2016 if (auio->uio_resid) /* zero remainder of page */
2017 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
2020 flush_dcache_page(pp);
2021 SetPageUptodate(pp);
2030 return afs_convert_code(code);
2034 afs_linux_prefetch(struct file *fp, struct page *pp)
2037 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2038 afs_offs_t offset = page_offset(pp);
2040 if (AFS_CHUNKOFFSET(offset) == 0) {
2042 struct vrequest treq;
2047 code = afs_InitReq(&treq, credp);
2048 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2049 tdc = afs_FindDCache(avc, offset);
2051 if (!(tdc->mflags & DFNextStarted))
2052 afs_PrefetchChunk(avc, tdc, credp, &treq);
2055 ReleaseWriteLock(&avc->lock);
2060 return afs_convert_code(code);
2065 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2066 struct list_head *page_list, unsigned num_pages)
2071 struct iovec* iovecp;
2072 struct nocache_read_request *ancr;
2074 struct pagevec lrupv;
2078 struct inode *ip = FILE_INODE(fp);
2079 struct vcache *avc = VTOAFS(ip);
2080 afs_int32 base_index = 0;
2081 afs_int32 page_count = 0;
2084 /* background thread must free: iovecp, auio, ancr */
2085 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2087 auio = osi_Alloc(sizeof(struct uio));
2088 auio->uio_iov = iovecp;
2089 auio->uio_iovcnt = num_pages;
2090 auio->uio_flag = UIO_READ;
2091 auio->uio_seg = AFS_UIOSYS;
2092 auio->uio_resid = num_pages * PAGE_SIZE;
2094 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2096 ancr->offset = auio->uio_offset;
2097 ancr->length = auio->uio_resid;
2099 pagevec_init(&lrupv, 0);
2101 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2103 if(list_empty(page_list))
2106 pp = list_entry(page_list->prev, struct page, lru);
2107 /* If we allocate a page and don't remove it from page_list,
2108 * the page cache gets upset. */
2110 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2111 if(pp->index > isize) {
2118 offset = page_offset(pp);
2119 ancr->offset = auio->uio_offset = offset;
2120 base_index = pp->index;
2122 iovecp[page_ix].iov_len = PAGE_SIZE;
2123 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2124 if(base_index != pp->index) {
2127 page_cache_release(pp);
2128 iovecp[page_ix].iov_base = (void *) 0;
2130 ancr->length -= PAGE_SIZE;
2137 page_cache_release(pp);
2138 iovecp[page_ix].iov_base = (void *) 0;
2141 if(!PageLocked(pp)) {
2145 /* increment page refcount--our original design assumed
2146 * that locking it would effectively pin it; protect
2147 * ourselves from the possiblity that this assumption is
2148 * is faulty, at low cost (provided we do not fail to
2149 * do the corresponding decref on the other side) */
2152 /* save the page for background map */
2153 iovecp[page_ix].iov_base = (void*) pp;
2155 /* and put it on the LRU cache */
2156 if (!pagevec_add(&lrupv, pp))
2157 __pagevec_lru_add_file(&lrupv);
2161 /* If there were useful pages in the page list, make sure all pages
2162 * are in the LRU cache, then schedule the read */
2164 if (pagevec_count(&lrupv))
2165 __pagevec_lru_add_file(&lrupv);
2167 code = afs_ReadNoCache(avc, ancr, credp);
2170 /* If there is nothing for the background thread to handle,
2171 * it won't be freeing the things that we never gave it */
2172 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2173 osi_Free(auio, sizeof(struct uio));
2174 osi_Free(ancr, sizeof(struct nocache_read_request));
2176 /* we do not flush, release, or unmap pages--that will be
2177 * done for us by the background thread as each page comes in
2178 * from the fileserver */
2179 return afs_convert_code(code);
2184 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2186 cred_t *credp = NULL;
2188 struct iovec *iovecp;
2189 struct nocache_read_request *ancr;
2193 * Special case: if page is at or past end of file, just zero it and set
2196 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2197 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2198 SetPageUptodate(pp);
2205 /* receiver frees */
2206 auio = osi_Alloc(sizeof(struct uio));
2207 iovecp = osi_Alloc(sizeof(struct iovec));
2209 /* address can be NULL, because we overwrite it with 'pp', below */
2210 setup_uio(auio, iovecp, NULL, page_offset(pp),
2211 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2213 /* save the page for background map */
2214 get_page(pp); /* see above */
2215 auio->uio_iov->iov_base = (void*) pp;
2216 /* the background thread will free this */
2217 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2219 ancr->offset = page_offset(pp);
2220 ancr->length = PAGE_SIZE;
2223 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2226 return afs_convert_code(code);
2230 afs_linux_can_bypass(struct inode *ip) {
2232 switch(cache_bypass_strategy) {
2233 case NEVER_BYPASS_CACHE:
2235 case ALWAYS_BYPASS_CACHE:
2237 case LARGE_FILES_BYPASS_CACHE:
2238 if (i_size_read(ip) > cache_bypass_threshold)
2245 /* Check if a file is permitted to bypass the cache by policy, and modify
2246 * the cache bypass state recorded for that file */
2249 afs_linux_bypass_check(struct inode *ip) {
2252 int bypass = afs_linux_can_bypass(ip);
2255 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2263 afs_linux_readpage(struct file *fp, struct page *pp)
2267 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2268 code = afs_linux_bypass_readpage(fp, pp);
2270 code = afs_linux_fillpage(fp, pp);
2272 code = afs_linux_prefetch(fp, pp);
2279 /* Readpages reads a number of pages for a particular file. We use
2280 * this to optimise the reading, by limiting the number of times upon which
2281 * we have to lookup, lock and open vcaches and dcaches
2285 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2286 struct list_head *page_list, unsigned int num_pages)
2288 struct inode *inode = mapping->host;
2289 struct vcache *avc = VTOAFS(inode);
2291 struct file *cacheFp = NULL;
2293 unsigned int page_idx;
2295 struct pagevec lrupv;
2296 struct afs_pagecopy_task *task;
2298 if (afs_linux_bypass_check(inode))
2299 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2301 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2305 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2310 ObtainWriteLock(&avc->lock, 912);
2313 task = afs_pagecopy_init_task();
2316 pagevec_init(&lrupv, 0);
2317 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2318 struct page *page = list_entry(page_list->prev, struct page, lru);
2319 list_del(&page->lru);
2320 offset = page_offset(page);
2322 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2324 ReleaseReadLock(&tdc->lock);
2329 filp_close(cacheFp, NULL);
2334 if ((tdc = afs_FindDCache(avc, offset))) {
2335 ObtainReadLock(&tdc->lock);
2336 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2337 (tdc->dflags & DFFetching)) {
2338 ReleaseReadLock(&tdc->lock);
2345 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2348 if (tdc && !add_to_page_cache(page, mapping, page->index,
2350 page_cache_get(page);
2351 if (!pagevec_add(&lrupv, page))
2352 __pagevec_lru_add_file(&lrupv);
2354 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2356 page_cache_release(page);
2358 if (pagevec_count(&lrupv))
2359 __pagevec_lru_add_file(&lrupv);
2362 filp_close(cacheFp, NULL);
2364 afs_pagecopy_put_task(task);
2368 ReleaseReadLock(&tdc->lock);
2372 ReleaseWriteLock(&avc->lock);
2377 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2380 afs_linux_prepare_writeback(struct vcache *avc) {
2381 if (avc->f.states & CPageWrite) {
2382 return AOP_WRITEPAGE_ACTIVATE;
2384 avc->f.states |= CPageWrite;
2389 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2390 struct vrequest treq;
2393 if (!afs_InitReq(&treq, credp))
2394 code = afs_DoPartialWrite(avc, &treq);
2396 return afs_convert_code(code);
2400 afs_linux_complete_writeback(struct vcache *avc) {
2401 avc->f.states &= ~CPageWrite;
2404 /* Writeback a given page syncronously. Called with no AFS locks held */
2406 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2407 unsigned long offset, unsigned int count,
2410 struct vcache *vcp = VTOAFS(ip);
2418 buffer = kmap(pp) + offset;
2419 base = page_offset(pp) + offset;
2422 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2423 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2424 ICL_TYPE_INT32, 99999);
2426 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2428 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2430 i_size_write(ip, vcp->f.m.Length);
2431 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2433 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
2435 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2436 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2437 ICL_TYPE_INT32, code);
2446 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2447 unsigned long offset, unsigned int count)
2451 struct vcache *vcp = VTOAFS(ip);
2454 /* Catch recursive writeback. This occurs if the kernel decides
2455 * writeback is required whilst we are writing to the cache, or
2456 * flushing to the server. When we're running syncronously (as
2457 * opposed to from writepage) we can't actually do anything about
2458 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2461 ObtainWriteLock(&vcp->lock, 532);
2462 afs_linux_prepare_writeback(vcp);
2463 ReleaseWriteLock(&vcp->lock);
2467 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2470 ObtainWriteLock(&vcp->lock, 533);
2472 code1 = afs_linux_dopartialwrite(vcp, credp);
2473 afs_linux_complete_writeback(vcp);
2474 ReleaseWriteLock(&vcp->lock);
2485 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2486 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2488 afs_linux_writepage(struct page *pp)
2491 struct address_space *mapping = pp->mapping;
2492 struct inode *inode;
2495 unsigned int to = PAGE_CACHE_SIZE;
2500 if (PageReclaim(pp)) {
2501 return AOP_WRITEPAGE_ACTIVATE;
2502 /* XXX - Do we need to redirty the page here? */
2507 inode = mapping->host;
2508 vcp = VTOAFS(inode);
2509 isize = i_size_read(inode);
2511 /* Don't defeat an earlier truncate */
2512 if (page_offset(pp) > isize) {
2513 set_page_writeback(pp);
2519 ObtainWriteLock(&vcp->lock, 537);
2520 code = afs_linux_prepare_writeback(vcp);
2521 if (code == AOP_WRITEPAGE_ACTIVATE) {
2522 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2523 * to return with the page still locked */
2524 ReleaseWriteLock(&vcp->lock);
2529 /* Grab the creds structure currently held in the vnode, and
2530 * get a reference to it, in case it goes away ... */
2536 ReleaseWriteLock(&vcp->lock);
2539 set_page_writeback(pp);
2541 SetPageUptodate(pp);
2543 /* We can unlock the page here, because it's protected by the
2544 * page_writeback flag. This should make us less vulnerable to
2545 * deadlocking in afs_write and afs_DoPartialWrite
2549 /* If this is the final page, then just write the number of bytes that
2550 * are actually in it */
2551 if ((isize - page_offset(pp)) < to )
2552 to = isize - page_offset(pp);
2554 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2557 ObtainWriteLock(&vcp->lock, 538);
2559 /* As much as we might like to ignore a file server error here,
2560 * and just try again when we close(), unfortunately StoreAllSegments
2561 * will invalidate our chunks if the server returns a permanent error,
2562 * so we need to at least try and get that error back to the user
2565 code1 = afs_linux_dopartialwrite(vcp, credp);
2567 afs_linux_complete_writeback(vcp);
2568 ReleaseWriteLock(&vcp->lock);
2573 end_page_writeback(pp);
2574 page_cache_release(pp);
2585 /* afs_linux_permission
2586 * Check access rights - returns error if can't check or permission denied.
2589 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2590 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2591 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2592 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2594 afs_linux_permission(struct inode *ip, int mode)
2601 /* Check for RCU path walking */
2602 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2603 if (flags & IPERM_FLAG_RCU)
2605 #elif defined(MAY_NOT_BLOCK)
2606 if (mode & MAY_NOT_BLOCK)
2612 if (mode & MAY_EXEC)
2614 if (mode & MAY_READ)
2616 if (mode & MAY_WRITE)
2618 code = afs_access(VTOAFS(ip), tmp, credp);
2622 return afs_convert_code(code);
2626 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2630 struct inode *inode = FILE_INODE(file);
2631 loff_t pagebase = page_offset(page);
2633 if (i_size_read(inode) < (pagebase + offset))
2634 i_size_write(inode, pagebase + offset);
2636 if (PageChecked(page)) {
2637 SetPageUptodate(page);
2638 ClearPageChecked(page);
2641 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2647 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2651 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2652 * prepare_write. Essentially, if the page exists within the file,
2653 * and is not being fully written, then we should populate it.
2656 if (!PageUptodate(page)) {
2657 loff_t pagebase = page_offset(page);
2658 loff_t isize = i_size_read(page->mapping->host);
2660 /* Is the location we are writing to beyond the end of the file? */
2661 if (pagebase >= isize ||
2662 ((from == 0) && (pagebase + to) >= isize)) {
2663 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2664 SetPageChecked(page);
2665 /* Are we we writing a full page */
2666 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2667 SetPageChecked(page);
2668 /* Is the page readable, if it's wronly, we don't care, because we're
2669 * not actually going to read from it ... */
2670 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2671 /* We don't care if fillpage fails, because if it does the page
2672 * won't be marked as up to date
2674 afs_linux_fillpage(file, page);
2680 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2682 afs_linux_write_end(struct file *file, struct address_space *mapping,
2683 loff_t pos, unsigned len, unsigned copied,
2684 struct page *page, void *fsdata)
2687 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2689 code = afs_linux_commit_write(file, page, from, from + len);
2692 page_cache_release(page);
2697 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2698 loff_t pos, unsigned len, unsigned flags,
2699 struct page **pagep, void **fsdata)
2702 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2703 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2706 page = grab_cache_page_write_begin(mapping, index, flags);
2709 code = afs_linux_prepare_write(file, page, from, from + len);
2712 page_cache_release(page);
2719 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2721 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2723 struct dentry **dpp;
2724 struct dentry *target;
2726 if (current->total_link_count > 0) {
2727 /* avoid symlink resolution limits when resolving; we cannot contribute to
2728 * an infinite symlink loop */
2729 /* only do this for follow_link when total_link_count is positive to be
2730 * on the safe side; there is at least one code path in the Linux
2731 * kernel where it seems like it may be possible to get here without
2732 * total_link_count getting incremented. it is not clear on how that
2733 * path is actually reached, but guard against it just to be safe */
2734 current->total_link_count--;
2737 target = canonical_dentry(dentry->d_inode);
2739 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2740 dpp = &nd->path.dentry;
2750 *dpp = dget(dentry);
2753 nd->last_type = LAST_BIND;
2757 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2760 static struct inode_operations afs_file_iops = {
2761 .permission = afs_linux_permission,
2762 .getattr = afs_linux_getattr,
2763 .setattr = afs_notify_change,
2766 static struct address_space_operations afs_file_aops = {
2767 .readpage = afs_linux_readpage,
2768 .readpages = afs_linux_readpages,
2769 .writepage = afs_linux_writepage,
2770 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2771 .write_begin = afs_linux_write_begin,
2772 .write_end = afs_linux_write_end,
2774 .commit_write = afs_linux_commit_write,
2775 .prepare_write = afs_linux_prepare_write,
2780 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2781 * by what sort of operation is allowed.....
2784 static struct inode_operations afs_dir_iops = {
2785 .setattr = afs_notify_change,
2786 .create = afs_linux_create,
2787 .lookup = afs_linux_lookup,
2788 .link = afs_linux_link,
2789 .unlink = afs_linux_unlink,
2790 .symlink = afs_linux_symlink,
2791 .mkdir = afs_linux_mkdir,
2792 .rmdir = afs_linux_rmdir,
2793 .rename = afs_linux_rename,
2794 .getattr = afs_linux_getattr,
2795 .permission = afs_linux_permission,
2796 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2797 .follow_link = afs_linux_dir_follow_link,
2801 /* We really need a separate symlink set of ops, since do_follow_link()
2802 * determines if it _is_ a link by checking if the follow_link op is set.
2804 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2806 afs_symlink_filler(struct file *file, struct page *page)
2808 struct inode *ip = (struct inode *)page->mapping->host;
2809 char *p = (char *)kmap(page);
2813 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2818 p[code] = '\0'; /* null terminate? */
2820 SetPageUptodate(page);
2832 static struct address_space_operations afs_symlink_aops = {
2833 .readpage = afs_symlink_filler
2835 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2837 static struct inode_operations afs_symlink_iops = {
2838 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2839 .readlink = page_readlink,
2840 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2841 .follow_link = page_follow_link,
2843 .follow_link = page_follow_link_light,
2844 .put_link = page_put_link,
2846 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2847 .readlink = afs_linux_readlink,
2848 .follow_link = afs_linux_follow_link,
2849 .put_link = afs_linux_put_link,
2850 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2851 .setattr = afs_notify_change,
2855 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2859 vattr2inode(ip, vattr);
2861 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2862 /* Reset ops if symlink or directory. */
2863 if (S_ISREG(ip->i_mode)) {
2864 ip->i_op = &afs_file_iops;
2865 ip->i_fop = &afs_file_fops;
2866 ip->i_data.a_ops = &afs_file_aops;
2868 } else if (S_ISDIR(ip->i_mode)) {
2869 ip->i_op = &afs_dir_iops;
2870 ip->i_fop = &afs_dir_fops;
2872 } else if (S_ISLNK(ip->i_mode)) {
2873 ip->i_op = &afs_symlink_iops;
2874 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2875 ip->i_data.a_ops = &afs_symlink_aops;
2876 ip->i_mapping = &ip->i_data;