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)
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 hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
832 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
835 if (!vcp->target_link || cur == vcp->target_link) {
848 vcp->target_link = ret;
850 # ifdef HAVE_DCACHE_LOCK
854 spin_unlock(&dcache_lock);
859 spin_unlock(&ip->i_lock);
865 /**********************************************************************
866 * AFS Linux dentry operations
867 **********************************************************************/
869 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
870 * that has its mvid (parent dir's fid) pointer set to the wrong directory
871 * due to being mounted in multiple points at once. fix_bad_parent()
872 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
873 * dotdotfid and mtpoint fid members.
875 * dp - dentry to be checked.
876 * credp - credentials
877 * vcp, pvc - item's and parent's vcache pointer
881 * This dentry's vcache's mvid will be set to the correct parent directory's
883 * This root vnode's volume will have its dotdotfid and mtpoint fids set
884 * to the correct parent and mountpoint fids.
888 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
890 struct vcache *avc = NULL;
892 /* force a lookup, so vcp->mvid is fixed up */
893 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
894 if (!avc || vcp != avc) { /* bad, very bad.. */
895 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
896 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
897 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
898 ICL_TYPE_POINTER, dp);
901 AFS_RELE(AFSTOV(avc));
906 /* afs_linux_revalidate
907 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
910 afs_linux_revalidate(struct dentry *dp)
913 struct vcache *vcp = VTOAFS(dp->d_inode);
917 if (afs_shuttingdown)
923 /* Make this a fast path (no crref), since it's called so often. */
924 if (vcp->states & CStatd) {
925 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
927 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
928 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
931 fix_bad_parent(dp); /* check and correct mvid */
940 /* This avoids the crref when we don't have to do it. Watch for
941 * changes in afs_getattr that don't get replicated here!
943 if (vcp->f.states & CStatd &&
944 (!afs_fakestat_enable || vcp->mvstat != 1) &&
946 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
947 code = afs_CopyOutAttrs(vcp, &vattr);
950 code = afs_getattr(vcp, &vattr, credp);
955 afs_fill_inode(AFSTOV(vcp), &vattr);
959 return afs_convert_code(code);
963 * Set iattr data into vattr. Assume vattr cleared before call.
966 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
968 vattrp->va_mask = iattrp->ia_valid;
969 if (iattrp->ia_valid & ATTR_MODE)
970 vattrp->va_mode = iattrp->ia_mode;
971 if (iattrp->ia_valid & ATTR_UID)
972 vattrp->va_uid = iattrp->ia_uid;
973 if (iattrp->ia_valid & ATTR_GID)
974 vattrp->va_gid = iattrp->ia_gid;
975 if (iattrp->ia_valid & ATTR_SIZE)
976 vattrp->va_size = iattrp->ia_size;
977 if (iattrp->ia_valid & ATTR_ATIME) {
978 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
979 vattrp->va_atime.tv_usec = 0;
981 if (iattrp->ia_valid & ATTR_MTIME) {
982 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
983 vattrp->va_mtime.tv_usec = 0;
985 if (iattrp->ia_valid & ATTR_CTIME) {
986 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
987 vattrp->va_ctime.tv_usec = 0;
992 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
995 vattr2inode(struct inode *ip, struct vattr *vp)
997 ip->i_ino = vp->va_nodeid;
998 #ifdef HAVE_LINUX_SET_NLINK
999 set_nlink(ip, vp->va_nlink);
1001 ip->i_nlink = vp->va_nlink;
1003 ip->i_blocks = vp->va_blocks;
1004 #ifdef STRUCT_INODE_HAS_I_BLKBITS
1005 ip->i_blkbits = AFS_BLKBITS;
1007 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
1008 ip->i_blksize = vp->va_blocksize;
1010 ip->i_rdev = vp->va_rdev;
1011 ip->i_mode = vp->va_mode;
1012 ip->i_uid = vp->va_uid;
1013 ip->i_gid = vp->va_gid;
1014 i_size_write(ip, vp->va_size);
1015 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
1016 ip->i_atime.tv_nsec = 0;
1017 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
1018 /* Set the mtime nanoseconds to the sysname generation number.
1019 * This convinces NFS clients that all directories have changed
1020 * any time the sysname list changes.
1022 ip->i_mtime.tv_nsec = afs_sysnamegen;
1023 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
1024 ip->i_ctime.tv_nsec = 0;
1027 /* afs_notify_change
1028 * Linux version of setattr call. What to change is in the iattr struct.
1029 * We need to set bits in both the Linux inode as well as the vcache.
1032 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1035 cred_t *credp = crref();
1036 struct inode *ip = dp->d_inode;
1040 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1043 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1045 afs_getattr(VTOAFS(ip), &vattr, credp);
1046 vattr2inode(ip, &vattr);
1050 return afs_convert_code(code);
1054 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1056 int err = afs_linux_revalidate(dentry);
1058 generic_fillattr(dentry->d_inode, stat);
1063 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1064 * In kernels 2.2.10 and above, we are passed an additional flags var which
1065 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1066 * we are advised to follow the entry if it is a link or to make sure that
1067 * it is a directory. But since the kernel itself checks these possibilities
1068 * later on, we shouldn't have to do it until later. Perhaps in the future..
1070 * The code here assumes that on entry the global lock is not held
1073 #if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1074 afs_linux_dentry_revalidate(struct dentry *dp, unsigned int flags)
1075 #elif defined(DOP_REVALIDATE_TAKES_NAMEIDATA)
1076 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1078 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1082 cred_t *credp = NULL;
1083 struct vcache *vcp, *pvcp, *tvc = NULL;
1084 struct dentry *parent;
1086 struct afs_fakestat_state fakestate;
1090 /* We don't support RCU path walking */
1091 # if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1092 if (flags & LOOKUP_RCU)
1094 if (nd->flags & LOOKUP_RCU)
1099 afs_InitFakeStat(&fakestate);
1102 vcp = VTOAFS(dp->d_inode);
1104 if (vcp == afs_globalVp)
1107 parent = dget_parent(dp);
1108 pvcp = VTOAFS(parent->d_inode);
1110 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1116 if (locked && vcp->mvstat == 1) { /* mount point */
1117 if (vcp->mvid && (vcp->f.states & CMValid)) {
1118 int tryEvalOnly = 0;
1120 struct vrequest treq;
1122 code = afs_InitReq(&treq, credp);
1124 (strcmp(dp->d_name.name, ".directory") == 0)) {
1128 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1130 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1131 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1132 /* a mount point, not yet replaced by its directory */
1137 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1138 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1139 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1144 /* If the last looker changes, we should make sure the current
1145 * looker still has permission to examine this file. This would
1146 * always require a crref() which would be "slow".
1148 if (vcp->last_looker != treq.uid) {
1149 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
1152 vcp->last_looker = treq.uid;
1157 /* If the parent's DataVersion has changed or the vnode
1158 * is longer valid, we need to do a full lookup. VerifyVCache
1159 * isn't enough since the vnode may have been renamed.
1162 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1168 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1169 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1170 if (!tvc || tvc != vcp) {
1175 if (afs_getattr(vcp, &vattr, credp)) {
1180 vattr2inode(AFSTOV(vcp), &vattr);
1181 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1184 /* should we always update the attributes at this point? */
1185 /* unlikely--the vcache entry hasn't changed */
1190 /* If this code is ever enabled, we should use dget_parent to handle
1191 * getting the parent, and dput() to dispose of it. See above for an
1193 pvcp = VTOAFS(dp->d_parent->d_inode);
1194 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1198 /* No change in parent's DataVersion so this negative
1199 * lookup is still valid. BUT, if a server is down a
1200 * negative lookup can result so there should be a
1201 * liftime as well. For now, always expire.
1214 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1216 /* we hold the global lock if we evaluated a mount point */
1223 shrink_dcache_parent(dp);
1229 if (have_submounts(dp))
1237 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1239 struct vcache *vcp = VTOAFS(ip);
1242 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1243 (void) afs_InactiveVCache(vcp, NULL);
1246 afs_linux_clear_nfsfs_renamed(dp);
1252 #if defined(DOP_D_DELETE_TAKES_CONST)
1253 afs_dentry_delete(const struct dentry *dp)
1255 afs_dentry_delete(struct dentry *dp)
1258 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1259 return 1; /* bad inode? */
1264 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1265 static struct vfsmount *
1266 afs_dentry_automount(afs_linux_path_t *path)
1268 struct dentry *target;
1270 /* avoid symlink resolution limits when resolving; we cannot contribute to
1271 * an infinite symlink loop */
1272 current->total_link_count--;
1274 target = canonical_dentry(path->dentry->d_inode);
1276 if (target == path->dentry) {
1283 path->dentry = target;
1286 spin_lock(&path->dentry->d_lock);
1287 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1288 spin_unlock(&path->dentry->d_lock);
1293 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1295 struct dentry_operations afs_dentry_operations = {
1296 .d_revalidate = afs_linux_dentry_revalidate,
1297 .d_delete = afs_dentry_delete,
1298 .d_iput = afs_dentry_iput,
1299 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1300 .d_automount = afs_dentry_automount,
1301 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1304 /**********************************************************************
1305 * AFS Linux inode operations
1306 **********************************************************************/
1310 * Merely need to set enough of vattr to get us through the create. Note
1311 * that the higher level code (open_namei) will take care of any tuncation
1312 * explicitly. Exclusive open is also taken care of in open_namei.
1314 * name is in kernel space at this point.
1317 #if defined(IOP_CREATE_TAKES_BOOL)
1318 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1320 #elif defined(IOP_CREATE_TAKES_UMODE_T)
1321 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1322 struct nameidata *nd)
1323 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
1324 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1325 struct nameidata *nd)
1327 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1331 cred_t *credp = crref();
1332 const char *name = dp->d_name.name;
1337 vattr.va_mode = mode;
1338 vattr.va_type = mode & S_IFMT;
1341 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1345 struct inode *ip = AFSTOV(vcp);
1347 afs_getattr(vcp, &vattr, credp);
1348 afs_fill_inode(ip, &vattr);
1349 insert_inode_hash(ip);
1350 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1351 dp->d_op = &afs_dentry_operations;
1353 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1354 d_instantiate(dp, ip);
1359 return afs_convert_code(code);
1362 /* afs_linux_lookup */
1363 static struct dentry *
1364 #if defined(IOP_LOOKUP_TAKES_UNSIGNED)
1365 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1367 #elif defined(IOP_LOOKUP_TAKES_NAMEIDATA)
1368 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1369 struct nameidata *nd)
1371 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1374 cred_t *credp = crref();
1375 struct vcache *vcp = NULL;
1376 const char *comp = dp->d_name.name;
1377 struct inode *ip = NULL;
1378 struct dentry *newdp = NULL;
1382 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1386 struct vcache *parent_vc = VTOAFS(dip);
1388 if (parent_vc == vcp) {
1389 /* This is possible if the parent dir is a mountpoint to a volume,
1390 * and the dir entry we looked up is a mountpoint to the same
1391 * volume. Linux cannot cope with this, so return an error instead
1392 * of risking a deadlock or panic. */
1400 afs_getattr(vcp, &vattr, credp);
1401 afs_fill_inode(ip, &vattr);
1402 if (hlist_unhashed(&ip->i_hash))
1403 insert_inode_hash(ip);
1405 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1406 dp->d_op = &afs_dentry_operations;
1408 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1411 if (ip && S_ISDIR(ip->i_mode)) {
1412 d_prune_aliases(ip);
1414 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1415 ip->i_flags |= S_AUTOMOUNT;
1418 newdp = d_splice_alias(ip, dp);
1423 /* It's ok for the file to not be found. That's noted by the caller by
1424 * seeing that the dp->d_inode field is NULL.
1426 if (!code || code == ENOENT)
1429 return ERR_PTR(afs_convert_code(code));
1433 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1436 cred_t *credp = crref();
1437 const char *name = newdp->d_name.name;
1438 struct inode *oldip = olddp->d_inode;
1440 /* If afs_link returned the vnode, we could instantiate the
1441 * dentry. Since it's not, we drop this one and do a new lookup.
1446 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1450 return afs_convert_code(code);
1453 /* We have to have a Linux specific sillyrename function, because we
1454 * also have to keep the dcache up to date when we're doing a silly
1455 * rename - so we don't want the generic vnodeops doing this behind our
1460 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1463 struct vcache *tvc = VTOAFS(dentry->d_inode);
1464 struct dentry *__dp = NULL;
1465 char *__name = NULL;
1468 if (afs_linux_nfsfs_renamed(dentry))
1476 osi_FreeSmallSpace(__name);
1477 __name = afs_newname();
1480 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1483 osi_FreeSmallSpace(__name);
1486 } while (__dp->d_inode != NULL);
1489 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1490 VTOAFS(dir), (char *)__dp->d_name.name,
1493 tvc->mvid = (void *) __name;
1496 crfree(tvc->uncred);
1498 tvc->uncred = credp;
1499 tvc->f.states |= CUnlinked;
1500 afs_linux_set_nfsfs_renamed(dentry);
1502 osi_FreeSmallSpace(__name);
1507 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1508 d_move(dentry, __dp);
1517 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1520 cred_t *credp = crref();
1521 const char *name = dp->d_name.name;
1522 struct vcache *tvc = VTOAFS(dp->d_inode);
1524 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1525 && !(tvc->f.states & CUnlinked)) {
1527 code = afs_linux_sillyrename(dip, dp, credp);
1530 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1537 return afs_convert_code(code);
1542 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1545 cred_t *credp = crref();
1547 const char *name = dp->d_name.name;
1549 /* If afs_symlink returned the vnode, we could instantiate the
1550 * dentry. Since it's not, we drop this one and do a new lookup.
1556 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1559 return afs_convert_code(code);
1563 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1564 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1566 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1570 cred_t *credp = crref();
1571 struct vcache *tvcp = NULL;
1573 const char *name = dp->d_name.name;
1576 vattr.va_mask = ATTR_MODE;
1577 vattr.va_mode = mode;
1579 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1582 struct inode *ip = AFSTOV(tvcp);
1584 afs_getattr(tvcp, &vattr, credp);
1585 afs_fill_inode(ip, &vattr);
1587 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1588 dp->d_op = &afs_dentry_operations;
1590 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1591 d_instantiate(dp, ip);
1596 return afs_convert_code(code);
1600 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1603 cred_t *credp = crref();
1604 const char *name = dp->d_name.name;
1606 /* locking kernel conflicts with glock? */
1609 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1612 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1613 * that failed because a directory is not empty. So, we map
1614 * EEXIST to ENOTEMPTY on linux.
1616 if (code == EEXIST) {
1625 return afs_convert_code(code);
1630 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1631 struct inode *newip, struct dentry *newdp)
1634 cred_t *credp = crref();
1635 const char *oldname = olddp->d_name.name;
1636 const char *newname = newdp->d_name.name;
1637 struct dentry *rehash = NULL;
1639 /* Prevent any new references during rename operation. */
1641 if (!d_unhashed(newdp)) {
1646 #if defined(D_COUNT_INT)
1647 spin_lock(&olddp->d_lock);
1648 if (olddp->d_count > 1) {
1649 spin_unlock(&olddp->d_lock);
1650 shrink_dcache_parent(olddp);
1652 spin_unlock(&olddp->d_lock);
1654 if (atomic_read(&olddp->d_count) > 1)
1655 shrink_dcache_parent(olddp);
1659 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1663 olddp->d_time = 0; /* force to revalidate */
1669 return afs_convert_code(code);
1673 /* afs_linux_ireadlink
1674 * Internal readlink which can return link contents to user or kernel space.
1675 * Note that the buffer is NOT supposed to be null-terminated.
1678 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1681 cred_t *credp = crref();
1685 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1686 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1690 return maxlen - tuio.uio_resid;
1692 return afs_convert_code(code);
1695 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1696 /* afs_linux_readlink
1697 * Fill target (which is in user space) with contents of symlink.
1700 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1703 struct inode *ip = dp->d_inode;
1706 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1712 /* afs_linux_follow_link
1713 * a file system dependent link following routine.
1715 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1720 name = kmalloc(PATH_MAX, GFP_NOFS);
1726 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1734 nd_set_link(nd, name);
1739 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1741 char *name = nd_get_link(nd);
1743 if (name && !IS_ERR(name))
1747 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1749 /* Populate a page by filling it from the cache file pointed at by cachefp
1750 * (which contains indicated chunk)
1751 * If task is NULL, the page copy occurs syncronously, and the routine
1752 * returns with page still locked. If task is non-NULL, then page copies
1753 * may occur in the background, and the page will be unlocked when it is
1757 afs_linux_read_cache(struct file *cachefp, struct page *page,
1758 int chunk, struct pagevec *lrupv,
1759 struct afs_pagecopy_task *task) {
1760 loff_t offset = page_offset(page);
1761 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1762 struct page *newpage, *cachepage;
1763 struct address_space *cachemapping;
1767 cachemapping = cacheinode->i_mapping;
1771 /* If we're trying to read a page that's past the end of the disk
1772 * cache file, then just return a zeroed page */
1773 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1774 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1775 SetPageUptodate(page);
1781 /* From our offset, we now need to work out which page in the disk
1782 * file it corresponds to. This will be fun ... */
1783 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1785 while (cachepage == NULL) {
1786 cachepage = find_get_page(cachemapping, pageindex);
1789 newpage = page_cache_alloc_cold(cachemapping);
1795 code = add_to_page_cache(newpage, cachemapping,
1796 pageindex, GFP_KERNEL);
1798 cachepage = newpage;
1801 page_cache_get(cachepage);
1802 if (!pagevec_add(lrupv, cachepage))
1803 __pagevec_lru_add_file(lrupv);
1806 page_cache_release(newpage);
1808 if (code != -EEXIST)
1812 lock_page(cachepage);
1816 if (!PageUptodate(cachepage)) {
1817 ClearPageError(cachepage);
1818 code = cachemapping->a_ops->readpage(NULL, cachepage);
1819 if (!code && !task) {
1820 wait_on_page_locked(cachepage);
1823 unlock_page(cachepage);
1827 if (PageUptodate(cachepage)) {
1828 copy_highpage(page, cachepage);
1829 flush_dcache_page(page);
1830 SetPageUptodate(page);
1835 afs_pagecopy_queue_page(task, cachepage, page);
1847 page_cache_release(cachepage);
1853 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1855 loff_t offset = page_offset(pp);
1856 struct inode *ip = FILE_INODE(fp);
1857 struct vcache *avc = VTOAFS(ip);
1859 struct file *cacheFp = NULL;
1862 struct pagevec lrupv;
1864 /* Not a UFS cache, don't do anything */
1865 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1868 /* Can't do anything if the vcache isn't statd , or if the read
1869 * crosses a chunk boundary.
1871 if (!(avc->f.states & CStatd) ||
1872 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1876 ObtainWriteLock(&avc->lock, 911);
1878 /* XXX - See if hinting actually makes things faster !!! */
1880 /* See if we have a suitable entry already cached */
1884 /* We need to lock xdcache, then dcache, to handle situations where
1885 * the hint is on the free list. However, we can't safely do this
1886 * according to the locking hierarchy. So, use a non blocking lock.
1888 ObtainReadLock(&afs_xdcache);
1889 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1891 if (dcLocked && (tdc->index != NULLIDX)
1892 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1893 && tdc->f.chunk == AFS_CHUNK(offset)
1894 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1895 /* Bonus - the hint was correct */
1898 /* Only destroy the hint if its actually invalid, not if there's
1899 * just been a locking failure */
1901 ReleaseReadLock(&tdc->lock);
1908 ReleaseReadLock(&afs_xdcache);
1911 /* No hint, or hint is no longer valid - see if we can get something
1912 * directly from the dcache
1915 tdc = afs_FindDCache(avc, offset);
1918 ReleaseWriteLock(&avc->lock);
1923 ObtainReadLock(&tdc->lock);
1925 /* Is the dcache we've been given currently up to date */
1926 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1927 (tdc->dflags & DFFetching)) {
1928 ReleaseWriteLock(&avc->lock);
1929 ReleaseReadLock(&tdc->lock);
1934 /* Update our hint for future abuse */
1937 /* Okay, so we've now got a cache file that is up to date */
1939 /* XXX - I suspect we should be locking the inodes before we use them! */
1941 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1942 pagevec_init(&lrupv, 0);
1944 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1946 if (pagevec_count(&lrupv))
1947 __pagevec_lru_add_file(&lrupv);
1949 filp_close(cacheFp, NULL);
1952 ReleaseReadLock(&tdc->lock);
1953 ReleaseWriteLock(&avc->lock);
1960 /* afs_linux_readpage
1962 * This function is split into two, because prepare_write/begin_write
1963 * require a readpage call which doesn't unlock the resulting page upon
1967 afs_linux_fillpage(struct file *fp, struct page *pp)
1972 struct iovec *iovecp;
1973 struct inode *ip = FILE_INODE(fp);
1974 afs_int32 cnt = page_count(pp);
1975 struct vcache *avc = VTOAFS(ip);
1976 afs_offs_t offset = page_offset(pp);
1980 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1990 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1991 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
1993 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1998 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1999 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2000 99999); /* not a possible code value */
2002 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
2004 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
2005 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
2007 AFS_DISCON_UNLOCK();
2010 /* XXX valid for no-cache also? Check last bits of files... :)
2011 * Cognate code goes in afs_NoCacheFetchProc. */
2012 if (auio->uio_resid) /* zero remainder of page */
2013 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
2016 flush_dcache_page(pp);
2017 SetPageUptodate(pp);
2026 return afs_convert_code(code);
2030 afs_linux_prefetch(struct file *fp, struct page *pp)
2033 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2034 afs_offs_t offset = page_offset(pp);
2036 if (AFS_CHUNKOFFSET(offset) == 0) {
2038 struct vrequest treq;
2043 code = afs_InitReq(&treq, credp);
2044 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2045 tdc = afs_FindDCache(avc, offset);
2047 if (!(tdc->mflags & DFNextStarted))
2048 afs_PrefetchChunk(avc, tdc, credp, &treq);
2051 ReleaseWriteLock(&avc->lock);
2056 return afs_convert_code(code);
2061 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2062 struct list_head *page_list, unsigned num_pages)
2067 struct iovec* iovecp;
2068 struct nocache_read_request *ancr;
2070 struct pagevec lrupv;
2074 struct inode *ip = FILE_INODE(fp);
2075 struct vcache *avc = VTOAFS(ip);
2076 afs_int32 base_index = 0;
2077 afs_int32 page_count = 0;
2080 /* background thread must free: iovecp, auio, ancr */
2081 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2083 auio = osi_Alloc(sizeof(struct uio));
2084 auio->uio_iov = iovecp;
2085 auio->uio_iovcnt = num_pages;
2086 auio->uio_flag = UIO_READ;
2087 auio->uio_seg = AFS_UIOSYS;
2088 auio->uio_resid = num_pages * PAGE_SIZE;
2090 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2092 ancr->offset = auio->uio_offset;
2093 ancr->length = auio->uio_resid;
2095 pagevec_init(&lrupv, 0);
2097 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2099 if(list_empty(page_list))
2102 pp = list_entry(page_list->prev, struct page, lru);
2103 /* If we allocate a page and don't remove it from page_list,
2104 * the page cache gets upset. */
2106 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2107 if(pp->index > isize) {
2114 offset = page_offset(pp);
2115 ancr->offset = auio->uio_offset = offset;
2116 base_index = pp->index;
2118 iovecp[page_ix].iov_len = PAGE_SIZE;
2119 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2120 if(base_index != pp->index) {
2123 page_cache_release(pp);
2124 iovecp[page_ix].iov_base = (void *) 0;
2126 ancr->length -= PAGE_SIZE;
2133 page_cache_release(pp);
2134 iovecp[page_ix].iov_base = (void *) 0;
2137 if(!PageLocked(pp)) {
2141 /* increment page refcount--our original design assumed
2142 * that locking it would effectively pin it; protect
2143 * ourselves from the possiblity that this assumption is
2144 * is faulty, at low cost (provided we do not fail to
2145 * do the corresponding decref on the other side) */
2148 /* save the page for background map */
2149 iovecp[page_ix].iov_base = (void*) pp;
2151 /* and put it on the LRU cache */
2152 if (!pagevec_add(&lrupv, pp))
2153 __pagevec_lru_add_file(&lrupv);
2157 /* If there were useful pages in the page list, make sure all pages
2158 * are in the LRU cache, then schedule the read */
2160 if (pagevec_count(&lrupv))
2161 __pagevec_lru_add_file(&lrupv);
2163 code = afs_ReadNoCache(avc, ancr, credp);
2166 /* If there is nothing for the background thread to handle,
2167 * it won't be freeing the things that we never gave it */
2168 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2169 osi_Free(auio, sizeof(struct uio));
2170 osi_Free(ancr, sizeof(struct nocache_read_request));
2172 /* we do not flush, release, or unmap pages--that will be
2173 * done for us by the background thread as each page comes in
2174 * from the fileserver */
2175 return afs_convert_code(code);
2180 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2182 cred_t *credp = NULL;
2184 struct iovec *iovecp;
2185 struct nocache_read_request *ancr;
2189 * Special case: if page is at or past end of file, just zero it and set
2192 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2193 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2194 SetPageUptodate(pp);
2201 /* receiver frees */
2202 auio = osi_Alloc(sizeof(struct uio));
2203 iovecp = osi_Alloc(sizeof(struct iovec));
2205 /* address can be NULL, because we overwrite it with 'pp', below */
2206 setup_uio(auio, iovecp, NULL, page_offset(pp),
2207 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2209 /* save the page for background map */
2210 get_page(pp); /* see above */
2211 auio->uio_iov->iov_base = (void*) pp;
2212 /* the background thread will free this */
2213 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2215 ancr->offset = page_offset(pp);
2216 ancr->length = PAGE_SIZE;
2219 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2222 return afs_convert_code(code);
2226 afs_linux_can_bypass(struct inode *ip) {
2228 switch(cache_bypass_strategy) {
2229 case NEVER_BYPASS_CACHE:
2231 case ALWAYS_BYPASS_CACHE:
2233 case LARGE_FILES_BYPASS_CACHE:
2234 if (i_size_read(ip) > cache_bypass_threshold)
2241 /* Check if a file is permitted to bypass the cache by policy, and modify
2242 * the cache bypass state recorded for that file */
2245 afs_linux_bypass_check(struct inode *ip) {
2248 int bypass = afs_linux_can_bypass(ip);
2251 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2259 afs_linux_readpage(struct file *fp, struct page *pp)
2263 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2264 code = afs_linux_bypass_readpage(fp, pp);
2266 code = afs_linux_fillpage(fp, pp);
2268 code = afs_linux_prefetch(fp, pp);
2275 /* Readpages reads a number of pages for a particular file. We use
2276 * this to optimise the reading, by limiting the number of times upon which
2277 * we have to lookup, lock and open vcaches and dcaches
2281 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2282 struct list_head *page_list, unsigned int num_pages)
2284 struct inode *inode = mapping->host;
2285 struct vcache *avc = VTOAFS(inode);
2287 struct file *cacheFp = NULL;
2289 unsigned int page_idx;
2291 struct pagevec lrupv;
2292 struct afs_pagecopy_task *task;
2294 if (afs_linux_bypass_check(inode))
2295 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2297 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2301 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2306 ObtainWriteLock(&avc->lock, 912);
2309 task = afs_pagecopy_init_task();
2312 pagevec_init(&lrupv, 0);
2313 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2314 struct page *page = list_entry(page_list->prev, struct page, lru);
2315 list_del(&page->lru);
2316 offset = page_offset(page);
2318 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2320 ReleaseReadLock(&tdc->lock);
2325 filp_close(cacheFp, NULL);
2330 if ((tdc = afs_FindDCache(avc, offset))) {
2331 ObtainReadLock(&tdc->lock);
2332 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2333 (tdc->dflags & DFFetching)) {
2334 ReleaseReadLock(&tdc->lock);
2341 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2344 if (tdc && !add_to_page_cache(page, mapping, page->index,
2346 page_cache_get(page);
2347 if (!pagevec_add(&lrupv, page))
2348 __pagevec_lru_add_file(&lrupv);
2350 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2352 page_cache_release(page);
2354 if (pagevec_count(&lrupv))
2355 __pagevec_lru_add_file(&lrupv);
2358 filp_close(cacheFp, NULL);
2360 afs_pagecopy_put_task(task);
2364 ReleaseReadLock(&tdc->lock);
2368 ReleaseWriteLock(&avc->lock);
2373 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2376 afs_linux_prepare_writeback(struct vcache *avc) {
2377 if (avc->f.states & CPageWrite) {
2378 return AOP_WRITEPAGE_ACTIVATE;
2380 avc->f.states |= CPageWrite;
2385 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2386 struct vrequest treq;
2389 if (!afs_InitReq(&treq, credp))
2390 code = afs_DoPartialWrite(avc, &treq);
2392 return afs_convert_code(code);
2396 afs_linux_complete_writeback(struct vcache *avc) {
2397 avc->f.states &= ~CPageWrite;
2400 /* Writeback a given page syncronously. Called with no AFS locks held */
2402 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2403 unsigned long offset, unsigned int count,
2406 struct vcache *vcp = VTOAFS(ip);
2414 buffer = kmap(pp) + offset;
2415 base = page_offset(pp) + offset;
2418 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2419 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2420 ICL_TYPE_INT32, 99999);
2422 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2424 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2426 i_size_write(ip, vcp->f.m.Length);
2427 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2429 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
2431 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2432 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2433 ICL_TYPE_INT32, code);
2442 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2443 unsigned long offset, unsigned int count)
2447 struct vcache *vcp = VTOAFS(ip);
2450 /* Catch recursive writeback. This occurs if the kernel decides
2451 * writeback is required whilst we are writing to the cache, or
2452 * flushing to the server. When we're running syncronously (as
2453 * opposed to from writepage) we can't actually do anything about
2454 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2457 ObtainWriteLock(&vcp->lock, 532);
2458 afs_linux_prepare_writeback(vcp);
2459 ReleaseWriteLock(&vcp->lock);
2463 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2466 ObtainWriteLock(&vcp->lock, 533);
2468 code1 = afs_linux_dopartialwrite(vcp, credp);
2469 afs_linux_complete_writeback(vcp);
2470 ReleaseWriteLock(&vcp->lock);
2481 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2482 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2484 afs_linux_writepage(struct page *pp)
2487 struct address_space *mapping = pp->mapping;
2488 struct inode *inode;
2491 unsigned int to = PAGE_CACHE_SIZE;
2496 if (PageReclaim(pp)) {
2497 return AOP_WRITEPAGE_ACTIVATE;
2498 /* XXX - Do we need to redirty the page here? */
2503 inode = mapping->host;
2504 vcp = VTOAFS(inode);
2505 isize = i_size_read(inode);
2507 /* Don't defeat an earlier truncate */
2508 if (page_offset(pp) > isize) {
2509 set_page_writeback(pp);
2515 ObtainWriteLock(&vcp->lock, 537);
2516 code = afs_linux_prepare_writeback(vcp);
2517 if (code == AOP_WRITEPAGE_ACTIVATE) {
2518 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2519 * to return with the page still locked */
2520 ReleaseWriteLock(&vcp->lock);
2525 /* Grab the creds structure currently held in the vnode, and
2526 * get a reference to it, in case it goes away ... */
2532 ReleaseWriteLock(&vcp->lock);
2535 set_page_writeback(pp);
2537 SetPageUptodate(pp);
2539 /* We can unlock the page here, because it's protected by the
2540 * page_writeback flag. This should make us less vulnerable to
2541 * deadlocking in afs_write and afs_DoPartialWrite
2545 /* If this is the final page, then just write the number of bytes that
2546 * are actually in it */
2547 if ((isize - page_offset(pp)) < to )
2548 to = isize - page_offset(pp);
2550 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2553 ObtainWriteLock(&vcp->lock, 538);
2555 /* As much as we might like to ignore a file server error here,
2556 * and just try again when we close(), unfortunately StoreAllSegments
2557 * will invalidate our chunks if the server returns a permanent error,
2558 * so we need to at least try and get that error back to the user
2561 code1 = afs_linux_dopartialwrite(vcp, credp);
2563 afs_linux_complete_writeback(vcp);
2564 ReleaseWriteLock(&vcp->lock);
2569 end_page_writeback(pp);
2570 page_cache_release(pp);
2581 /* afs_linux_permission
2582 * Check access rights - returns error if can't check or permission denied.
2585 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2586 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2587 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2588 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2590 afs_linux_permission(struct inode *ip, int mode)
2597 /* Check for RCU path walking */
2598 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2599 if (flags & IPERM_FLAG_RCU)
2601 #elif defined(MAY_NOT_BLOCK)
2602 if (mode & MAY_NOT_BLOCK)
2608 if (mode & MAY_EXEC)
2610 if (mode & MAY_READ)
2612 if (mode & MAY_WRITE)
2614 code = afs_access(VTOAFS(ip), tmp, credp);
2618 return afs_convert_code(code);
2622 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2626 struct inode *inode = FILE_INODE(file);
2627 loff_t pagebase = page_offset(page);
2629 if (i_size_read(inode) < (pagebase + offset))
2630 i_size_write(inode, pagebase + offset);
2632 if (PageChecked(page)) {
2633 SetPageUptodate(page);
2634 ClearPageChecked(page);
2637 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2643 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2647 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2648 * prepare_write. Essentially, if the page exists within the file,
2649 * and is not being fully written, then we should populate it.
2652 if (!PageUptodate(page)) {
2653 loff_t pagebase = page_offset(page);
2654 loff_t isize = i_size_read(page->mapping->host);
2656 /* Is the location we are writing to beyond the end of the file? */
2657 if (pagebase >= isize ||
2658 ((from == 0) && (pagebase + to) >= isize)) {
2659 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2660 SetPageChecked(page);
2661 /* Are we we writing a full page */
2662 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2663 SetPageChecked(page);
2664 /* Is the page readable, if it's wronly, we don't care, because we're
2665 * not actually going to read from it ... */
2666 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2667 /* We don't care if fillpage fails, because if it does the page
2668 * won't be marked as up to date
2670 afs_linux_fillpage(file, page);
2676 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2678 afs_linux_write_end(struct file *file, struct address_space *mapping,
2679 loff_t pos, unsigned len, unsigned copied,
2680 struct page *page, void *fsdata)
2683 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2685 code = afs_linux_commit_write(file, page, from, from + len);
2688 page_cache_release(page);
2693 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2694 loff_t pos, unsigned len, unsigned flags,
2695 struct page **pagep, void **fsdata)
2698 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2699 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2702 page = grab_cache_page_write_begin(mapping, index, flags);
2705 code = afs_linux_prepare_write(file, page, from, from + len);
2708 page_cache_release(page);
2715 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2717 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2719 struct dentry **dpp;
2720 struct dentry *target;
2722 if (current->total_link_count > 0) {
2723 /* avoid symlink resolution limits when resolving; we cannot contribute to
2724 * an infinite symlink loop */
2725 /* only do this for follow_link when total_link_count is positive to be
2726 * on the safe side; there is at least one code path in the Linux
2727 * kernel where it seems like it may be possible to get here without
2728 * total_link_count getting incremented. it is not clear on how that
2729 * path is actually reached, but guard against it just to be safe */
2730 current->total_link_count--;
2733 target = canonical_dentry(dentry->d_inode);
2735 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2736 dpp = &nd->path.dentry;
2746 *dpp = dget(dentry);
2749 nd->last_type = LAST_BIND;
2753 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2756 static struct inode_operations afs_file_iops = {
2757 .permission = afs_linux_permission,
2758 .getattr = afs_linux_getattr,
2759 .setattr = afs_notify_change,
2762 static struct address_space_operations afs_file_aops = {
2763 .readpage = afs_linux_readpage,
2764 .readpages = afs_linux_readpages,
2765 .writepage = afs_linux_writepage,
2766 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2767 .write_begin = afs_linux_write_begin,
2768 .write_end = afs_linux_write_end,
2770 .commit_write = afs_linux_commit_write,
2771 .prepare_write = afs_linux_prepare_write,
2776 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2777 * by what sort of operation is allowed.....
2780 static struct inode_operations afs_dir_iops = {
2781 .setattr = afs_notify_change,
2782 .create = afs_linux_create,
2783 .lookup = afs_linux_lookup,
2784 .link = afs_linux_link,
2785 .unlink = afs_linux_unlink,
2786 .symlink = afs_linux_symlink,
2787 .mkdir = afs_linux_mkdir,
2788 .rmdir = afs_linux_rmdir,
2789 .rename = afs_linux_rename,
2790 .getattr = afs_linux_getattr,
2791 .permission = afs_linux_permission,
2792 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2793 .follow_link = afs_linux_dir_follow_link,
2797 /* We really need a separate symlink set of ops, since do_follow_link()
2798 * determines if it _is_ a link by checking if the follow_link op is set.
2800 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2802 afs_symlink_filler(struct file *file, struct page *page)
2804 struct inode *ip = (struct inode *)page->mapping->host;
2805 char *p = (char *)kmap(page);
2809 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2814 p[code] = '\0'; /* null terminate? */
2816 SetPageUptodate(page);
2828 static struct address_space_operations afs_symlink_aops = {
2829 .readpage = afs_symlink_filler
2831 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2833 static struct inode_operations afs_symlink_iops = {
2834 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2835 .readlink = page_readlink,
2836 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2837 .follow_link = page_follow_link,
2839 .follow_link = page_follow_link_light,
2840 .put_link = page_put_link,
2842 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2843 .readlink = afs_linux_readlink,
2844 .follow_link = afs_linux_follow_link,
2845 .put_link = afs_linux_put_link,
2846 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2847 .setattr = afs_notify_change,
2851 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2855 vattr2inode(ip, vattr);
2857 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2858 /* Reset ops if symlink or directory. */
2859 if (S_ISREG(ip->i_mode)) {
2860 ip->i_op = &afs_file_iops;
2861 ip->i_fop = &afs_file_fops;
2862 ip->i_data.a_ops = &afs_file_aops;
2864 } else if (S_ISDIR(ip->i_mode)) {
2865 ip->i_op = &afs_dir_iops;
2866 ip->i_fop = &afs_dir_fops;
2868 } else if (S_ISLNK(ip->i_mode)) {
2869 ip->i_op = &afs_symlink_iops;
2870 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2871 ip->i_data.a_ops = &afs_symlink_aops;
2872 ip->i_mapping = &ip->i_data;