2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Linux specific vnodeops. Also includes the glue routines required to call
14 * So far the only truly scary part is that Linux relies on the inode cache
15 * to be up to date. Don't you dare break a callback and expect an fstat
16 * to give you meaningful information. This appears to be fixed in the 2.1
17 * development kernels. As it is we can fix this now by intercepting the
21 #include <afsconfig.h>
22 #include "afs/param.h"
25 #include "afs/sysincludes.h"
26 #include "afsincludes.h"
27 #include "afs/afs_stats.h"
29 #ifdef HAVE_MM_INLINE_H
30 #include <linux/mm_inline.h>
32 #include <linux/pagemap.h>
33 #include <linux/writeback.h>
34 #include <linux/pagevec.h>
36 #include "afs/afs_bypasscache.h"
38 #include "osi_compat.h"
39 #include "osi_pagecopy.h"
41 #ifndef HAVE_LINUX_PAGEVEC_LRU_ADD_FILE
42 #define __pagevec_lru_add_file __pagevec_lru_add
46 #define MAX_ERRNO 1000L
49 extern struct backing_dev_info *afs_backing_dev_info;
51 extern struct vcache *afs_globalVp;
53 /* This function converts a positive error code from AFS into a negative
54 * code suitable for passing into the Linux VFS layer. It checks that the
55 * error code is within the permissable bounds for the ERR_PTR mechanism.
57 * _All_ error codes which come from the AFS layer should be passed through
58 * this function before being returned to the kernel.
62 afs_convert_code(int code) {
63 if ((code >= 0) && (code <= MAX_ERRNO))
69 /* Linux doesn't require a credp for many functions, and crref is an expensive
70 * operation. This helper function avoids obtaining it for VerifyVCache calls
74 afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
79 if (avc->f.states & CStatd) {
87 code = afs_InitReq(&treq, credp);
89 code = afs_VerifyVCache2(avc, &treq);
96 return afs_convert_code(code);
99 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
101 afs_linux_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long segs, loff_t pos)
103 struct file *fp = iocb->ki_filp;
105 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
108 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
109 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
111 code = afs_linux_VerifyVCache(vcp, NULL);
114 /* Linux's FlushPages implementation doesn't ever use credp,
115 * so we optimise by not using it */
116 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
118 code = generic_file_aio_read(iocb, iov, segs, pos);
122 afs_Trace4(afs_iclSetp, CM_TRACE_AIOREADOP, ICL_TYPE_POINTER, vcp,
123 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
130 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
133 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
136 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
137 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
139 code = afs_linux_VerifyVCache(vcp, NULL);
142 /* Linux's FlushPages implementation doesn't ever use credp,
143 * so we optimise by not using it */
144 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
146 code = do_sync_read(fp, buf, count, offp);
150 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
151 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
159 /* Now we have integrated VM for writes as well as reads. the generic write operations
160 * also take care of re-positioning the pointer if file is open in append
161 * mode. Call fake open/close to ensure we do writes of core dumps.
163 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
165 afs_linux_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long segs, loff_t pos)
168 struct vcache *vcp = VTOAFS(iocb->ki_filp->f_dentry->d_inode);
173 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
174 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
175 (iocb->ki_filp->f_flags & O_APPEND) ? 99998 : 99999);
177 code = afs_linux_VerifyVCache(vcp, &credp);
179 ObtainWriteLock(&vcp->lock, 529);
181 ReleaseWriteLock(&vcp->lock);
184 code = generic_file_aio_write(iocb, iov, segs, pos);
188 ObtainWriteLock(&vcp->lock, 530);
190 if (vcp->execsOrWriters == 1 && !credp)
193 afs_FakeClose(vcp, credp);
194 ReleaseWriteLock(&vcp->lock);
196 afs_Trace4(afs_iclSetp, CM_TRACE_AIOWRITEOP, ICL_TYPE_POINTER, vcp,
197 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(pos), ICL_TYPE_INT32, segs, ICL_TYPE_INT32,
207 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
210 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
215 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
216 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
217 (fp->f_flags & O_APPEND) ? 99998 : 99999);
219 code = afs_linux_VerifyVCache(vcp, &credp);
221 ObtainWriteLock(&vcp->lock, 529);
223 ReleaseWriteLock(&vcp->lock);
226 code = do_sync_write(fp, buf, count, offp);
230 ObtainWriteLock(&vcp->lock, 530);
232 if (vcp->execsOrWriters == 1 && !credp)
235 afs_FakeClose(vcp, credp);
236 ReleaseWriteLock(&vcp->lock);
238 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
239 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
249 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
251 /* This is a complete rewrite of afs_readdir, since we can make use of
252 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
253 * handling and use of bulkstats will need to be reflected here as well.
256 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
258 struct vcache *avc = VTOAFS(FILE_INODE(fp));
259 struct vrequest treq;
265 struct DirBuffer entry;
268 afs_size_t origOffset, tlen;
269 cred_t *credp = crref();
270 struct afs_fakestat_state fakestat;
273 AFS_STATCNT(afs_readdir);
275 code = afs_convert_code(afs_InitReq(&treq, credp));
280 afs_InitFakeStat(&fakestat);
281 code = afs_convert_code(afs_EvalFakeStat(&avc, &fakestat, &treq));
285 /* update the cache entry */
287 code = afs_convert_code(afs_VerifyVCache2(avc, &treq));
291 /* get a reference to the entire directory */
292 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
298 ObtainWriteLock(&avc->lock, 811);
299 ObtainReadLock(&tdc->lock);
301 * Make sure that the data in the cache is current. There are two
302 * cases we need to worry about:
303 * 1. The cache data is being fetched by another process.
304 * 2. The cache data is no longer valid
306 while ((avc->f.states & CStatd)
307 && (tdc->dflags & DFFetching)
308 && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
309 ReleaseReadLock(&tdc->lock);
310 ReleaseWriteLock(&avc->lock);
311 afs_osi_Sleep(&tdc->validPos);
312 ObtainWriteLock(&avc->lock, 812);
313 ObtainReadLock(&tdc->lock);
315 if (!(avc->f.states & CStatd)
316 || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
317 ReleaseReadLock(&tdc->lock);
318 ReleaseWriteLock(&avc->lock);
323 /* Set the readdir-in-progress flag, and downgrade the lock
324 * to shared so others will be able to acquire a read lock.
326 avc->f.states |= CReadDir;
327 avc->dcreaddir = tdc;
328 avc->readdir_pid = MyPidxx2Pid(MyPidxx);
329 ConvertWToSLock(&avc->lock);
331 /* Fill in until we get an error or we're done. This implementation
332 * takes an offset in units of blobs, rather than bytes.
335 offset = (int) fp->f_pos;
337 dirpos = BlobScan(tdc, offset);
341 code = afs_dir_GetVerifiedBlob(tdc, dirpos, &entry);
343 afs_warn("Corrupt directory (inode %lx, dirpos %d)",
344 (unsigned long)&tdc->f.inode, dirpos);
345 ReleaseSharedLock(&avc->lock);
351 de = (struct DirEntry *)entry.data;
352 ino = afs_calc_inum (avc->f.fid.Cell, avc->f.fid.Fid.Volume,
353 ntohl(de->fid.vnode));
354 len = strlen(de->name);
356 /* filldir returns -EINVAL when the buffer is full. */
358 unsigned int type = DT_UNKNOWN;
359 struct VenusFid afid;
362 afid.Cell = avc->f.fid.Cell;
363 afid.Fid.Volume = avc->f.fid.Fid.Volume;
364 afid.Fid.Vnode = ntohl(de->fid.vnode);
365 afid.Fid.Unique = ntohl(de->fid.vunique);
366 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
368 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
371 } else if (((tvc->f.states) & (CStatd | CTruth))) {
372 /* CTruth will be set if the object has
377 else if (vtype == VREG)
379 /* Don't do this until we're sure it can't be a mtpt */
380 /* else if (vtype == VLNK)
382 /* what other types does AFS support? */
384 /* clean up from afs_FindVCache */
388 * If this is NFS readdirplus, then the filler is going to
389 * call getattr on this inode, which will deadlock if we're
393 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
399 offset = dirpos + 1 + ((len + 16) >> 5);
401 /* If filldir didn't fill in the last one this is still pointing to that
404 fp->f_pos = (loff_t) offset;
406 ReleaseReadLock(&tdc->lock);
408 UpgradeSToWLock(&avc->lock, 813);
409 avc->f.states &= ~CReadDir;
411 avc->readdir_pid = 0;
412 ReleaseSharedLock(&avc->lock);
416 afs_PutFakeStat(&fakestat);
423 /* in afs_pioctl.c */
424 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
427 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
428 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
430 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
437 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
439 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
443 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
444 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
445 vmap->vm_end - vmap->vm_start);
447 /* get a validated vcache entry */
448 code = afs_linux_VerifyVCache(vcp, NULL);
451 /* Linux's Flushpage implementation doesn't use credp, so optimise
452 * our code to not need to crref() it */
453 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
455 code = generic_file_mmap(fp, vmap);
458 vcp->f.states |= CMAPPED;
466 afs_linux_open(struct inode *ip, struct file *fp)
468 struct vcache *vcp = VTOAFS(ip);
469 cred_t *credp = crref();
473 code = afs_open(&vcp, fp->f_flags, credp);
477 return afs_convert_code(code);
481 afs_linux_release(struct inode *ip, struct file *fp)
483 struct vcache *vcp = VTOAFS(ip);
484 cred_t *credp = crref();
488 code = afs_close(vcp, fp->f_flags, credp);
489 ObtainWriteLock(&vcp->lock, 807);
494 ReleaseWriteLock(&vcp->lock);
498 return afs_convert_code(code);
502 #if defined(FOP_FSYNC_TAKES_DENTRY)
503 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
504 #elif defined(FOP_FSYNC_TAKES_RANGE)
505 afs_linux_fsync(struct file *fp, loff_t start, loff_t end, int datasync)
507 afs_linux_fsync(struct file *fp, int datasync)
511 struct inode *ip = FILE_INODE(fp);
512 cred_t *credp = crref();
514 #if defined(FOP_FSYNC_TAKES_RANGE)
515 mutex_lock(&ip->i_mutex);
518 code = afs_fsync(VTOAFS(ip), credp);
520 #if defined(FOP_FSYNC_TAKES_RANGE)
521 mutex_unlock(&ip->i_mutex);
524 return afs_convert_code(code);
530 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
533 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
534 cred_t *credp = crref();
535 struct AFS_FLOCK flock;
537 /* Convert to a lock format afs_lockctl understands. */
538 memset(&flock, 0, sizeof(flock));
539 flock.l_type = flp->fl_type;
540 flock.l_pid = flp->fl_pid;
542 flock.l_start = flp->fl_start;
543 if (flp->fl_end == OFFSET_MAX)
544 flock.l_len = 0; /* Lock to end of file */
546 flock.l_len = flp->fl_end - flp->fl_start + 1;
548 /* Safe because there are no large files, yet */
549 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
550 if (cmd == F_GETLK64)
552 else if (cmd == F_SETLK64)
554 else if (cmd == F_SETLKW64)
556 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
559 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
562 if ((code == 0 || flp->fl_type == F_UNLCK) &&
563 (cmd == F_SETLK || cmd == F_SETLKW)) {
564 code = afs_posix_lock_file(fp, flp);
565 if (code && flp->fl_type != F_UNLCK) {
566 struct AFS_FLOCK flock2;
568 flock2.l_type = F_UNLCK;
570 afs_lockctl(vcp, &flock2, F_SETLK, credp);
574 /* If lockctl says there are no conflicting locks, then also check with the
575 * kernel, as lockctl knows nothing about byte range locks
577 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
578 afs_posix_test_lock(fp, flp);
579 /* If we found a lock in the kernel's structure, return it */
580 if (flp->fl_type != F_UNLCK) {
586 /* Convert flock back to Linux's file_lock */
587 flp->fl_type = flock.l_type;
588 flp->fl_pid = flock.l_pid;
589 flp->fl_start = flock.l_start;
590 if (flock.l_len == 0)
591 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
593 flp->fl_end = flock.l_start + flock.l_len - 1;
599 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
601 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
603 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
604 cred_t *credp = crref();
605 struct AFS_FLOCK flock;
606 /* Convert to a lock format afs_lockctl understands. */
607 memset(&flock, 0, sizeof(flock));
608 flock.l_type = flp->fl_type;
609 flock.l_pid = flp->fl_pid;
614 /* Safe because there are no large files, yet */
615 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
616 if (cmd == F_GETLK64)
618 else if (cmd == F_SETLK64)
620 else if (cmd == F_SETLKW64)
622 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
625 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
628 if ((code == 0 || flp->fl_type == F_UNLCK) &&
629 (cmd == F_SETLK || cmd == F_SETLKW)) {
630 flp->fl_flags &=~ FL_SLEEP;
631 code = flock_lock_file_wait(fp, flp);
632 if (code && flp->fl_type != F_UNLCK) {
633 struct AFS_FLOCK flock2;
635 flock2.l_type = F_UNLCK;
637 afs_lockctl(vcp, &flock2, F_SETLK, credp);
641 /* Convert flock back to Linux's file_lock */
642 flp->fl_type = flock.l_type;
643 flp->fl_pid = flock.l_pid;
651 * essentially the same as afs_fsync() but we need to get the return
652 * code for the sys_close() here, not afs_linux_release(), so call
653 * afs_StoreAllSegments() with AFS_LASTSTORE
656 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
657 afs_linux_flush(struct file *fp, fl_owner_t id)
659 afs_linux_flush(struct file *fp)
662 struct vrequest treq;
670 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
678 vcp = VTOAFS(FILE_INODE(fp));
680 code = afs_InitReq(&treq, credp);
683 /* If caching is bypassed for this file, or globally, just return 0 */
684 if (cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
687 ObtainReadLock(&vcp->lock);
688 if (vcp->cachingStates & FCSBypass)
690 ReleaseReadLock(&vcp->lock);
693 /* future proof: don't rely on 0 return from afs_InitReq */
698 ObtainSharedLock(&vcp->lock, 535);
699 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
700 UpgradeSToWLock(&vcp->lock, 536);
701 if (!AFS_IS_DISCONNECTED) {
702 code = afs_StoreAllSegments(vcp,
704 AFS_SYNC | AFS_LASTSTORE);
706 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
708 ConvertWToSLock(&vcp->lock);
710 code = afs_CheckCode(code, &treq, 54);
711 ReleaseSharedLock(&vcp->lock);
718 return afs_convert_code(code);
721 struct file_operations afs_dir_fops = {
722 .read = generic_read_dir,
723 .readdir = afs_linux_readdir,
724 #ifdef HAVE_UNLOCKED_IOCTL
725 .unlocked_ioctl = afs_unlocked_xioctl,
729 #ifdef HAVE_COMPAT_IOCTL
730 .compat_ioctl = afs_unlocked_xioctl,
732 .open = afs_linux_open,
733 .release = afs_linux_release,
734 .llseek = default_llseek,
735 #ifdef HAVE_LINUX_NOOP_FSYNC
738 .fsync = simple_sync_file,
742 struct file_operations afs_file_fops = {
743 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
744 .aio_read = afs_linux_aio_read,
745 .aio_write = afs_linux_aio_write,
747 .read = afs_linux_read,
748 .write = afs_linux_write,
750 #ifdef HAVE_UNLOCKED_IOCTL
751 .unlocked_ioctl = afs_unlocked_xioctl,
755 #ifdef HAVE_COMPAT_IOCTL
756 .compat_ioctl = afs_unlocked_xioctl,
758 .mmap = afs_linux_mmap,
759 .open = afs_linux_open,
760 .flush = afs_linux_flush,
761 #if defined(STRUCT_FILE_OPERATIONS_HAS_SENDFILE)
762 .sendfile = generic_file_sendfile,
764 #if defined(STRUCT_FILE_OPERATIONS_HAS_SPLICE)
765 .splice_write = generic_file_splice_write,
766 .splice_read = generic_file_splice_read,
768 .release = afs_linux_release,
769 .fsync = afs_linux_fsync,
770 .lock = afs_linux_lock,
771 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
772 .flock = afs_linux_flock,
774 .llseek = default_llseek,
777 static struct dentry *
778 canonical_dentry(struct inode *ip)
780 struct vcache *vcp = VTOAFS(ip);
781 struct dentry *first = NULL, *ret = NULL, *cur;
782 #if defined(D_ALIAS_IS_HLIST)
783 struct hlist_node *p;
787 * if vcp->target_link is set, and can be found in ip->i_dentry, use that.
788 * otherwise, use the first dentry in ip->i_dentry.
789 * if ip->i_dentry is empty, use the 'dentry' argument we were given.
791 /* note that vcp->target_link specifies which dentry to use, but we have
792 * no reference held on that dentry. so, we cannot use or dereference
793 * vcp->target_link itself, since it may have been freed. instead, we only
794 * use it to compare to pointers in the ip->i_dentry list. */
798 # ifdef HAVE_DCACHE_LOCK
799 spin_lock(&dcache_lock);
801 spin_lock(&ip->i_lock);
804 #if defined(D_ALIAS_IS_HLIST)
805 hlist_for_each_entry(cur, p, &ip->i_dentry, d_alias) {
807 list_for_each_entry_reverse(cur, &ip->i_dentry, d_alias) {
810 if (!vcp->target_link || cur == vcp->target_link) {
823 vcp->target_link = ret;
825 # ifdef HAVE_DCACHE_LOCK
829 spin_unlock(&dcache_lock);
834 spin_unlock(&ip->i_lock);
840 /**********************************************************************
841 * AFS Linux dentry operations
842 **********************************************************************/
844 /* fix_bad_parent() : called if this dentry's vcache is a root vcache
845 * that has its mvid (parent dir's fid) pointer set to the wrong directory
846 * due to being mounted in multiple points at once. fix_bad_parent()
847 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
848 * dotdotfid and mtpoint fid members.
850 * dp - dentry to be checked.
851 * credp - credentials
852 * vcp, pvc - item's and parent's vcache pointer
856 * This dentry's vcache's mvid will be set to the correct parent directory's
858 * This root vnode's volume will have its dotdotfid and mtpoint fids set
859 * to the correct parent and mountpoint fids.
863 fix_bad_parent(struct dentry *dp, cred_t *credp, struct vcache *vcp, struct vcache *pvc)
865 struct vcache *avc = NULL;
867 /* force a lookup, so vcp->mvid is fixed up */
868 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
869 if (!avc || vcp != avc) { /* bad, very bad.. */
870 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
871 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
872 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
873 ICL_TYPE_POINTER, dp);
876 AFS_RELE(AFSTOV(avc));
881 /* afs_linux_revalidate
882 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
885 afs_linux_revalidate(struct dentry *dp)
888 struct vcache *vcp = VTOAFS(dp->d_inode);
892 if (afs_shuttingdown)
898 /* Make this a fast path (no crref), since it's called so often. */
899 if (vcp->states & CStatd) {
900 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
902 if (*dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
903 if (vcp->mvid->Fid.Volume != pvc->fid.Fid.Volume) { /* bad parent */
906 fix_bad_parent(dp); /* check and correct mvid */
915 /* This avoids the crref when we don't have to do it. Watch for
916 * changes in afs_getattr that don't get replicated here!
918 if (vcp->f.states & CStatd &&
919 (!afs_fakestat_enable || vcp->mvstat != 1) &&
921 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
922 code = afs_CopyOutAttrs(vcp, &vattr);
925 code = afs_getattr(vcp, &vattr, credp);
930 afs_fill_inode(AFSTOV(vcp), &vattr);
934 return afs_convert_code(code);
938 * Set iattr data into vattr. Assume vattr cleared before call.
941 iattr2vattr(struct vattr *vattrp, struct iattr *iattrp)
943 vattrp->va_mask = iattrp->ia_valid;
944 if (iattrp->ia_valid & ATTR_MODE)
945 vattrp->va_mode = iattrp->ia_mode;
946 if (iattrp->ia_valid & ATTR_UID)
947 vattrp->va_uid = iattrp->ia_uid;
948 if (iattrp->ia_valid & ATTR_GID)
949 vattrp->va_gid = iattrp->ia_gid;
950 if (iattrp->ia_valid & ATTR_SIZE)
951 vattrp->va_size = iattrp->ia_size;
952 if (iattrp->ia_valid & ATTR_ATIME) {
953 vattrp->va_atime.tv_sec = iattrp->ia_atime.tv_sec;
954 vattrp->va_atime.tv_usec = 0;
956 if (iattrp->ia_valid & ATTR_MTIME) {
957 vattrp->va_mtime.tv_sec = iattrp->ia_mtime.tv_sec;
958 vattrp->va_mtime.tv_usec = 0;
960 if (iattrp->ia_valid & ATTR_CTIME) {
961 vattrp->va_ctime.tv_sec = iattrp->ia_ctime.tv_sec;
962 vattrp->va_ctime.tv_usec = 0;
967 * Rewrite the inode cache from the attr. Assumes all vattr fields are valid.
970 vattr2inode(struct inode *ip, struct vattr *vp)
972 ip->i_ino = vp->va_nodeid;
973 #ifdef HAVE_LINUX_SET_NLINK
974 set_nlink(ip, vp->va_nlink);
976 ip->i_nlink = vp->va_nlink;
978 ip->i_blocks = vp->va_blocks;
979 #ifdef STRUCT_INODE_HAS_I_BLKBITS
980 ip->i_blkbits = AFS_BLKBITS;
982 #ifdef STRUCT_INODE_HAS_I_BLKSIZE
983 ip->i_blksize = vp->va_blocksize;
985 ip->i_rdev = vp->va_rdev;
986 ip->i_mode = vp->va_mode;
987 ip->i_uid = vp->va_uid;
988 ip->i_gid = vp->va_gid;
989 i_size_write(ip, vp->va_size);
990 ip->i_atime.tv_sec = vp->va_atime.tv_sec;
991 ip->i_atime.tv_nsec = 0;
992 ip->i_mtime.tv_sec = vp->va_mtime.tv_sec;
993 /* Set the mtime nanoseconds to the sysname generation number.
994 * This convinces NFS clients that all directories have changed
995 * any time the sysname list changes.
997 ip->i_mtime.tv_nsec = afs_sysnamegen;
998 ip->i_ctime.tv_sec = vp->va_ctime.tv_sec;
999 ip->i_ctime.tv_nsec = 0;
1002 /* afs_notify_change
1003 * Linux version of setattr call. What to change is in the iattr struct.
1004 * We need to set bits in both the Linux inode as well as the vcache.
1007 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
1010 cred_t *credp = crref();
1011 struct inode *ip = dp->d_inode;
1015 iattr2vattr(&vattr, iattrp); /* Convert for AFS vnodeops call. */
1018 code = afs_setattr(VTOAFS(ip), &vattr, credp);
1020 afs_getattr(VTOAFS(ip), &vattr, credp);
1021 vattr2inode(ip, &vattr);
1025 return afs_convert_code(code);
1029 afs_linux_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
1031 int err = afs_linux_revalidate(dentry);
1033 generic_fillattr(dentry->d_inode, stat);
1038 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
1039 * In kernels 2.2.10 and above, we are passed an additional flags var which
1040 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
1041 * we are advised to follow the entry if it is a link or to make sure that
1042 * it is a directory. But since the kernel itself checks these possibilities
1043 * later on, we shouldn't have to do it until later. Perhaps in the future..
1045 * The code here assumes that on entry the global lock is not held
1048 #if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1049 afs_linux_dentry_revalidate(struct dentry *dp, unsigned int flags)
1050 #elif defined(DOP_REVALIDATE_TAKES_NAMEIDATA)
1051 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
1053 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
1057 cred_t *credp = NULL;
1058 struct vcache *vcp, *pvcp, *tvc = NULL;
1059 struct dentry *parent;
1061 struct afs_fakestat_state fakestate;
1065 /* We don't support RCU path walking */
1066 # if defined(DOP_REVALIDATE_TAKES_UNSIGNED)
1067 if (flags & LOOKUP_RCU)
1069 if (nd->flags & LOOKUP_RCU)
1074 afs_InitFakeStat(&fakestate);
1077 vcp = VTOAFS(dp->d_inode);
1079 if (vcp == afs_globalVp)
1082 parent = dget_parent(dp);
1083 pvcp = VTOAFS(parent->d_inode);
1085 if ((vcp->mvstat == 1) || (vcp->mvstat == 2)) { /* need to lock */
1091 if (locked && vcp->mvstat == 1) { /* mount point */
1092 if (vcp->mvid && (vcp->f.states & CMValid)) {
1093 int tryEvalOnly = 0;
1095 struct vrequest treq;
1097 code = afs_InitReq(&treq, credp);
1099 (strcmp(dp->d_name.name, ".directory") == 0)) {
1103 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
1105 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
1106 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
1107 /* a mount point, not yet replaced by its directory */
1112 if (locked && *dp->d_name.name != '/' && vcp->mvstat == 2) { /* root vnode */
1113 if (vcp->mvid->Fid.Volume != pvcp->f.fid.Fid.Volume) { /* bad parent */
1114 fix_bad_parent(dp, credp, vcp, pvcp); /* check and correct mvid */
1119 /* If the last looker changes, we should make sure the current
1120 * looker still has permission to examine this file. This would
1121 * always require a crref() which would be "slow".
1123 if (vcp->last_looker != treq.uid) {
1124 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
1127 vcp->last_looker = treq.uid;
1132 /* If the parent's DataVersion has changed or the vnode
1133 * is longer valid, we need to do a full lookup. VerifyVCache
1134 * isn't enough since the vnode may have been renamed.
1137 if ((!locked) && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) ) {
1143 if (locked && (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd))) {
1144 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
1145 if (!tvc || tvc != vcp) {
1150 if (afs_getattr(vcp, &vattr, credp)) {
1155 vattr2inode(AFSTOV(vcp), &vattr);
1156 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
1159 /* should we always update the attributes at this point? */
1160 /* unlikely--the vcache entry hasn't changed */
1165 /* If this code is ever enabled, we should use dget_parent to handle
1166 * getting the parent, and dput() to dispose of it. See above for an
1168 pvcp = VTOAFS(dp->d_parent->d_inode);
1169 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
1173 /* No change in parent's DataVersion so this negative
1174 * lookup is still valid. BUT, if a server is down a
1175 * negative lookup can result so there should be a
1176 * liftime as well. For now, always expire.
1189 afs_PutFakeStat(&fakestate); /* from here on vcp may be no longer valid */
1191 /* we hold the global lock if we evaluated a mount point */
1198 shrink_dcache_parent(dp);
1204 if (have_submounts(dp))
1212 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1214 struct vcache *vcp = VTOAFS(ip);
1217 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1218 (void) afs_InactiveVCache(vcp, NULL);
1221 afs_linux_clear_nfsfs_renamed(dp);
1227 #if defined(DOP_D_DELETE_TAKES_CONST)
1228 afs_dentry_delete(const struct dentry *dp)
1230 afs_dentry_delete(struct dentry *dp)
1233 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1234 return 1; /* bad inode? */
1239 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1240 static struct vfsmount *
1241 afs_dentry_automount(struct path *path)
1243 struct dentry *target;
1245 target = canonical_dentry(path->dentry->d_inode);
1247 if (target == path->dentry) {
1254 path->dentry = target;
1257 spin_lock(&path->dentry->d_lock);
1258 path->dentry->d_flags &= ~DCACHE_NEED_AUTOMOUNT;
1259 spin_unlock(&path->dentry->d_lock);
1264 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1266 struct dentry_operations afs_dentry_operations = {
1267 .d_revalidate = afs_linux_dentry_revalidate,
1268 .d_delete = afs_dentry_delete,
1269 .d_iput = afs_dentry_iput,
1270 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1271 .d_automount = afs_dentry_automount,
1272 #endif /* STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
1275 /**********************************************************************
1276 * AFS Linux inode operations
1277 **********************************************************************/
1281 * Merely need to set enough of vattr to get us through the create. Note
1282 * that the higher level code (open_namei) will take care of any tuncation
1283 * explicitly. Exclusive open is also taken care of in open_namei.
1285 * name is in kernel space at this point.
1288 #if defined(IOP_CREATE_TAKES_BOOL)
1289 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1291 #elif defined(IOP_CREATE_TAKES_UMODE_T)
1292 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
1293 struct nameidata *nd)
1294 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
1295 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1296 struct nameidata *nd)
1298 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1302 cred_t *credp = crref();
1303 const char *name = dp->d_name.name;
1308 vattr.va_mode = mode;
1309 vattr.va_type = mode & S_IFMT;
1312 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1316 struct inode *ip = AFSTOV(vcp);
1318 afs_getattr(vcp, &vattr, credp);
1319 afs_fill_inode(ip, &vattr);
1320 insert_inode_hash(ip);
1321 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1322 dp->d_op = &afs_dentry_operations;
1324 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1325 d_instantiate(dp, ip);
1330 return afs_convert_code(code);
1333 /* afs_linux_lookup */
1334 static struct dentry *
1335 #if defined(IOP_LOOKUP_TAKES_UNSIGNED)
1336 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1338 #elif defined(IOP_LOOKUP_TAKES_NAMEIDATA)
1339 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1340 struct nameidata *nd)
1342 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1345 cred_t *credp = crref();
1346 struct vcache *vcp = NULL;
1347 const char *comp = dp->d_name.name;
1348 struct inode *ip = NULL;
1349 struct dentry *newdp = NULL;
1353 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1357 struct vcache *parent_vc = VTOAFS(dip);
1359 if (parent_vc == vcp) {
1360 /* This is possible if the parent dir is a mountpoint to a volume,
1361 * and the dir entry we looked up is a mountpoint to the same
1362 * volume. Linux cannot cope with this, so return an error instead
1363 * of risking a deadlock or panic. */
1371 afs_getattr(vcp, &vattr, credp);
1372 afs_fill_inode(ip, &vattr);
1373 if (hlist_unhashed(&ip->i_hash))
1374 insert_inode_hash(ip);
1376 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1377 dp->d_op = &afs_dentry_operations;
1379 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1382 if (ip && S_ISDIR(ip->i_mode)) {
1384 struct dentry *alias;
1389 /* Try to invalidate an existing alias in favor of our new one */
1390 alias = d_find_alias(ip);
1391 /* But not if it's disconnected; then we want d_splice_alias below */
1392 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
1393 if (d_invalidate(alias) == 0) {
1394 /* there may be more aliases; try again until we run out */
1402 #ifdef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
1403 ip->i_flags |= S_AUTOMOUNT;
1406 newdp = d_splice_alias(ip, dp);
1411 /* It's ok for the file to not be found. That's noted by the caller by
1412 * seeing that the dp->d_inode field is NULL.
1414 if (!code || code == ENOENT)
1417 return ERR_PTR(afs_convert_code(code));
1421 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1424 cred_t *credp = crref();
1425 const char *name = newdp->d_name.name;
1426 struct inode *oldip = olddp->d_inode;
1428 /* If afs_link returned the vnode, we could instantiate the
1429 * dentry. Since it's not, we drop this one and do a new lookup.
1434 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1438 return afs_convert_code(code);
1441 /* We have to have a Linux specific sillyrename function, because we
1442 * also have to keep the dcache up to date when we're doing a silly
1443 * rename - so we don't want the generic vnodeops doing this behind our
1448 afs_linux_sillyrename(struct inode *dir, struct dentry *dentry,
1451 struct vcache *tvc = VTOAFS(dentry->d_inode);
1452 struct dentry *__dp = NULL;
1453 char *__name = NULL;
1456 if (afs_linux_nfsfs_renamed(dentry))
1464 osi_FreeSmallSpace(__name);
1465 __name = afs_newname();
1468 __dp = lookup_one_len(__name, dentry->d_parent, strlen(__name));
1471 osi_FreeSmallSpace(__name);
1474 } while (__dp->d_inode != NULL);
1477 code = afs_rename(VTOAFS(dir), (char *)dentry->d_name.name,
1478 VTOAFS(dir), (char *)__dp->d_name.name,
1481 tvc->mvid = (void *) __name;
1484 crfree(tvc->uncred);
1486 tvc->uncred = credp;
1487 tvc->f.states |= CUnlinked;
1488 afs_linux_set_nfsfs_renamed(dentry);
1490 osi_FreeSmallSpace(__name);
1495 __dp->d_time = hgetlo(VTOAFS(dir)->f.m.DataVersion);
1496 d_move(dentry, __dp);
1505 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1508 cred_t *credp = crref();
1509 const char *name = dp->d_name.name;
1510 struct vcache *tvc = VTOAFS(dp->d_inode);
1512 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1513 && !(tvc->f.states & CUnlinked)) {
1515 code = afs_linux_sillyrename(dip, dp, credp);
1518 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1525 return afs_convert_code(code);
1530 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1533 cred_t *credp = crref();
1535 const char *name = dp->d_name.name;
1537 /* If afs_symlink returned the vnode, we could instantiate the
1538 * dentry. Since it's not, we drop this one and do a new lookup.
1544 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1547 return afs_convert_code(code);
1551 #if defined(IOP_MKDIR_TAKES_UMODE_T)
1552 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
1554 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1558 cred_t *credp = crref();
1559 struct vcache *tvcp = NULL;
1561 const char *name = dp->d_name.name;
1564 vattr.va_mask = ATTR_MODE;
1565 vattr.va_mode = mode;
1567 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1570 struct inode *ip = AFSTOV(tvcp);
1572 afs_getattr(tvcp, &vattr, credp);
1573 afs_fill_inode(ip, &vattr);
1575 #if !defined(STRUCT_SUPER_BLOCK_HAS_S_D_OP)
1576 dp->d_op = &afs_dentry_operations;
1578 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1579 d_instantiate(dp, ip);
1584 return afs_convert_code(code);
1588 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1591 cred_t *credp = crref();
1592 const char *name = dp->d_name.name;
1594 /* locking kernel conflicts with glock? */
1597 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1600 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1601 * that failed because a directory is not empty. So, we map
1602 * EEXIST to ENOTEMPTY on linux.
1604 if (code == EEXIST) {
1613 return afs_convert_code(code);
1618 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1619 struct inode *newip, struct dentry *newdp)
1622 cred_t *credp = crref();
1623 const char *oldname = olddp->d_name.name;
1624 const char *newname = newdp->d_name.name;
1625 struct dentry *rehash = NULL;
1627 /* Prevent any new references during rename operation. */
1629 if (!d_unhashed(newdp)) {
1634 #if defined(D_COUNT_INT)
1635 spin_lock(&olddp->d_lock);
1636 if (olddp->d_count > 1) {
1637 spin_unlock(&olddp->d_lock);
1638 shrink_dcache_parent(olddp);
1640 spin_unlock(&olddp->d_lock);
1642 if (atomic_read(&olddp->d_count) > 1)
1643 shrink_dcache_parent(olddp);
1647 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1651 olddp->d_time = 0; /* force to revalidate */
1657 return afs_convert_code(code);
1661 /* afs_linux_ireadlink
1662 * Internal readlink which can return link contents to user or kernel space.
1663 * Note that the buffer is NOT supposed to be null-terminated.
1666 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1669 cred_t *credp = crref();
1673 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1674 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1678 return maxlen - tuio.uio_resid;
1680 return afs_convert_code(code);
1683 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1684 /* afs_linux_readlink
1685 * Fill target (which is in user space) with contents of symlink.
1688 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1691 struct inode *ip = dp->d_inode;
1694 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1700 /* afs_linux_follow_link
1701 * a file system dependent link following routine.
1703 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1708 name = kmalloc(PATH_MAX, GFP_NOFS);
1714 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1722 nd_set_link(nd, name);
1727 afs_linux_put_link(struct dentry *dentry, struct nameidata *nd)
1729 char *name = nd_get_link(nd);
1731 if (name && !IS_ERR(name))
1735 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1737 /* Populate a page by filling it from the cache file pointed at by cachefp
1738 * (which contains indicated chunk)
1739 * If task is NULL, the page copy occurs syncronously, and the routine
1740 * returns with page still locked. If task is non-NULL, then page copies
1741 * may occur in the background, and the page will be unlocked when it is
1745 afs_linux_read_cache(struct file *cachefp, struct page *page,
1746 int chunk, struct pagevec *lrupv,
1747 struct afs_pagecopy_task *task) {
1748 loff_t offset = page_offset(page);
1749 struct inode *cacheinode = cachefp->f_dentry->d_inode;
1750 struct page *newpage, *cachepage;
1751 struct address_space *cachemapping;
1755 cachemapping = cacheinode->i_mapping;
1759 /* If we're trying to read a page that's past the end of the disk
1760 * cache file, then just return a zeroed page */
1761 if (AFS_CHUNKOFFSET(offset) >= i_size_read(cacheinode)) {
1762 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1763 SetPageUptodate(page);
1769 /* From our offset, we now need to work out which page in the disk
1770 * file it corresponds to. This will be fun ... */
1771 pageindex = (offset - AFS_CHUNKTOBASE(chunk)) >> PAGE_CACHE_SHIFT;
1773 while (cachepage == NULL) {
1774 cachepage = find_get_page(cachemapping, pageindex);
1777 newpage = page_cache_alloc_cold(cachemapping);
1783 code = add_to_page_cache(newpage, cachemapping,
1784 pageindex, GFP_KERNEL);
1786 cachepage = newpage;
1789 page_cache_get(cachepage);
1790 if (!pagevec_add(lrupv, cachepage))
1791 __pagevec_lru_add_file(lrupv);
1794 page_cache_release(newpage);
1796 if (code != -EEXIST)
1800 lock_page(cachepage);
1804 if (!PageUptodate(cachepage)) {
1805 ClearPageError(cachepage);
1806 code = cachemapping->a_ops->readpage(NULL, cachepage);
1807 if (!code && !task) {
1808 wait_on_page_locked(cachepage);
1811 unlock_page(cachepage);
1815 if (PageUptodate(cachepage)) {
1816 copy_highpage(page, cachepage);
1817 flush_dcache_page(page);
1818 SetPageUptodate(page);
1823 afs_pagecopy_queue_page(task, cachepage, page);
1835 page_cache_release(cachepage);
1841 afs_linux_readpage_fastpath(struct file *fp, struct page *pp, int *codep)
1843 loff_t offset = page_offset(pp);
1844 struct inode *ip = FILE_INODE(fp);
1845 struct vcache *avc = VTOAFS(ip);
1847 struct file *cacheFp = NULL;
1850 struct pagevec lrupv;
1852 /* Not a UFS cache, don't do anything */
1853 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
1856 /* Can't do anything if the vcache isn't statd , or if the read
1857 * crosses a chunk boundary.
1859 if (!(avc->f.states & CStatd) ||
1860 AFS_CHUNK(offset) != AFS_CHUNK(offset + PAGE_SIZE)) {
1864 ObtainWriteLock(&avc->lock, 911);
1866 /* XXX - See if hinting actually makes things faster !!! */
1868 /* See if we have a suitable entry already cached */
1872 /* We need to lock xdcache, then dcache, to handle situations where
1873 * the hint is on the free list. However, we can't safely do this
1874 * according to the locking hierarchy. So, use a non blocking lock.
1876 ObtainReadLock(&afs_xdcache);
1877 dcLocked = ( 0 == NBObtainReadLock(&tdc->lock));
1879 if (dcLocked && (tdc->index != NULLIDX)
1880 && !FidCmp(&tdc->f.fid, &avc->f.fid)
1881 && tdc->f.chunk == AFS_CHUNK(offset)
1882 && !(afs_indexFlags[tdc->index] & (IFFree | IFDiscarded))) {
1883 /* Bonus - the hint was correct */
1886 /* Only destroy the hint if its actually invalid, not if there's
1887 * just been a locking failure */
1889 ReleaseReadLock(&tdc->lock);
1896 ReleaseReadLock(&afs_xdcache);
1899 /* No hint, or hint is no longer valid - see if we can get something
1900 * directly from the dcache
1903 tdc = afs_FindDCache(avc, offset);
1906 ReleaseWriteLock(&avc->lock);
1911 ObtainReadLock(&tdc->lock);
1913 /* Is the dcache we've been given currently up to date */
1914 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
1915 (tdc->dflags & DFFetching)) {
1916 ReleaseWriteLock(&avc->lock);
1917 ReleaseReadLock(&tdc->lock);
1922 /* Update our hint for future abuse */
1925 /* Okay, so we've now got a cache file that is up to date */
1927 /* XXX - I suspect we should be locking the inodes before we use them! */
1929 cacheFp = afs_linux_raw_open(&tdc->f.inode);
1930 pagevec_init(&lrupv, 0);
1932 code = afs_linux_read_cache(cacheFp, pp, tdc->f.chunk, &lrupv, NULL);
1934 if (pagevec_count(&lrupv))
1935 __pagevec_lru_add_file(&lrupv);
1937 filp_close(cacheFp, NULL);
1940 ReleaseReadLock(&tdc->lock);
1941 ReleaseWriteLock(&avc->lock);
1948 /* afs_linux_readpage
1950 * This function is split into two, because prepare_write/begin_write
1951 * require a readpage call which doesn't unlock the resulting page upon
1955 afs_linux_fillpage(struct file *fp, struct page *pp)
1960 struct iovec *iovecp;
1961 struct inode *ip = FILE_INODE(fp);
1962 afs_int32 cnt = page_count(pp);
1963 struct vcache *avc = VTOAFS(ip);
1964 afs_offs_t offset = page_offset(pp);
1968 if (afs_linux_readpage_fastpath(fp, pp, &code)) {
1978 auio = kmalloc(sizeof(struct uio), GFP_NOFS);
1979 iovecp = kmalloc(sizeof(struct iovec), GFP_NOFS);
1981 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1986 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1987 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1988 99999); /* not a possible code value */
1990 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1992 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1993 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1995 AFS_DISCON_UNLOCK();
1998 /* XXX valid for no-cache also? Check last bits of files... :)
1999 * Cognate code goes in afs_NoCacheFetchProc. */
2000 if (auio->uio_resid) /* zero remainder of page */
2001 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
2004 flush_dcache_page(pp);
2005 SetPageUptodate(pp);
2014 return afs_convert_code(code);
2018 afs_linux_prefetch(struct file *fp, struct page *pp)
2021 struct vcache *avc = VTOAFS(FILE_INODE(fp));
2022 afs_offs_t offset = page_offset(pp);
2024 if (AFS_CHUNKOFFSET(offset) == 0) {
2026 struct vrequest treq;
2031 code = afs_InitReq(&treq, credp);
2032 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
2033 tdc = afs_FindDCache(avc, offset);
2035 if (!(tdc->mflags & DFNextStarted))
2036 afs_PrefetchChunk(avc, tdc, credp, &treq);
2039 ReleaseWriteLock(&avc->lock);
2044 return afs_convert_code(code);
2049 afs_linux_bypass_readpages(struct file *fp, struct address_space *mapping,
2050 struct list_head *page_list, unsigned num_pages)
2055 struct iovec* iovecp;
2056 struct nocache_read_request *ancr;
2058 struct pagevec lrupv;
2062 struct inode *ip = FILE_INODE(fp);
2063 struct vcache *avc = VTOAFS(ip);
2064 afs_int32 base_index = 0;
2065 afs_int32 page_count = 0;
2068 /* background thread must free: iovecp, auio, ancr */
2069 iovecp = osi_Alloc(num_pages * sizeof(struct iovec));
2071 auio = osi_Alloc(sizeof(struct uio));
2072 auio->uio_iov = iovecp;
2073 auio->uio_iovcnt = num_pages;
2074 auio->uio_flag = UIO_READ;
2075 auio->uio_seg = AFS_UIOSYS;
2076 auio->uio_resid = num_pages * PAGE_SIZE;
2078 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2080 ancr->offset = auio->uio_offset;
2081 ancr->length = auio->uio_resid;
2083 pagevec_init(&lrupv, 0);
2085 for(page_ix = 0; page_ix < num_pages; ++page_ix) {
2087 if(list_empty(page_list))
2090 pp = list_entry(page_list->prev, struct page, lru);
2091 /* If we allocate a page and don't remove it from page_list,
2092 * the page cache gets upset. */
2094 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
2095 if(pp->index > isize) {
2102 offset = page_offset(pp);
2103 auio->uio_offset = offset;
2104 base_index = pp->index;
2106 iovecp[page_ix].iov_len = PAGE_SIZE;
2107 code = add_to_page_cache(pp, mapping, pp->index, GFP_KERNEL);
2108 if(base_index != pp->index) {
2111 page_cache_release(pp);
2112 iovecp[page_ix].iov_base = (void *) 0;
2114 ancr->length -= PAGE_SIZE;
2121 page_cache_release(pp);
2122 iovecp[page_ix].iov_base = (void *) 0;
2125 if(!PageLocked(pp)) {
2129 /* increment page refcount--our original design assumed
2130 * that locking it would effectively pin it; protect
2131 * ourselves from the possiblity that this assumption is
2132 * is faulty, at low cost (provided we do not fail to
2133 * do the corresponding decref on the other side) */
2136 /* save the page for background map */
2137 iovecp[page_ix].iov_base = (void*) pp;
2139 /* and put it on the LRU cache */
2140 if (!pagevec_add(&lrupv, pp))
2141 __pagevec_lru_add_file(&lrupv);
2145 /* If there were useful pages in the page list, make sure all pages
2146 * are in the LRU cache, then schedule the read */
2148 if (pagevec_count(&lrupv))
2149 __pagevec_lru_add_file(&lrupv);
2151 code = afs_ReadNoCache(avc, ancr, credp);
2154 /* If there is nothing for the background thread to handle,
2155 * it won't be freeing the things that we never gave it */
2156 osi_Free(iovecp, num_pages * sizeof(struct iovec));
2157 osi_Free(auio, sizeof(struct uio));
2158 osi_Free(ancr, sizeof(struct nocache_read_request));
2160 /* we do not flush, release, or unmap pages--that will be
2161 * done for us by the background thread as each page comes in
2162 * from the fileserver */
2163 return afs_convert_code(code);
2168 afs_linux_bypass_readpage(struct file *fp, struct page *pp)
2170 cred_t *credp = NULL;
2172 struct iovec *iovecp;
2173 struct nocache_read_request *ancr;
2177 * Special case: if page is at or past end of file, just zero it and set
2180 if (page_offset(pp) >= i_size_read(fp->f_mapping->host)) {
2181 zero_user_segment(pp, 0, PAGE_CACHE_SIZE);
2182 SetPageUptodate(pp);
2189 /* receiver frees */
2190 auio = osi_Alloc(sizeof(struct uio));
2191 iovecp = osi_Alloc(sizeof(struct iovec));
2193 /* address can be NULL, because we overwrite it with 'pp', below */
2194 setup_uio(auio, iovecp, NULL, page_offset(pp),
2195 PAGE_SIZE, UIO_READ, AFS_UIOSYS);
2197 /* save the page for background map */
2198 get_page(pp); /* see above */
2199 auio->uio_iov->iov_base = (void*) pp;
2200 /* the background thread will free this */
2201 ancr = osi_Alloc(sizeof(struct nocache_read_request));
2203 ancr->offset = page_offset(pp);
2204 ancr->length = PAGE_SIZE;
2207 code = afs_ReadNoCache(VTOAFS(FILE_INODE(fp)), ancr, credp);
2210 return afs_convert_code(code);
2214 afs_linux_can_bypass(struct inode *ip) {
2215 switch(cache_bypass_strategy) {
2216 case NEVER_BYPASS_CACHE:
2218 case ALWAYS_BYPASS_CACHE:
2220 case LARGE_FILES_BYPASS_CACHE:
2221 if(i_size_read(ip) > cache_bypass_threshold)
2228 /* Check if a file is permitted to bypass the cache by policy, and modify
2229 * the cache bypass state recorded for that file */
2232 afs_linux_bypass_check(struct inode *ip) {
2235 int bypass = afs_linux_can_bypass(ip);
2238 trydo_cache_transition(VTOAFS(ip), credp, bypass);
2246 afs_linux_readpage(struct file *fp, struct page *pp)
2250 if (afs_linux_bypass_check(FILE_INODE(fp))) {
2251 code = afs_linux_bypass_readpage(fp, pp);
2253 code = afs_linux_fillpage(fp, pp);
2255 code = afs_linux_prefetch(fp, pp);
2262 /* Readpages reads a number of pages for a particular file. We use
2263 * this to optimise the reading, by limiting the number of times upon which
2264 * we have to lookup, lock and open vcaches and dcaches
2268 afs_linux_readpages(struct file *fp, struct address_space *mapping,
2269 struct list_head *page_list, unsigned int num_pages)
2271 struct inode *inode = mapping->host;
2272 struct vcache *avc = VTOAFS(inode);
2274 struct file *cacheFp = NULL;
2276 unsigned int page_idx;
2278 struct pagevec lrupv;
2279 struct afs_pagecopy_task *task;
2281 if (afs_linux_bypass_check(inode))
2282 return afs_linux_bypass_readpages(fp, mapping, page_list, num_pages);
2284 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2288 if ((code = afs_linux_VerifyVCache(avc, NULL))) {
2293 ObtainWriteLock(&avc->lock, 912);
2296 task = afs_pagecopy_init_task();
2299 pagevec_init(&lrupv, 0);
2300 for (page_idx = 0; page_idx < num_pages; page_idx++) {
2301 struct page *page = list_entry(page_list->prev, struct page, lru);
2302 list_del(&page->lru);
2303 offset = page_offset(page);
2305 if (tdc && tdc->f.chunk != AFS_CHUNK(offset)) {
2307 ReleaseReadLock(&tdc->lock);
2312 filp_close(cacheFp, NULL);
2317 if ((tdc = afs_FindDCache(avc, offset))) {
2318 ObtainReadLock(&tdc->lock);
2319 if (!hsame(avc->f.m.DataVersion, tdc->f.versionNo) ||
2320 (tdc->dflags & DFFetching)) {
2321 ReleaseReadLock(&tdc->lock);
2328 cacheFp = afs_linux_raw_open(&tdc->f.inode);
2331 if (tdc && !add_to_page_cache(page, mapping, page->index,
2333 page_cache_get(page);
2334 if (!pagevec_add(&lrupv, page))
2335 __pagevec_lru_add_file(&lrupv);
2337 afs_linux_read_cache(cacheFp, page, tdc->f.chunk, &lrupv, task);
2339 page_cache_release(page);
2341 if (pagevec_count(&lrupv))
2342 __pagevec_lru_add_file(&lrupv);
2345 filp_close(cacheFp, NULL);
2347 afs_pagecopy_put_task(task);
2351 ReleaseReadLock(&tdc->lock);
2355 ReleaseWriteLock(&avc->lock);
2360 /* Prepare an AFS vcache for writeback. Should be called with the vcache
2363 afs_linux_prepare_writeback(struct vcache *avc) {
2364 if (avc->f.states & CPageWrite) {
2365 return AOP_WRITEPAGE_ACTIVATE;
2367 avc->f.states |= CPageWrite;
2372 afs_linux_dopartialwrite(struct vcache *avc, cred_t *credp) {
2373 struct vrequest treq;
2376 if (!afs_InitReq(&treq, credp))
2377 code = afs_DoPartialWrite(avc, &treq);
2379 return afs_convert_code(code);
2383 afs_linux_complete_writeback(struct vcache *avc) {
2384 avc->f.states &= ~CPageWrite;
2387 /* Writeback a given page syncronously. Called with no AFS locks held */
2389 afs_linux_page_writeback(struct inode *ip, struct page *pp,
2390 unsigned long offset, unsigned int count,
2393 struct vcache *vcp = VTOAFS(ip);
2401 buffer = kmap(pp) + offset;
2402 base = page_offset(pp) + offset;
2405 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
2406 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
2407 ICL_TYPE_INT32, 99999);
2409 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
2411 code = afs_write(vcp, &tuio, f_flags, credp, 0);
2413 i_size_write(ip, vcp->f.m.Length);
2414 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
2416 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
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, code);
2429 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
2430 unsigned long offset, unsigned int count)
2434 struct vcache *vcp = VTOAFS(ip);
2437 /* Catch recursive writeback. This occurs if the kernel decides
2438 * writeback is required whilst we are writing to the cache, or
2439 * flushing to the server. When we're running syncronously (as
2440 * opposed to from writepage) we can't actually do anything about
2441 * this case - as we can't return AOP_WRITEPAGE_ACTIVATE to write()
2444 ObtainWriteLock(&vcp->lock, 532);
2445 afs_linux_prepare_writeback(vcp);
2446 ReleaseWriteLock(&vcp->lock);
2450 code = afs_linux_page_writeback(ip, pp, offset, count, credp);
2453 ObtainWriteLock(&vcp->lock, 533);
2455 code1 = afs_linux_dopartialwrite(vcp, credp);
2456 afs_linux_complete_writeback(vcp);
2457 ReleaseWriteLock(&vcp->lock);
2468 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
2469 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
2471 afs_linux_writepage(struct page *pp)
2474 struct address_space *mapping = pp->mapping;
2475 struct inode *inode;
2478 unsigned int to = PAGE_CACHE_SIZE;
2483 if (PageReclaim(pp)) {
2484 return AOP_WRITEPAGE_ACTIVATE;
2485 /* XXX - Do we need to redirty the page here? */
2490 inode = mapping->host;
2491 vcp = VTOAFS(inode);
2492 isize = i_size_read(inode);
2494 /* Don't defeat an earlier truncate */
2495 if (page_offset(pp) > isize) {
2496 set_page_writeback(pp);
2502 ObtainWriteLock(&vcp->lock, 537);
2503 code = afs_linux_prepare_writeback(vcp);
2504 if (code == AOP_WRITEPAGE_ACTIVATE) {
2505 /* WRITEPAGE_ACTIVATE is the only return value that permits us
2506 * to return with the page still locked */
2507 ReleaseWriteLock(&vcp->lock);
2512 /* Grab the creds structure currently held in the vnode, and
2513 * get a reference to it, in case it goes away ... */
2519 ReleaseWriteLock(&vcp->lock);
2522 set_page_writeback(pp);
2524 SetPageUptodate(pp);
2526 /* We can unlock the page here, because it's protected by the
2527 * page_writeback flag. This should make us less vulnerable to
2528 * deadlocking in afs_write and afs_DoPartialWrite
2532 /* If this is the final page, then just write the number of bytes that
2533 * are actually in it */
2534 if ((isize - page_offset(pp)) < to )
2535 to = isize - page_offset(pp);
2537 code = afs_linux_page_writeback(inode, pp, 0, to, credp);
2540 ObtainWriteLock(&vcp->lock, 538);
2542 /* As much as we might like to ignore a file server error here,
2543 * and just try again when we close(), unfortunately StoreAllSegments
2544 * will invalidate our chunks if the server returns a permanent error,
2545 * so we need to at least try and get that error back to the user
2548 code1 = afs_linux_dopartialwrite(vcp, credp);
2550 afs_linux_complete_writeback(vcp);
2551 ReleaseWriteLock(&vcp->lock);
2556 end_page_writeback(pp);
2557 page_cache_release(pp);
2568 /* afs_linux_permission
2569 * Check access rights - returns error if can't check or permission denied.
2572 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2573 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
2574 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
2575 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
2577 afs_linux_permission(struct inode *ip, int mode)
2584 /* Check for RCU path walking */
2585 #if defined(IOP_PERMISSION_TAKES_FLAGS)
2586 if (flags & IPERM_FLAG_RCU)
2588 #elif defined(MAY_NOT_BLOCK)
2589 if (mode & MAY_NOT_BLOCK)
2595 if (mode & MAY_EXEC)
2597 if (mode & MAY_READ)
2599 if (mode & MAY_WRITE)
2601 code = afs_access(VTOAFS(ip), tmp, credp);
2605 return afs_convert_code(code);
2609 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
2613 struct inode *inode = FILE_INODE(file);
2614 loff_t pagebase = page_offset(page);
2616 if (i_size_read(inode) < (pagebase + offset))
2617 i_size_write(inode, pagebase + offset);
2619 if (PageChecked(page)) {
2620 SetPageUptodate(page);
2621 ClearPageChecked(page);
2624 code = afs_linux_writepage_sync(inode, page, offset, to - offset);
2630 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
2634 /* http://kerneltrap.org/node/4941 details the expected behaviour of
2635 * prepare_write. Essentially, if the page exists within the file,
2636 * and is not being fully written, then we should populate it.
2639 if (!PageUptodate(page)) {
2640 loff_t pagebase = page_offset(page);
2641 loff_t isize = i_size_read(page->mapping->host);
2643 /* Is the location we are writing to beyond the end of the file? */
2644 if (pagebase >= isize ||
2645 ((from == 0) && (pagebase + to) >= isize)) {
2646 zero_user_segments(page, 0, from, to, PAGE_CACHE_SIZE);
2647 SetPageChecked(page);
2648 /* Are we we writing a full page */
2649 } else if (from == 0 && to == PAGE_CACHE_SIZE) {
2650 SetPageChecked(page);
2651 /* Is the page readable, if it's wronly, we don't care, because we're
2652 * not actually going to read from it ... */
2653 } else if ((file->f_flags && O_ACCMODE) != O_WRONLY) {
2654 /* We don't care if fillpage fails, because if it does the page
2655 * won't be marked as up to date
2657 afs_linux_fillpage(file, page);
2663 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2665 afs_linux_write_end(struct file *file, struct address_space *mapping,
2666 loff_t pos, unsigned len, unsigned copied,
2667 struct page *page, void *fsdata)
2670 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2672 code = afs_linux_commit_write(file, page, from, from + len);
2675 page_cache_release(page);
2680 afs_linux_write_begin(struct file *file, struct address_space *mapping,
2681 loff_t pos, unsigned len, unsigned flags,
2682 struct page **pagep, void **fsdata)
2685 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
2686 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
2689 page = grab_cache_page_write_begin(mapping, index, flags);
2692 code = afs_linux_prepare_write(file, page, from, from + len);
2695 page_cache_release(page);
2702 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2704 afs_linux_dir_follow_link(struct dentry *dentry, struct nameidata *nd)
2706 struct dentry **dpp;
2707 struct dentry *target;
2709 target = canonical_dentry(dentry->d_inode);
2711 # ifdef STRUCT_NAMEIDATA_HAS_PATH
2712 dpp = &nd->path.dentry;
2722 *dpp = dget(dentry);
2727 #endif /* !STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT */
2730 static struct inode_operations afs_file_iops = {
2731 .permission = afs_linux_permission,
2732 .getattr = afs_linux_getattr,
2733 .setattr = afs_notify_change,
2736 static struct address_space_operations afs_file_aops = {
2737 .readpage = afs_linux_readpage,
2738 .readpages = afs_linux_readpages,
2739 .writepage = afs_linux_writepage,
2740 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
2741 .write_begin = afs_linux_write_begin,
2742 .write_end = afs_linux_write_end,
2744 .commit_write = afs_linux_commit_write,
2745 .prepare_write = afs_linux_prepare_write,
2750 /* Separate ops vector for directories. Linux 2.2 tests type of inode
2751 * by what sort of operation is allowed.....
2754 static struct inode_operations afs_dir_iops = {
2755 .setattr = afs_notify_change,
2756 .create = afs_linux_create,
2757 .lookup = afs_linux_lookup,
2758 .link = afs_linux_link,
2759 .unlink = afs_linux_unlink,
2760 .symlink = afs_linux_symlink,
2761 .mkdir = afs_linux_mkdir,
2762 .rmdir = afs_linux_rmdir,
2763 .rename = afs_linux_rename,
2764 .getattr = afs_linux_getattr,
2765 .permission = afs_linux_permission,
2766 #ifndef STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT
2767 .follow_link = afs_linux_dir_follow_link,
2771 /* We really need a separate symlink set of ops, since do_follow_link()
2772 * determines if it _is_ a link by checking if the follow_link op is set.
2774 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2776 afs_symlink_filler(struct file *file, struct page *page)
2778 struct inode *ip = (struct inode *)page->mapping->host;
2779 char *p = (char *)kmap(page);
2783 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
2788 p[code] = '\0'; /* null terminate? */
2790 SetPageUptodate(page);
2802 static struct address_space_operations afs_symlink_aops = {
2803 .readpage = afs_symlink_filler
2805 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2807 static struct inode_operations afs_symlink_iops = {
2808 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2809 .readlink = page_readlink,
2810 # if defined(HAVE_LINUX_PAGE_FOLLOW_LINK)
2811 .follow_link = page_follow_link,
2813 .follow_link = page_follow_link_light,
2814 .put_link = page_put_link,
2816 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2817 .readlink = afs_linux_readlink,
2818 .follow_link = afs_linux_follow_link,
2819 .put_link = afs_linux_put_link,
2820 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2821 .setattr = afs_notify_change,
2825 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2829 vattr2inode(ip, vattr);
2831 ip->i_mapping->backing_dev_info = afs_backing_dev_info;
2832 /* Reset ops if symlink or directory. */
2833 if (S_ISREG(ip->i_mode)) {
2834 ip->i_op = &afs_file_iops;
2835 ip->i_fop = &afs_file_fops;
2836 ip->i_data.a_ops = &afs_file_aops;
2838 } else if (S_ISDIR(ip->i_mode)) {
2839 ip->i_op = &afs_dir_iops;
2840 ip->i_fop = &afs_dir_fops;
2842 } else if (S_ISLNK(ip->i_mode)) {
2843 ip->i_op = &afs_symlink_iops;
2844 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2845 ip->i_data.a_ops = &afs_symlink_aops;
2846 ip->i_mapping = &ip->i_data;