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 "h/mm_inline.h"
32 #include "h/pagemap.h"
33 #if defined(AFS_LINUX24_ENV)
34 #include "h/smp_lock.h"
37 #include "afs/afs_bypasscache.h"
40 #define pageoff(pp) pgoff2loff((pp)->index)
42 #define pageoff(pp) pp->offset
46 #define MAX_ERRNO 1000L
49 extern struct vcache *afs_globalVp;
50 extern int afs_notify_change(struct dentry *dp, struct iattr *iattrp);
51 #if defined(AFS_LINUX24_ENV)
52 /* Some uses of BKL are perhaps not needed for bypass or memcache--
53 * why don't we try it out? */
54 extern struct afs_cacheOps afs_UfsCacheOps;
55 #define maybe_lock_kernel() \
57 if(afs_cacheType == &afs_UfsCacheOps) \
62 #define maybe_unlock_kernel() \
64 if(afs_cacheType == &afs_UfsCacheOps) \
67 #endif /* AFS_LINUX24_ENV */
70 /* This function converts a positive error code from AFS into a negative
71 * code suitable for passing into the Linux VFS layer. It checks that the
72 * error code is within the permissable bounds for the ERR_PTR mechanism.
74 * _All_ error codes which come from the AFS layer should be passed through
75 * this function before being returned to the kernel.
78 static inline int afs_convert_code(int code) {
79 if ((code >= 0) && (code <= MAX_ERRNO))
85 /* Linux doesn't require a credp for many functions, and crref is an expensive
86 * operation. This helper function avoids obtaining it for VerifyVCache calls
89 static inline int afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
94 if (avc->f.states & CStatd) {
102 code = afs_InitReq(&treq, credp);
104 code = afs_VerifyVCache2(avc, &treq);
111 return afs_convert_code(code);
115 afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp)
118 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
120 afs_size_t isize, offindex;
124 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
125 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
127 code = afs_linux_VerifyVCache(vcp, NULL);
130 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
131 isize = (i_size_read(fp->f_mapping->host) - 1) >> PAGE_CACHE_SHIFT;
132 offindex = *offp >> PAGE_CACHE_SHIFT;
133 if(offindex > isize) {
138 /* Linux's FlushPages implementation doesn't ever use credp,
139 * so we optimise by not using it */
140 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
142 #ifdef HAVE_LINUX_DO_SYNC_READ
143 code = do_sync_read(fp, buf, count, offp);
145 code = generic_file_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,
153 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
161 /* Now we have integrated VM for writes as well as reads. generic_file_write
162 * also takes care of re-positioning the pointer if file is open in append
163 * mode. Call fake open/close to ensure we do writes of core dumps.
166 afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp)
169 struct vcache *vcp = VTOAFS(fp->f_dentry->d_inode);
174 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
175 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
176 (fp->f_flags & O_APPEND) ? 99998 : 99999);
178 code = afs_linux_VerifyVCache(vcp, &credp);
180 ObtainWriteLock(&vcp->lock, 529);
182 ReleaseWriteLock(&vcp->lock);
186 code = do_sync_write(fp, buf, count, offp);
188 code = generic_file_write(fp, buf, count, offp);
193 ObtainWriteLock(&vcp->lock, 530);
195 if (vcp->execsOrWriters == 1 && !credp)
198 afs_FakeClose(vcp, credp);
199 ReleaseWriteLock(&vcp->lock);
201 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
202 ICL_TYPE_OFFSET, offp, ICL_TYPE_INT32, count, ICL_TYPE_INT32,
211 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
213 /* This is a complete rewrite of afs_readdir, since we can make use of
214 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
215 * handling and use of bulkstats will need to be reflected here as well.
218 afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir)
220 struct vcache *avc = VTOAFS(FILE_INODE(fp));
221 struct vrequest treq;
229 afs_size_t origOffset, tlen;
230 cred_t *credp = crref();
231 struct afs_fakestat_state fakestat;
234 AFS_STATCNT(afs_readdir);
236 code = afs_convert_code(afs_InitReq(&treq, credp));
241 afs_InitFakeStat(&fakestat);
242 code = afs_convert_code(afs_EvalFakeStat(&avc, &fakestat, &treq));
246 /* update the cache entry */
248 code = afs_convert_code(afs_VerifyVCache2(avc, &treq));
252 /* get a reference to the entire directory */
253 tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
259 ObtainSharedLock(&avc->lock, 810);
260 UpgradeSToWLock(&avc->lock, 811);
261 ObtainReadLock(&tdc->lock);
263 * Make sure that the data in the cache is current. There are two
264 * cases we need to worry about:
265 * 1. The cache data is being fetched by another process.
266 * 2. The cache data is no longer valid
268 while ((avc->f.states & CStatd)
269 && (tdc->dflags & DFFetching)
270 && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
271 ReleaseReadLock(&tdc->lock);
272 ReleaseSharedLock(&avc->lock);
273 afs_osi_Sleep(&tdc->validPos);
274 ObtainSharedLock(&avc->lock, 812);
275 ObtainReadLock(&tdc->lock);
277 if (!(avc->f.states & CStatd)
278 || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) {
279 ReleaseReadLock(&tdc->lock);
280 ReleaseSharedLock(&avc->lock);
285 /* Set the readdir-in-progress flag, and downgrade the lock
286 * to shared so others will be able to acquire a read lock.
288 avc->f.states |= CReadDir;
289 avc->dcreaddir = tdc;
290 avc->readdir_pid = MyPidxx2Pid(MyPidxx);
291 ConvertWToSLock(&avc->lock);
293 /* Fill in until we get an error or we're done. This implementation
294 * takes an offset in units of blobs, rather than bytes.
297 offset = (int) fp->f_pos;
299 dirpos = BlobScan(tdc, offset);
303 de = afs_dir_GetBlob(tdc, dirpos);
307 ino = afs_calc_inum (avc->f.fid.Fid.Volume, ntohl(de->fid.vnode));
310 len = strlen(de->name);
312 printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %lx, dirpos %d)\n",
313 (unsigned long)&tdc->f.inode, dirpos);
315 ReleaseSharedLock(&avc->lock);
321 /* filldir returns -EINVAL when the buffer is full. */
322 #if (defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE)
324 unsigned int type = DT_UNKNOWN;
325 struct VenusFid afid;
328 afid.Cell = avc->f.fid.Cell;
329 afid.Fid.Volume = avc->f.fid.Fid.Volume;
330 afid.Fid.Vnode = ntohl(de->fid.vnode);
331 afid.Fid.Unique = ntohl(de->fid.vunique);
332 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
334 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
337 } else if (((tvc->f.states) & (CStatd | CTruth))) {
338 /* CTruth will be set if the object has
343 else if (vtype == VREG)
345 /* Don't do this until we're sure it can't be a mtpt */
346 /* else if (vtype == VLNK)
348 /* what other types does AFS support? */
350 /* clean up from afs_FindVCache */
354 * If this is NFS readdirplus, then the filler is going to
355 * call getattr on this inode, which will deadlock if we're
359 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
363 code = (*filldir) (dirbuf, de->name, len, offset, ino);
368 offset = dirpos + 1 + ((len + 16) >> 5);
370 /* If filldir didn't fill in the last one this is still pointing to that
373 fp->f_pos = (loff_t) offset;
375 ReleaseReadLock(&tdc->lock);
377 UpgradeSToWLock(&avc->lock, 813);
378 avc->f.states &= ~CReadDir;
380 avc->readdir_pid = 0;
381 ReleaseSharedLock(&avc->lock);
385 afs_PutFakeStat(&fakestat);
392 /* in afs_pioctl.c */
393 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
396 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
397 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
399 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
406 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
408 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
412 #if defined(AFS_LINUX24_ENV)
413 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
414 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
415 vmap->vm_end - vmap->vm_start);
417 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
418 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
419 vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32,
423 /* get a validated vcache entry */
424 code = afs_linux_VerifyVCache(vcp, NULL);
426 /* Linux's Flushpage implementation doesn't use credp, so optimise
427 * our code to not need to crref() it */
428 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
430 code = generic_file_mmap(fp, vmap);
433 vcp->f.states |= CMAPPED;
440 afs_linux_open(struct inode *ip, struct file *fp)
442 struct vcache *vcp = VTOAFS(ip);
443 cred_t *credp = crref();
446 #ifdef AFS_LINUX24_ENV
450 code = afs_open(&vcp, fp->f_flags, credp);
452 #ifdef AFS_LINUX24_ENV
453 maybe_unlock_kernel();
457 return afs_convert_code(code);
461 afs_linux_release(struct inode *ip, struct file *fp)
463 struct vcache *vcp = VTOAFS(ip);
464 cred_t *credp = crref();
467 #ifdef AFS_LINUX24_ENV
471 code = afs_close(vcp, fp->f_flags, credp);
473 #ifdef AFS_LINUX24_ENV
474 maybe_unlock_kernel();
478 return afs_convert_code(code);
482 #if defined(AFS_LINUX24_ENV)
483 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
485 afs_linux_fsync(struct file *fp, struct dentry *dp)
489 struct inode *ip = FILE_INODE(fp);
490 cred_t *credp = crref();
492 #ifdef AFS_LINUX24_ENV
496 code = afs_fsync(VTOAFS(ip), credp);
498 #ifdef AFS_LINUX24_ENV
499 maybe_unlock_kernel();
502 return afs_convert_code(code);
508 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
511 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
512 cred_t *credp = crref();
513 struct AFS_FLOCK flock;
514 #if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
515 struct file_lock conflict;
516 #elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
517 struct file_lock *conflict;
520 /* Convert to a lock format afs_lockctl understands. */
521 memset(&flock, 0, sizeof(flock));
522 flock.l_type = flp->fl_type;
523 flock.l_pid = flp->fl_pid;
525 flock.l_start = flp->fl_start;
526 if (flp->fl_end == OFFSET_MAX)
527 flock.l_len = 0; /* Lock to end of file */
529 flock.l_len = flp->fl_end - flp->fl_start + 1;
531 /* Safe because there are no large files, yet */
532 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
533 if (cmd == F_GETLK64)
535 else if (cmd == F_SETLK64)
537 else if (cmd == F_SETLKW64)
539 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
542 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
545 #ifdef AFS_LINUX24_ENV
546 if ((code == 0 || flp->fl_type == F_UNLCK) &&
547 (cmd == F_SETLK || cmd == F_SETLKW)) {
548 # ifdef POSIX_LOCK_FILE_WAIT_ARG
549 code = posix_lock_file(fp, flp, 0);
551 flp->fl_flags &=~ FL_SLEEP;
552 code = posix_lock_file(fp, flp);
554 if (code && flp->fl_type != F_UNLCK) {
555 struct AFS_FLOCK flock2;
557 flock2.l_type = F_UNLCK;
559 afs_lockctl(vcp, &flock2, F_SETLK, credp);
563 /* If lockctl says there are no conflicting locks, then also check with the
564 * kernel, as lockctl knows nothing about byte range locks
566 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
567 # if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
568 if (posix_test_lock(fp, flp, &conflict)) {
569 locks_copy_lock(flp, &conflict);
570 flp->fl_type = F_UNLCK;
574 # elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
575 if ((conflict = posix_test_lock(fp, flp))) {
576 locks_copy_lock(flp, conflict);
577 flp->fl_type = F_UNLCK;
582 posix_test_lock(fp, flp);
583 /* If we found a lock in the kernel's structure, return it */
584 if (flp->fl_type != F_UNLCK) {
592 /* Convert flock back to Linux's file_lock */
593 flp->fl_type = flock.l_type;
594 flp->fl_pid = flock.l_pid;
595 flp->fl_start = flock.l_start;
596 if (flock.l_len == 0)
597 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
599 flp->fl_end = flock.l_start + flock.l_len - 1;
605 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
607 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
609 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
610 cred_t *credp = crref();
611 struct AFS_FLOCK flock;
612 /* Convert to a lock format afs_lockctl understands. */
613 memset(&flock, 0, sizeof(flock));
614 flock.l_type = flp->fl_type;
615 flock.l_pid = flp->fl_pid;
620 /* Safe because there are no large files, yet */
621 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
622 if (cmd == F_GETLK64)
624 else if (cmd == F_SETLK64)
626 else if (cmd == F_SETLKW64)
628 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
631 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
634 if ((code == 0 || flp->fl_type == F_UNLCK) &&
635 (cmd == F_SETLK || cmd == F_SETLKW)) {
636 flp->fl_flags &=~ FL_SLEEP;
637 code = flock_lock_file_wait(fp, flp);
638 if (code && flp->fl_type != F_UNLCK) {
639 struct AFS_FLOCK flock2;
641 flock2.l_type = F_UNLCK;
643 afs_lockctl(vcp, &flock2, F_SETLK, credp);
647 /* Convert flock back to Linux's file_lock */
648 flp->fl_type = flock.l_type;
649 flp->fl_pid = flock.l_pid;
657 * essentially the same as afs_fsync() but we need to get the return
658 * code for the sys_close() here, not afs_linux_release(), so call
659 * afs_StoreAllSegments() with AFS_LASTSTORE
662 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
663 afs_linux_flush(struct file *fp, fl_owner_t id)
665 afs_linux_flush(struct file *fp)
668 struct vrequest treq;
676 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
684 vcp = VTOAFS(FILE_INODE(fp));
686 code = afs_InitReq(&treq, credp);
689 /* If caching is bypassed for this file, or globally, just return 0 */
690 if(cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
693 ObtainReadLock(&vcp->lock);
694 if(vcp->cachingStates & FCSBypass)
696 ReleaseReadLock(&vcp->lock);
699 /* future proof: don't rely on 0 return from afs_InitReq */
703 ObtainSharedLock(&vcp->lock, 535);
704 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
705 UpgradeSToWLock(&vcp->lock, 536);
706 if (!AFS_IS_DISCONNECTED) {
707 code = afs_StoreAllSegments(vcp,
709 AFS_SYNC | AFS_LASTSTORE);
711 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
713 ConvertWToSLock(&vcp->lock);
715 code = afs_CheckCode(code, &treq, 54);
716 ReleaseSharedLock(&vcp->lock);
723 return afs_convert_code(code);
726 #if !defined(AFS_LINUX24_ENV)
727 /* Not allowed to directly read a directory. */
729 afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos)
737 struct file_operations afs_dir_fops = {
738 #if !defined(AFS_LINUX24_ENV)
739 .read = afs_linux_dir_read,
740 .lock = afs_linux_lock,
741 .fsync = afs_linux_fsync,
743 .read = generic_read_dir,
745 .readdir = afs_linux_readdir,
746 #ifdef HAVE_UNLOCKED_IOCTL
747 .unlocked_ioctl = afs_unlocked_xioctl,
751 #ifdef HAVE_COMPAT_IOCTL
752 .compat_ioctl = afs_unlocked_xioctl,
754 .open = afs_linux_open,
755 .release = afs_linux_release,
758 struct file_operations afs_file_fops = {
759 .read = afs_linux_read,
760 .write = afs_linux_write,
761 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
762 .aio_read = generic_file_aio_read,
763 .aio_write = generic_file_aio_write,
765 #ifdef HAVE_UNLOCKED_IOCTL
766 .unlocked_ioctl = afs_unlocked_xioctl,
770 #ifdef HAVE_COMPAT_IOCTL
771 .compat_ioctl = afs_unlocked_xioctl,
773 .mmap = afs_linux_mmap,
774 .open = afs_linux_open,
775 .flush = afs_linux_flush,
776 .release = afs_linux_release,
777 .fsync = afs_linux_fsync,
778 .lock = afs_linux_lock,
779 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
780 .flock = afs_linux_flock,
785 /**********************************************************************
786 * AFS Linux dentry operations
787 **********************************************************************/
789 /* check_bad_parent() : Checks if this dentry's vcache is a root vcache
790 * that has its mvid (parent dir's fid) pointer set to the wrong directory
791 * due to being mounted in multiple points at once. If so, check_bad_parent()
792 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
793 * dotdotfid and mtpoint fid members.
795 * dp - dentry to be checked.
799 * This dentry's vcache's mvid will be set to the correct parent directory's
801 * This root vnode's volume will have its dotdotfid and mtpoint fids set
802 * to the correct parent and mountpoint fids.
806 check_bad_parent(struct dentry *dp)
809 struct vcache *vcp = VTOAFS(dp->d_inode), *avc = NULL;
810 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
812 if (vcp->mvid->Fid.Volume != pvc->f.fid.Fid.Volume) { /* bad parent */
815 /* force a lookup, so vcp->mvid is fixed up */
816 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
817 if (!avc || vcp != avc) { /* bad, very bad.. */
818 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
819 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
820 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
821 ICL_TYPE_POINTER, dp);
824 AFS_RELE(AFSTOV(avc));
831 /* afs_linux_revalidate
832 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
835 afs_linux_revalidate(struct dentry *dp)
838 struct vcache *vcp = VTOAFS(dp->d_inode);
842 if (afs_shuttingdown)
845 #ifdef AFS_LINUX24_ENV
851 /* Make this a fast path (no crref), since it's called so often. */
852 if (vcp->f.states & CStatd) {
854 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
855 check_bad_parent(dp); /* check and correct mvid */
858 #ifdef AFS_LINUX24_ENV
865 /* This avoids the crref when we don't have to do it. Watch for
866 * changes in afs_getattr that don't get replicated here!
868 if (vcp->f.states & CStatd &&
869 (!afs_fakestat_enable || vcp->mvstat != 1) &&
871 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
872 code = afs_CopyOutAttrs(vcp, &vattr);
875 code = afs_getattr(vcp, &vattr, credp);
879 afs_fill_inode(AFSTOV(vcp), &vattr);
882 #ifdef AFS_LINUX24_ENV
883 maybe_unlock_kernel();
886 return afs_convert_code(code);
889 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
890 * In kernels 2.2.10 and above, we are passed an additional flags var which
891 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
892 * we are advised to follow the entry if it is a link or to make sure that
893 * it is a directory. But since the kernel itself checks these possibilities
894 * later on, we shouldn't have to do it until later. Perhaps in the future..
897 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
898 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
899 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
901 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
904 afs_linux_dentry_revalidate(struct dentry *dp)
908 cred_t *credp = NULL;
909 struct vcache *vcp, *pvcp, *tvc = NULL;
911 struct afs_fakestat_state fakestate;
913 #ifdef AFS_LINUX24_ENV
917 afs_InitFakeStat(&fakestate);
921 vcp = VTOAFS(dp->d_inode);
922 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
924 if (vcp == afs_globalVp)
927 if (vcp->mvstat == 1) { /* mount point */
928 if (vcp->mvid && (vcp->f.states & CMValid)) {
931 struct vrequest treq;
934 code = afs_InitReq(&treq, credp);
936 #ifdef AFS_DARWIN_ENV
937 (strcmp(dp->d_name.name, ".DS_Store") == 0) ||
938 (strcmp(dp->d_name.name, "Contents") == 0) ||
940 (strcmp(dp->d_name.name, ".directory") == 0)) {
944 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
946 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
947 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
948 /* a mount point, not yet replaced by its directory */
953 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
954 check_bad_parent(dp); /* check and correct mvid */
957 /* If the last looker changes, we should make sure the current
958 * looker still has permission to examine this file. This would
959 * always require a crref() which would be "slow".
961 if (vcp->last_looker != treq.uid) {
962 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
965 vcp->last_looker = treq.uid;
969 /* If the parent's DataVersion has changed or the vnode
970 * is longer valid, we need to do a full lookup. VerifyVCache
971 * isn't enough since the vnode may have been renamed.
974 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) {
977 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
978 if (!tvc || tvc != vcp)
981 if (afs_getattr(vcp, &vattr, credp))
984 vattr2inode(AFSTOV(vcp), &vattr);
985 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
988 /* should we always update the attributes at this point? */
989 /* unlikely--the vcache entry hasn't changed */
993 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
994 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
998 /* No change in parent's DataVersion so this negative
999 * lookup is still valid. BUT, if a server is down a
1000 * negative lookup can result so there should be a
1001 * liftime as well. For now, always expire.
1014 afs_PutFakeStat(&fakestate);
1020 shrink_dcache_parent(dp);
1023 #ifdef AFS_LINUX24_ENV
1024 maybe_unlock_kernel();
1029 if (have_submounts(dp))
1037 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1039 struct vcache *vcp = VTOAFS(ip);
1042 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1043 (void) afs_InactiveVCache(vcp, NULL);
1046 #ifdef DCACHE_NFSFS_RENAMED
1047 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
1054 afs_dentry_delete(struct dentry *dp)
1056 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1057 return 1; /* bad inode? */
1062 struct dentry_operations afs_dentry_operations = {
1063 .d_revalidate = afs_linux_dentry_revalidate,
1064 .d_delete = afs_dentry_delete,
1065 .d_iput = afs_dentry_iput,
1068 /**********************************************************************
1069 * AFS Linux inode operations
1070 **********************************************************************/
1074 * Merely need to set enough of vattr to get us through the create. Note
1075 * that the higher level code (open_namei) will take care of any tuncation
1076 * explicitly. Exclusive open is also taken care of in open_namei.
1078 * name is in kernel space at this point.
1081 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1082 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1083 struct nameidata *nd)
1085 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1089 cred_t *credp = crref();
1090 const char *name = dp->d_name.name;
1095 vattr.va_mode = mode;
1096 vattr.va_type = mode & S_IFMT;
1099 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1103 struct inode *ip = AFSTOV(vcp);
1105 afs_getattr(vcp, &vattr, credp);
1106 afs_fill_inode(ip, &vattr);
1107 insert_inode_hash(ip);
1108 dp->d_op = &afs_dentry_operations;
1109 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1110 d_instantiate(dp, ip);
1115 return afs_convert_code(code);
1118 /* afs_linux_lookup */
1119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1120 static struct dentry *
1121 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1122 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1123 struct nameidata *nd)
1125 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1129 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1132 cred_t *credp = crref();
1133 struct vcache *vcp = NULL;
1134 const char *comp = dp->d_name.name;
1135 struct inode *ip = NULL;
1139 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1145 afs_getattr(vcp, &vattr, credp);
1146 afs_fill_inode(ip, &vattr);
1148 #ifdef HAVE_LINUX_HLIST_UNHASHED
1149 hlist_unhashed(&ip->i_hash)
1151 ip->i_hash.prev == NULL
1154 insert_inode_hash(ip);
1156 dp->d_op = &afs_dentry_operations;
1157 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1160 #if defined(AFS_LINUX24_ENV)
1161 if (ip && S_ISDIR(ip->i_mode)) {
1162 struct dentry *alias;
1164 /* Try to invalidate an existing alias in favor of our new one */
1165 alias = d_find_alias(ip);
1167 if (d_invalidate(alias) == 0) {
1181 /* It's ok for the file to not be found. That's noted by the caller by
1182 * seeing that the dp->d_inode field is NULL.
1184 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1188 return ERR_PTR(afs_convert_code(code));
1192 return afs_convert_code(code);
1197 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1200 cred_t *credp = crref();
1201 const char *name = newdp->d_name.name;
1202 struct inode *oldip = olddp->d_inode;
1204 /* If afs_link returned the vnode, we could instantiate the
1205 * dentry. Since it's not, we drop this one and do a new lookup.
1210 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1214 return afs_convert_code(code);
1218 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1221 cred_t *credp = crref();
1222 const char *name = dp->d_name.name;
1223 struct vcache *tvc = VTOAFS(dp->d_inode);
1225 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1226 && !(tvc->f.states & CUnlinked)) {
1227 struct dentry *__dp;
1237 osi_FreeSmallSpace(__name);
1238 __name = afs_newname();
1241 __dp = lookup_one_len(__name, dp->d_parent, strlen(__name));
1245 } while (__dp->d_inode != NULL);
1248 code = afs_rename(VTOAFS(dip), (char *)dp->d_name.name, VTOAFS(dip), (char *)__dp->d_name.name, credp);
1250 tvc->mvid = (void *) __name;
1253 crfree(tvc->uncred);
1255 tvc->uncred = credp;
1256 tvc->f.states |= CUnlinked;
1257 #ifdef DCACHE_NFSFS_RENAMED
1258 dp->d_flags |= DCACHE_NFSFS_RENAMED;
1261 osi_FreeSmallSpace(__name);
1266 __dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1275 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1281 return afs_convert_code(code);
1286 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1289 cred_t *credp = crref();
1291 const char *name = dp->d_name.name;
1293 /* If afs_symlink returned the vnode, we could instantiate the
1294 * dentry. Since it's not, we drop this one and do a new lookup.
1300 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1303 return afs_convert_code(code);
1307 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1310 cred_t *credp = crref();
1311 struct vcache *tvcp = NULL;
1313 const char *name = dp->d_name.name;
1316 vattr.va_mask = ATTR_MODE;
1317 vattr.va_mode = mode;
1319 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1322 struct inode *ip = AFSTOV(tvcp);
1324 afs_getattr(tvcp, &vattr, credp);
1325 afs_fill_inode(ip, &vattr);
1327 dp->d_op = &afs_dentry_operations;
1328 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1329 d_instantiate(dp, ip);
1334 return afs_convert_code(code);
1338 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1341 cred_t *credp = crref();
1342 const char *name = dp->d_name.name;
1344 /* locking kernel conflicts with glock? */
1347 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1350 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1351 * that failed because a directory is not empty. So, we map
1352 * EEXIST to ENOTEMPTY on linux.
1354 if (code == EEXIST) {
1363 return afs_convert_code(code);
1368 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1369 struct inode *newip, struct dentry *newdp)
1372 cred_t *credp = crref();
1373 const char *oldname = olddp->d_name.name;
1374 const char *newname = newdp->d_name.name;
1375 struct dentry *rehash = NULL;
1377 if (!list_empty(&newdp->d_hash)) {
1382 #if defined(AFS_LINUX24_ENV)
1383 if (atomic_read(&olddp->d_count) > 1)
1384 shrink_dcache_parent(olddp);
1388 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1392 olddp->d_time = 0; /* force to revalidate */
1398 return afs_convert_code(code);
1402 /* afs_linux_ireadlink
1403 * Internal readlink which can return link contents to user or kernel space.
1404 * Note that the buffer is NOT supposed to be null-terminated.
1407 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1410 cred_t *credp = crref();
1414 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1415 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1419 return maxlen - tuio.uio_resid;
1421 return afs_convert_code(code);
1424 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1425 /* afs_linux_readlink
1426 * Fill target (which is in user space) with contents of symlink.
1429 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1432 struct inode *ip = dp->d_inode;
1435 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1441 /* afs_linux_follow_link
1442 * a file system dependent link following routine.
1444 #if defined(AFS_LINUX24_ENV)
1445 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1450 name = osi_Alloc(PATH_MAX);
1456 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1464 code = vfs_follow_link(nd, name);
1467 osi_Free(name, PATH_MAX);
1472 #else /* !defined(AFS_LINUX24_ENV) */
1474 static struct dentry *
1475 afs_linux_follow_link(struct dentry *dp, struct dentry *basep,
1476 unsigned int follow)
1484 name = osi_Alloc(PATH_MAX + 1);
1488 return ERR_PTR(-EIO);
1491 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1496 if (code < -MAX_ERRNO)
1497 res = ERR_PTR(-EIO);
1499 res = ERR_PTR(code);
1502 res = lookup_dentry(name, basep, follow);
1506 osi_Free(name, PATH_MAX + 1);
1510 #endif /* AFS_LINUX24_ENV */
1511 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1514 afs_linux_can_bypass(struct inode *ip) {
1515 switch(cache_bypass_strategy) {
1516 case NEVER_BYPASS_CACHE:
1518 case ALWAYS_BYPASS_CACHE:
1520 case LARGE_FILES_BYPASS_CACHE:
1521 if(i_size_read(ip) > cache_bypass_threshold)
1528 /* afs_linux_readpage
1529 * all reads come through here. A strategy-like read call.
1532 afs_linux_readpage(struct file *fp, struct page *pp)
1535 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1537 afs_offs_t offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1539 ulong address = afs_linux_page_address(pp);
1540 afs_offs_t offset = pageoff(pp);
1542 afs_int32 bypasscache = 0; /* bypass for this read */
1543 struct nocache_read_request *ancr;
1544 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1548 struct iovec *iovecp;
1549 struct inode *ip = FILE_INODE(fp);
1550 afs_int32 cnt = page_count(pp);
1551 struct vcache *avc = VTOAFS(ip);
1555 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1559 atomic_add(1, &pp->count);
1560 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1561 clear_bit(PG_error, &pp->flags);
1563 /* if bypasscache, receiver frees, else we do */
1564 auio = osi_Alloc(sizeof(uio_t));
1565 iovecp = osi_Alloc(sizeof(struct iovec));
1567 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1570 bypasscache = afs_linux_can_bypass(ip);
1572 /* In the new incarnation of selective caching, a file's caching policy
1573 * can change, eg because file size exceeds threshold, etc. */
1574 trydo_cache_transition(avc, credp, bypasscache);
1579 /* save the page for background map */
1580 auio->uio_iov->iov_base = (void*) pp;
1581 /* the background thread will free this */
1582 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1584 ancr->offset = offset;
1585 ancr->length = PAGE_SIZE;
1587 maybe_lock_kernel();
1588 code = afs_ReadNoCache(avc, ancr, credp);
1589 maybe_unlock_kernel();
1591 goto done; /* skips release page, doing it in bg thread */
1594 #ifdef AFS_LINUX24_ENV
1595 maybe_lock_kernel();
1599 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1600 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1601 99999); /* not a possible code value */
1603 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1605 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1606 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1608 AFS_DISCON_UNLOCK();
1610 #ifdef AFS_LINUX24_ENV
1611 maybe_unlock_kernel();
1614 /* XXX valid for no-cache also? Check last bits of files... :)
1615 * Cognate code goes in afs_NoCacheFetchProc. */
1616 if (auio->uio_resid) /* zero remainder of page */
1617 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1620 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1621 flush_dcache_page(pp);
1622 SetPageUptodate(pp);
1624 set_bit(PG_uptodate, &pp->flags);
1628 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1632 clear_bit(PG_locked, &pp->flags);
1637 /* do not call afs_GetDCache if cache is bypassed */
1641 /* free if not bypassing cache */
1642 osi_Free(auio, sizeof(uio_t));
1643 osi_Free(iovecp, sizeof(struct iovec));
1645 if (!code && AFS_CHUNKOFFSET(offset) == 0) {
1647 struct vrequest treq;
1650 code = afs_InitReq(&treq, credp);
1651 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
1652 tdc = afs_FindDCache(avc, offset);
1654 if (!(tdc->mflags & DFNextStarted))
1655 afs_PrefetchChunk(avc, tdc, credp, &treq);
1658 ReleaseWriteLock(&avc->lock);
1665 return afs_convert_code(code);
1668 #if defined(AFS_LINUX24_ENV)
1670 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1671 unsigned long offset, unsigned int count)
1673 struct vcache *vcp = VTOAFS(ip);
1682 buffer = kmap(pp) + offset;
1683 base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
1686 maybe_lock_kernel();
1688 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1689 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1690 ICL_TYPE_INT32, 99999);
1692 ObtainWriteLock(&vcp->lock, 532);
1693 if (vcp->f.states & CPageWrite) {
1694 ReleaseWriteLock(&vcp->lock);
1696 maybe_unlock_kernel();
1699 /* should mark it dirty? */
1702 vcp->f.states |= CPageWrite;
1703 ReleaseWriteLock(&vcp->lock);
1705 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1707 code = afs_write(vcp, &tuio, f_flags, credp, 0);
1709 i_size_write(ip, vcp->f.m.Length);
1710 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
1712 ObtainWriteLock(&vcp->lock, 533);
1714 struct vrequest treq;
1716 if (!afs_InitReq(&treq, credp))
1717 code = afs_DoPartialWrite(vcp, &treq);
1719 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
1721 vcp->f.states &= ~CPageWrite;
1722 ReleaseWriteLock(&vcp->lock);
1724 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1725 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1726 ICL_TYPE_INT32, code);
1729 maybe_unlock_kernel();
1738 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
1739 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
1741 afs_linux_writepage(struct page *pp)
1744 struct address_space *mapping = pp->mapping;
1745 struct inode *inode;
1746 unsigned long end_index;
1747 unsigned offset = PAGE_CACHE_SIZE;
1750 if (PageLaunder(pp)) {
1751 return(fail_writepage(pp));
1754 inode = (struct inode *)mapping->host;
1755 end_index = i_size_read(inode) >> PAGE_CACHE_SHIFT;
1758 if (pp->index < end_index)
1760 /* things got complicated... */
1761 offset = i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
1762 /* OK, are we completely out? */
1763 if (pp->index >= end_index + 1 || !offset)
1766 status = afs_linux_writepage_sync(inode, pp, 0, offset);
1767 SetPageUptodate(pp);
1769 if (status == offset)
1775 /* afs_linux_updatepage
1776 * What one would have thought was writepage - write dirty page to file.
1777 * Called from generic_file_write. buffer is still in user space. pagep
1778 * has been filled in with old data if we're updating less than a page.
1781 afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset,
1782 unsigned int count, int sync)
1784 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
1785 u8 *page_addr = (u8 *) afs_linux_page_address(pp);
1791 set_bit(PG_locked, &pp->flags);
1796 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1797 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1798 ICL_TYPE_INT32, 99999);
1799 setup_uio(&tuio, &iovec, page_addr + offset,
1800 (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE,
1803 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1805 i_size_write(ip, vcp->f.m.Length);
1806 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
1809 struct vrequest treq;
1811 ObtainWriteLock(&vcp->lock, 533);
1812 vcp->f.m.Date = osi_Time(); /* set modification time */
1813 if (!afs_InitReq(&treq, credp))
1814 code = afs_DoPartialWrite(vcp, &treq);
1815 ReleaseWriteLock(&vcp->lock);
1818 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
1819 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1820 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1821 ICL_TYPE_INT32, code);
1823 AFS_DISCON_UNLOCK();
1827 clear_bit(PG_locked, &pp->flags);
1832 /* afs_linux_permission
1833 * Check access rights - returns error if can't check or permission denied.
1836 #ifdef IOP_PERMISSION_TAKES_NAMEIDATA
1837 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
1839 afs_linux_permission(struct inode *ip, int mode)
1843 cred_t *credp = crref();
1847 if (mode & MAY_EXEC)
1849 if (mode & MAY_READ)
1851 if (mode & MAY_WRITE)
1853 code = afs_access(VTOAFS(ip), tmp, credp);
1857 return afs_convert_code(code);
1860 #if defined(AFS_LINUX24_ENV) && !defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1862 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
1867 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
1868 offset, to - offset);
1875 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
1878 /* sometime between 2.4.0 and 2.4.19, the callers of prepare_write began to
1879 call kmap directly instead of relying on us to do it */
1885 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1887 afs_linux_write_end(struct file *file, struct address_space *mapping,
1888 loff_t pos, unsigned len, unsigned copied,
1889 struct page *page, void *fsdata)
1892 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
1894 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
1897 page_cache_release(page);
1902 afs_linux_write_begin(struct file *file, struct address_space *mapping,
1903 loff_t pos, unsigned len, unsigned flags,
1904 struct page **pagep, void **fsdata)
1907 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1908 #if defined(HAVE_LINUX_GRAB_CACHE_PAGE_WRITE_BEGIN)
1909 page = grab_cache_page_write_begin(mapping, index, flags);
1911 page = __grab_cache_page(mapping, index);
1920 static struct inode_operations afs_file_iops = {
1921 #if defined(AFS_LINUX24_ENV)
1922 .permission = afs_linux_permission,
1923 .revalidate = afs_linux_revalidate,
1924 .setattr = afs_notify_change,
1926 .default_file_ops = &afs_file_fops,
1927 .readpage = afs_linux_readpage,
1928 .revalidate = afs_linux_revalidate,
1929 .updatepage = afs_linux_updatepage,
1933 #if defined(AFS_LINUX24_ENV)
1934 static struct address_space_operations afs_file_aops = {
1935 .readpage = afs_linux_readpage,
1936 .writepage = afs_linux_writepage,
1937 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1938 .write_begin = afs_linux_write_begin,
1939 .write_end = afs_linux_write_end,
1941 .commit_write = afs_linux_commit_write,
1942 .prepare_write = afs_linux_prepare_write,
1948 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1949 * by what sort of operation is allowed.....
1952 static struct inode_operations afs_dir_iops = {
1953 #if !defined(AFS_LINUX24_ENV)
1954 .default_file_ops = &afs_dir_fops,
1956 .setattr = afs_notify_change,
1958 .create = afs_linux_create,
1959 .lookup = afs_linux_lookup,
1960 .link = afs_linux_link,
1961 .unlink = afs_linux_unlink,
1962 .symlink = afs_linux_symlink,
1963 .mkdir = afs_linux_mkdir,
1964 .rmdir = afs_linux_rmdir,
1965 .rename = afs_linux_rename,
1966 .revalidate = afs_linux_revalidate,
1967 .permission = afs_linux_permission,
1970 /* We really need a separate symlink set of ops, since do_follow_link()
1971 * determines if it _is_ a link by checking if the follow_link op is set.
1973 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1975 afs_symlink_filler(struct file *file, struct page *page)
1977 struct inode *ip = (struct inode *)page->mapping->host;
1978 char *p = (char *)kmap(page);
1981 maybe_lock_kernel();
1983 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
1988 p[code] = '\0'; /* null terminate? */
1989 maybe_unlock_kernel();
1991 SetPageUptodate(page);
1997 maybe_unlock_kernel();
2005 static struct address_space_operations afs_symlink_aops = {
2006 .readpage = afs_symlink_filler
2008 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2010 static struct inode_operations afs_symlink_iops = {
2011 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2012 .readlink = page_readlink,
2013 #if defined(HAVE_KERNEL_PAGE_FOLLOW_LINK)
2014 .follow_link = page_follow_link,
2016 .follow_link = page_follow_link_light,
2017 .put_link = page_put_link,
2019 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2020 .readlink = afs_linux_readlink,
2021 .follow_link = afs_linux_follow_link,
2022 #if !defined(AFS_LINUX24_ENV)
2023 .permission = afs_linux_permission,
2024 .revalidate = afs_linux_revalidate,
2026 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2027 #if defined(AFS_LINUX24_ENV)
2028 .setattr = afs_notify_change,
2033 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2037 vattr2inode(ip, vattr);
2039 /* Reset ops if symlink or directory. */
2040 if (S_ISREG(ip->i_mode)) {
2041 ip->i_op = &afs_file_iops;
2042 #if defined(AFS_LINUX24_ENV)
2043 ip->i_fop = &afs_file_fops;
2044 ip->i_data.a_ops = &afs_file_aops;
2047 } else if (S_ISDIR(ip->i_mode)) {
2048 ip->i_op = &afs_dir_iops;
2049 #if defined(AFS_LINUX24_ENV)
2050 ip->i_fop = &afs_dir_fops;
2053 } else if (S_ISLNK(ip->i_mode)) {
2054 ip->i_op = &afs_symlink_iops;
2055 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2056 ip->i_data.a_ops = &afs_symlink_aops;
2057 ip->i_mapping = &ip->i_data;