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 code = afs_dir_GetBlob(tdc, dirpos, &entry);
306 de = (struct DirEntry *)entry.data;
308 ino = afs_calc_inum (avc->f.fid.Fid.Volume, ntohl(de->fid.vnode));
311 len = strlen(de->name);
313 printf("afs_linux_readdir: afs_dir_GetBlob failed, null name (inode %lx, dirpos %d)\n",
314 (unsigned long)&tdc->f.inode, dirpos);
316 ReleaseSharedLock(&avc->lock);
322 /* filldir returns -EINVAL when the buffer is full. */
323 #if (defined(AFS_LINUX24_ENV) || defined(pgoff2loff)) && defined(DECLARE_FSTYPE)
325 unsigned int type = DT_UNKNOWN;
326 struct VenusFid afid;
329 afid.Cell = avc->f.fid.Cell;
330 afid.Fid.Volume = avc->f.fid.Fid.Volume;
331 afid.Fid.Vnode = ntohl(de->fid.vnode);
332 afid.Fid.Unique = ntohl(de->fid.vunique);
333 if ((avc->f.states & CForeign) == 0 && (ntohl(de->fid.vnode) & 1)) {
335 } else if ((tvc = afs_FindVCache(&afid, 0, 0))) {
338 } else if (((tvc->f.states) & (CStatd | CTruth))) {
339 /* CTruth will be set if the object has
344 else if (vtype == VREG)
346 /* Don't do this until we're sure it can't be a mtpt */
347 /* else if (vtype == VLNK)
349 /* what other types does AFS support? */
351 /* clean up from afs_FindVCache */
355 * If this is NFS readdirplus, then the filler is going to
356 * call getattr on this inode, which will deadlock if we're
360 code = (*filldir) (dirbuf, de->name, len, offset, ino, type);
364 code = (*filldir) (dirbuf, de->name, len, offset, ino);
369 offset = dirpos + 1 + ((len + 16) >> 5);
371 /* If filldir didn't fill in the last one this is still pointing to that
374 fp->f_pos = (loff_t) offset;
376 ReleaseReadLock(&tdc->lock);
378 UpgradeSToWLock(&avc->lock, 813);
379 avc->f.states &= ~CReadDir;
381 avc->readdir_pid = 0;
382 ReleaseSharedLock(&avc->lock);
386 afs_PutFakeStat(&fakestat);
393 /* in afs_pioctl.c */
394 extern int afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
397 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
398 static long afs_unlocked_xioctl(struct file *fp, unsigned int com,
400 return afs_xioctl(FILE_INODE(fp), fp, com, arg);
407 afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
409 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
413 #if defined(AFS_LINUX24_ENV)
414 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
415 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
416 vmap->vm_end - vmap->vm_start);
418 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
419 ICL_TYPE_POINTER, vmap->vm_start, ICL_TYPE_INT32,
420 vmap->vm_end - vmap->vm_start, ICL_TYPE_INT32,
424 /* get a validated vcache entry */
425 code = afs_linux_VerifyVCache(vcp, NULL);
427 /* Linux's Flushpage implementation doesn't use credp, so optimise
428 * our code to not need to crref() it */
429 osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
431 code = generic_file_mmap(fp, vmap);
434 vcp->f.states |= CMAPPED;
441 afs_linux_open(struct inode *ip, struct file *fp)
443 struct vcache *vcp = VTOAFS(ip);
444 cred_t *credp = crref();
447 #ifdef AFS_LINUX24_ENV
451 code = afs_open(&vcp, fp->f_flags, credp);
453 #ifdef AFS_LINUX24_ENV
454 maybe_unlock_kernel();
458 return afs_convert_code(code);
462 afs_linux_release(struct inode *ip, struct file *fp)
464 struct vcache *vcp = VTOAFS(ip);
465 cred_t *credp = crref();
468 #ifdef AFS_LINUX24_ENV
472 code = afs_close(vcp, fp->f_flags, credp);
474 #ifdef AFS_LINUX24_ENV
475 maybe_unlock_kernel();
479 return afs_convert_code(code);
483 #if defined(AFS_LINUX24_ENV)
484 afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
486 afs_linux_fsync(struct file *fp, struct dentry *dp)
490 struct inode *ip = FILE_INODE(fp);
491 cred_t *credp = crref();
493 #ifdef AFS_LINUX24_ENV
497 code = afs_fsync(VTOAFS(ip), credp);
499 #ifdef AFS_LINUX24_ENV
500 maybe_unlock_kernel();
503 return afs_convert_code(code);
509 afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
512 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
513 cred_t *credp = crref();
514 struct AFS_FLOCK flock;
515 #if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
516 struct file_lock conflict;
517 #elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
518 struct file_lock *conflict;
521 /* Convert to a lock format afs_lockctl understands. */
522 memset(&flock, 0, sizeof(flock));
523 flock.l_type = flp->fl_type;
524 flock.l_pid = flp->fl_pid;
526 flock.l_start = flp->fl_start;
527 if (flp->fl_end == OFFSET_MAX)
528 flock.l_len = 0; /* Lock to end of file */
530 flock.l_len = flp->fl_end - flp->fl_start + 1;
532 /* Safe because there are no large files, yet */
533 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
534 if (cmd == F_GETLK64)
536 else if (cmd == F_SETLK64)
538 else if (cmd == F_SETLKW64)
540 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
543 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
546 #ifdef AFS_LINUX24_ENV
547 if ((code == 0 || flp->fl_type == F_UNLCK) &&
548 (cmd == F_SETLK || cmd == F_SETLKW)) {
549 # ifdef POSIX_LOCK_FILE_WAIT_ARG
550 code = posix_lock_file(fp, flp, 0);
552 flp->fl_flags &=~ FL_SLEEP;
553 code = posix_lock_file(fp, flp);
555 if (code && flp->fl_type != F_UNLCK) {
556 struct AFS_FLOCK flock2;
558 flock2.l_type = F_UNLCK;
560 afs_lockctl(vcp, &flock2, F_SETLK, credp);
564 /* If lockctl says there are no conflicting locks, then also check with the
565 * kernel, as lockctl knows nothing about byte range locks
567 if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
568 # if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
569 if (posix_test_lock(fp, flp, &conflict)) {
570 locks_copy_lock(flp, &conflict);
571 flp->fl_type = F_UNLCK;
575 # elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
576 if ((conflict = posix_test_lock(fp, flp))) {
577 locks_copy_lock(flp, conflict);
578 flp->fl_type = F_UNLCK;
583 posix_test_lock(fp, flp);
584 /* If we found a lock in the kernel's structure, return it */
585 if (flp->fl_type != F_UNLCK) {
593 /* Convert flock back to Linux's file_lock */
594 flp->fl_type = flock.l_type;
595 flp->fl_pid = flock.l_pid;
596 flp->fl_start = flock.l_start;
597 if (flock.l_len == 0)
598 flp->fl_end = OFFSET_MAX; /* Lock to end of file */
600 flp->fl_end = flock.l_start + flock.l_len - 1;
606 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
608 afs_linux_flock(struct file *fp, int cmd, struct file_lock *flp) {
610 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
611 cred_t *credp = crref();
612 struct AFS_FLOCK flock;
613 /* Convert to a lock format afs_lockctl understands. */
614 memset(&flock, 0, sizeof(flock));
615 flock.l_type = flp->fl_type;
616 flock.l_pid = flp->fl_pid;
621 /* Safe because there are no large files, yet */
622 #if defined(F_GETLK64) && (F_GETLK != F_GETLK64)
623 if (cmd == F_GETLK64)
625 else if (cmd == F_SETLK64)
627 else if (cmd == F_SETLKW64)
629 #endif /* F_GETLK64 && F_GETLK != F_GETLK64 */
632 code = afs_convert_code(afs_lockctl(vcp, &flock, cmd, credp));
635 if ((code == 0 || flp->fl_type == F_UNLCK) &&
636 (cmd == F_SETLK || cmd == F_SETLKW)) {
637 flp->fl_flags &=~ FL_SLEEP;
638 code = flock_lock_file_wait(fp, flp);
639 if (code && flp->fl_type != F_UNLCK) {
640 struct AFS_FLOCK flock2;
642 flock2.l_type = F_UNLCK;
644 afs_lockctl(vcp, &flock2, F_SETLK, credp);
648 /* Convert flock back to Linux's file_lock */
649 flp->fl_type = flock.l_type;
650 flp->fl_pid = flock.l_pid;
658 * essentially the same as afs_fsync() but we need to get the return
659 * code for the sys_close() here, not afs_linux_release(), so call
660 * afs_StoreAllSegments() with AFS_LASTSTORE
663 #if defined(FOP_FLUSH_TAKES_FL_OWNER_T)
664 afs_linux_flush(struct file *fp, fl_owner_t id)
666 afs_linux_flush(struct file *fp)
669 struct vrequest treq;
677 if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { /* readers dont flush */
685 vcp = VTOAFS(FILE_INODE(fp));
687 code = afs_InitReq(&treq, credp);
690 /* If caching is bypassed for this file, or globally, just return 0 */
691 if(cache_bypass_strategy == ALWAYS_BYPASS_CACHE)
694 ObtainReadLock(&vcp->lock);
695 if(vcp->cachingStates & FCSBypass)
697 ReleaseReadLock(&vcp->lock);
700 /* future proof: don't rely on 0 return from afs_InitReq */
704 ObtainSharedLock(&vcp->lock, 535);
705 if ((vcp->execsOrWriters > 0) && (file_count(fp) == 1)) {
706 UpgradeSToWLock(&vcp->lock, 536);
707 if (!AFS_IS_DISCONNECTED) {
708 code = afs_StoreAllSegments(vcp,
710 AFS_SYNC | AFS_LASTSTORE);
712 afs_DisconAddDirty(vcp, VDisconWriteOsiFlush, 1);
714 ConvertWToSLock(&vcp->lock);
716 code = afs_CheckCode(code, &treq, 54);
717 ReleaseSharedLock(&vcp->lock);
724 return afs_convert_code(code);
727 #if !defined(AFS_LINUX24_ENV)
728 /* Not allowed to directly read a directory. */
730 afs_linux_dir_read(struct file * fp, char *buf, size_t count, loff_t * ppos)
738 struct file_operations afs_dir_fops = {
739 #if !defined(AFS_LINUX24_ENV)
740 .read = afs_linux_dir_read,
741 .lock = afs_linux_lock,
742 .fsync = afs_linux_fsync,
744 .read = generic_read_dir,
746 .readdir = afs_linux_readdir,
747 #ifdef HAVE_UNLOCKED_IOCTL
748 .unlocked_ioctl = afs_unlocked_xioctl,
752 #ifdef HAVE_COMPAT_IOCTL
753 .compat_ioctl = afs_unlocked_xioctl,
755 .open = afs_linux_open,
756 .release = afs_linux_release,
759 struct file_operations afs_file_fops = {
760 .read = afs_linux_read,
761 .write = afs_linux_write,
762 #ifdef HAVE_LINUX_GENERIC_FILE_AIO_READ
763 .aio_read = generic_file_aio_read,
764 .aio_write = generic_file_aio_write,
766 #ifdef HAVE_UNLOCKED_IOCTL
767 .unlocked_ioctl = afs_unlocked_xioctl,
771 #ifdef HAVE_COMPAT_IOCTL
772 .compat_ioctl = afs_unlocked_xioctl,
774 .mmap = afs_linux_mmap,
775 .open = afs_linux_open,
776 .flush = afs_linux_flush,
777 .release = afs_linux_release,
778 .fsync = afs_linux_fsync,
779 .lock = afs_linux_lock,
780 #ifdef STRUCT_FILE_OPERATIONS_HAS_FLOCK
781 .flock = afs_linux_flock,
786 /**********************************************************************
787 * AFS Linux dentry operations
788 **********************************************************************/
790 /* check_bad_parent() : Checks if this dentry's vcache is a root vcache
791 * that has its mvid (parent dir's fid) pointer set to the wrong directory
792 * due to being mounted in multiple points at once. If so, check_bad_parent()
793 * calls afs_lookup() to correct the vcache's mvid, as well as the volume's
794 * dotdotfid and mtpoint fid members.
796 * dp - dentry to be checked.
800 * This dentry's vcache's mvid will be set to the correct parent directory's
802 * This root vnode's volume will have its dotdotfid and mtpoint fids set
803 * to the correct parent and mountpoint fids.
807 check_bad_parent(struct dentry *dp)
810 struct vcache *vcp = VTOAFS(dp->d_inode), *avc = NULL;
811 struct vcache *pvc = VTOAFS(dp->d_parent->d_inode);
813 if (vcp->mvid->Fid.Volume != pvc->f.fid.Fid.Volume) { /* bad parent */
816 /* force a lookup, so vcp->mvid is fixed up */
817 afs_lookup(pvc, (char *)dp->d_name.name, &avc, credp);
818 if (!avc || vcp != avc) { /* bad, very bad.. */
819 afs_Trace4(afs_iclSetp, CM_TRACE_TMP_1S3L, ICL_TYPE_STRING,
820 "check_bad_parent: bad pointer returned from afs_lookup origvc newvc dentry",
821 ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, avc,
822 ICL_TYPE_POINTER, dp);
825 AFS_RELE(AFSTOV(avc));
832 /* afs_linux_revalidate
833 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
836 afs_linux_revalidate(struct dentry *dp)
839 struct vcache *vcp = VTOAFS(dp->d_inode);
843 if (afs_shuttingdown)
846 #ifdef AFS_LINUX24_ENV
852 /* Make this a fast path (no crref), since it's called so often. */
853 if (vcp->f.states & CStatd) {
855 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
856 check_bad_parent(dp); /* check and correct mvid */
859 #ifdef AFS_LINUX24_ENV
866 /* This avoids the crref when we don't have to do it. Watch for
867 * changes in afs_getattr that don't get replicated here!
869 if (vcp->f.states & CStatd &&
870 (!afs_fakestat_enable || vcp->mvstat != 1) &&
872 (vType(vcp) == VDIR || vType(vcp) == VLNK)) {
873 code = afs_CopyOutAttrs(vcp, &vattr);
876 code = afs_getattr(vcp, &vattr, credp);
880 afs_fill_inode(AFSTOV(vcp), &vattr);
883 #ifdef AFS_LINUX24_ENV
884 maybe_unlock_kernel();
887 return afs_convert_code(code);
890 /* Validate a dentry. Return 1 if unchanged, 0 if VFS layer should re-evaluate.
891 * In kernels 2.2.10 and above, we are passed an additional flags var which
892 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
893 * we are advised to follow the entry if it is a link or to make sure that
894 * it is a directory. But since the kernel itself checks these possibilities
895 * later on, we shouldn't have to do it until later. Perhaps in the future..
898 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
899 #ifdef DOP_REVALIDATE_TAKES_NAMEIDATA
900 afs_linux_dentry_revalidate(struct dentry *dp, struct nameidata *nd)
902 afs_linux_dentry_revalidate(struct dentry *dp, int flags)
905 afs_linux_dentry_revalidate(struct dentry *dp)
909 cred_t *credp = NULL;
910 struct vcache *vcp, *pvcp, *tvc = NULL;
912 struct afs_fakestat_state fakestate;
914 #ifdef AFS_LINUX24_ENV
918 afs_InitFakeStat(&fakestate);
922 vcp = VTOAFS(dp->d_inode);
923 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
925 if (vcp == afs_globalVp)
928 if (vcp->mvstat == 1) { /* mount point */
929 if (vcp->mvid && (vcp->f.states & CMValid)) {
932 struct vrequest treq;
935 code = afs_InitReq(&treq, credp);
937 #ifdef AFS_DARWIN_ENV
938 (strcmp(dp->d_name.name, ".DS_Store") == 0) ||
939 (strcmp(dp->d_name.name, "Contents") == 0) ||
941 (strcmp(dp->d_name.name, ".directory") == 0)) {
945 code = afs_TryEvalFakeStat(&vcp, &fakestate, &treq);
947 code = afs_EvalFakeStat(&vcp, &fakestate, &treq);
948 if ((tryEvalOnly && vcp->mvstat == 1) || code) {
949 /* a mount point, not yet replaced by its directory */
954 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
955 check_bad_parent(dp); /* check and correct mvid */
958 /* If the last looker changes, we should make sure the current
959 * looker still has permission to examine this file. This would
960 * always require a crref() which would be "slow".
962 if (vcp->last_looker != treq.uid) {
963 if (!afs_AccessOK(vcp, (vType(vcp) == VREG) ? PRSFS_READ : PRSFS_LOOKUP, &treq, CHECK_MODE_BITS))
966 vcp->last_looker = treq.uid;
970 /* If the parent's DataVersion has changed or the vnode
971 * is longer valid, we need to do a full lookup. VerifyVCache
972 * isn't enough since the vnode may have been renamed.
975 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time || !(vcp->f.states & CStatd)) {
978 afs_lookup(pvcp, (char *)dp->d_name.name, &tvc, credp);
979 if (!tvc || tvc != vcp)
982 if (afs_getattr(vcp, &vattr, credp))
985 vattr2inode(AFSTOV(vcp), &vattr);
986 dp->d_time = hgetlo(pvcp->f.m.DataVersion);
989 /* should we always update the attributes at this point? */
990 /* unlikely--the vcache entry hasn't changed */
994 pvcp = VTOAFS(dp->d_parent->d_inode); /* dget_parent()? */
995 if (hgetlo(pvcp->f.m.DataVersion) > dp->d_time)
999 /* No change in parent's DataVersion so this negative
1000 * lookup is still valid. BUT, if a server is down a
1001 * negative lookup can result so there should be a
1002 * liftime as well. For now, always expire.
1015 afs_PutFakeStat(&fakestate);
1021 shrink_dcache_parent(dp);
1024 #ifdef AFS_LINUX24_ENV
1025 maybe_unlock_kernel();
1030 if (have_submounts(dp))
1038 afs_dentry_iput(struct dentry *dp, struct inode *ip)
1040 struct vcache *vcp = VTOAFS(ip);
1043 if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
1044 (void) afs_InactiveVCache(vcp, NULL);
1047 #ifdef DCACHE_NFSFS_RENAMED
1048 dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
1055 afs_dentry_delete(struct dentry *dp)
1057 if (dp->d_inode && (VTOAFS(dp->d_inode)->f.states & CUnlinked))
1058 return 1; /* bad inode? */
1063 struct dentry_operations afs_dentry_operations = {
1064 .d_revalidate = afs_linux_dentry_revalidate,
1065 .d_delete = afs_dentry_delete,
1066 .d_iput = afs_dentry_iput,
1069 /**********************************************************************
1070 * AFS Linux inode operations
1071 **********************************************************************/
1075 * Merely need to set enough of vattr to get us through the create. Note
1076 * that the higher level code (open_namei) will take care of any tuncation
1077 * explicitly. Exclusive open is also taken care of in open_namei.
1079 * name is in kernel space at this point.
1082 #ifdef IOP_CREATE_TAKES_NAMEIDATA
1083 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
1084 struct nameidata *nd)
1086 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
1090 cred_t *credp = crref();
1091 const char *name = dp->d_name.name;
1096 vattr.va_mode = mode;
1097 vattr.va_type = mode & S_IFMT;
1100 code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
1104 struct inode *ip = AFSTOV(vcp);
1106 afs_getattr(vcp, &vattr, credp);
1107 afs_fill_inode(ip, &vattr);
1108 insert_inode_hash(ip);
1109 dp->d_op = &afs_dentry_operations;
1110 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1111 d_instantiate(dp, ip);
1116 return afs_convert_code(code);
1119 /* afs_linux_lookup */
1120 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1121 static struct dentry *
1122 #ifdef IOP_LOOKUP_TAKES_NAMEIDATA
1123 afs_linux_lookup(struct inode *dip, struct dentry *dp,
1124 struct nameidata *nd)
1126 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1130 afs_linux_lookup(struct inode *dip, struct dentry *dp)
1133 cred_t *credp = crref();
1134 struct vcache *vcp = NULL;
1135 const char *comp = dp->d_name.name;
1136 struct inode *ip = NULL;
1140 code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
1146 afs_getattr(vcp, &vattr, credp);
1147 afs_fill_inode(ip, &vattr);
1149 #ifdef HAVE_LINUX_HLIST_UNHASHED
1150 hlist_unhashed(&ip->i_hash)
1152 ip->i_hash.prev == NULL
1155 insert_inode_hash(ip);
1157 dp->d_op = &afs_dentry_operations;
1158 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1161 #if defined(AFS_LINUX24_ENV)
1162 if (ip && S_ISDIR(ip->i_mode)) {
1163 struct dentry *alias;
1165 /* Try to invalidate an existing alias in favor of our new one */
1166 alias = d_find_alias(ip);
1168 if (d_invalidate(alias) == 0) {
1182 /* It's ok for the file to not be found. That's noted by the caller by
1183 * seeing that the dp->d_inode field is NULL.
1185 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
1189 return ERR_PTR(afs_convert_code(code));
1193 return afs_convert_code(code);
1198 afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp)
1201 cred_t *credp = crref();
1202 const char *name = newdp->d_name.name;
1203 struct inode *oldip = olddp->d_inode;
1205 /* If afs_link returned the vnode, we could instantiate the
1206 * dentry. Since it's not, we drop this one and do a new lookup.
1211 code = afs_link(VTOAFS(oldip), VTOAFS(dip), (char *)name, credp);
1215 return afs_convert_code(code);
1219 afs_linux_unlink(struct inode *dip, struct dentry *dp)
1222 cred_t *credp = crref();
1223 const char *name = dp->d_name.name;
1224 struct vcache *tvc = VTOAFS(dp->d_inode);
1226 if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
1227 && !(tvc->f.states & CUnlinked)) {
1228 struct dentry *__dp;
1238 osi_FreeSmallSpace(__name);
1239 __name = afs_newname();
1242 __dp = lookup_one_len(__name, dp->d_parent, strlen(__name));
1246 } while (__dp->d_inode != NULL);
1249 code = afs_rename(VTOAFS(dip), (char *)dp->d_name.name, VTOAFS(dip), (char *)__dp->d_name.name, credp);
1251 tvc->mvid = (void *) __name;
1254 crfree(tvc->uncred);
1256 tvc->uncred = credp;
1257 tvc->f.states |= CUnlinked;
1258 #ifdef DCACHE_NFSFS_RENAMED
1259 dp->d_flags |= DCACHE_NFSFS_RENAMED;
1262 osi_FreeSmallSpace(__name);
1267 __dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1276 code = afs_remove(VTOAFS(dip), (char *)name, credp);
1282 return afs_convert_code(code);
1287 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
1290 cred_t *credp = crref();
1292 const char *name = dp->d_name.name;
1294 /* If afs_symlink returned the vnode, we could instantiate the
1295 * dentry. Since it's not, we drop this one and do a new lookup.
1301 code = afs_symlink(VTOAFS(dip), (char *)name, &vattr, (char *)target, credp);
1304 return afs_convert_code(code);
1308 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
1311 cred_t *credp = crref();
1312 struct vcache *tvcp = NULL;
1314 const char *name = dp->d_name.name;
1317 vattr.va_mask = ATTR_MODE;
1318 vattr.va_mode = mode;
1320 code = afs_mkdir(VTOAFS(dip), (char *)name, &vattr, &tvcp, credp);
1323 struct inode *ip = AFSTOV(tvcp);
1325 afs_getattr(tvcp, &vattr, credp);
1326 afs_fill_inode(ip, &vattr);
1328 dp->d_op = &afs_dentry_operations;
1329 dp->d_time = hgetlo(VTOAFS(dip)->f.m.DataVersion);
1330 d_instantiate(dp, ip);
1335 return afs_convert_code(code);
1339 afs_linux_rmdir(struct inode *dip, struct dentry *dp)
1342 cred_t *credp = crref();
1343 const char *name = dp->d_name.name;
1345 /* locking kernel conflicts with glock? */
1348 code = afs_rmdir(VTOAFS(dip), (char *)name, credp);
1351 /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
1352 * that failed because a directory is not empty. So, we map
1353 * EEXIST to ENOTEMPTY on linux.
1355 if (code == EEXIST) {
1364 return afs_convert_code(code);
1369 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1370 struct inode *newip, struct dentry *newdp)
1373 cred_t *credp = crref();
1374 const char *oldname = olddp->d_name.name;
1375 const char *newname = newdp->d_name.name;
1376 struct dentry *rehash = NULL;
1378 if (!list_empty(&newdp->d_hash)) {
1383 #if defined(AFS_LINUX24_ENV)
1384 if (atomic_read(&olddp->d_count) > 1)
1385 shrink_dcache_parent(olddp);
1389 code = afs_rename(VTOAFS(oldip), (char *)oldname, VTOAFS(newip), (char *)newname, credp);
1393 olddp->d_time = 0; /* force to revalidate */
1399 return afs_convert_code(code);
1403 /* afs_linux_ireadlink
1404 * Internal readlink which can return link contents to user or kernel space.
1405 * Note that the buffer is NOT supposed to be null-terminated.
1408 afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg)
1411 cred_t *credp = crref();
1415 setup_uio(&tuio, &iov, target, (afs_offs_t) 0, maxlen, UIO_READ, seg);
1416 code = afs_readlink(VTOAFS(ip), &tuio, credp);
1420 return maxlen - tuio.uio_resid;
1422 return afs_convert_code(code);
1425 #if !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1426 /* afs_linux_readlink
1427 * Fill target (which is in user space) with contents of symlink.
1430 afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1433 struct inode *ip = dp->d_inode;
1436 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1442 /* afs_linux_follow_link
1443 * a file system dependent link following routine.
1445 #if defined(AFS_LINUX24_ENV)
1446 static int afs_linux_follow_link(struct dentry *dentry, struct nameidata *nd)
1451 name = osi_Alloc(PATH_MAX);
1457 code = afs_linux_ireadlink(dentry->d_inode, name, PATH_MAX - 1, AFS_UIOSYS);
1465 code = vfs_follow_link(nd, name);
1468 osi_Free(name, PATH_MAX);
1473 #else /* !defined(AFS_LINUX24_ENV) */
1475 static struct dentry *
1476 afs_linux_follow_link(struct dentry *dp, struct dentry *basep,
1477 unsigned int follow)
1485 name = osi_Alloc(PATH_MAX + 1);
1489 return ERR_PTR(-EIO);
1492 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1497 if (code < -MAX_ERRNO)
1498 res = ERR_PTR(-EIO);
1500 res = ERR_PTR(code);
1503 res = lookup_dentry(name, basep, follow);
1507 osi_Free(name, PATH_MAX + 1);
1511 #endif /* AFS_LINUX24_ENV */
1512 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
1515 afs_linux_can_bypass(struct inode *ip) {
1516 switch(cache_bypass_strategy) {
1517 case NEVER_BYPASS_CACHE:
1519 case ALWAYS_BYPASS_CACHE:
1521 case LARGE_FILES_BYPASS_CACHE:
1522 if(i_size_read(ip) > cache_bypass_threshold)
1529 /* afs_linux_readpage
1530 * all reads come through here. A strategy-like read call.
1533 afs_linux_readpage(struct file *fp, struct page *pp)
1536 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1538 afs_offs_t offset = ((loff_t) pp->index) << PAGE_CACHE_SHIFT;
1540 ulong address = afs_linux_page_address(pp);
1541 afs_offs_t offset = pageoff(pp);
1543 afs_int32 bypasscache = 0; /* bypass for this read */
1544 struct nocache_read_request *ancr;
1545 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1549 struct iovec *iovecp;
1550 struct inode *ip = FILE_INODE(fp);
1551 afs_int32 cnt = page_count(pp);
1552 struct vcache *avc = VTOAFS(ip);
1556 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1560 atomic_add(1, &pp->count);
1561 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1562 clear_bit(PG_error, &pp->flags);
1564 /* if bypasscache, receiver frees, else we do */
1565 auio = osi_Alloc(sizeof(struct uio));
1566 iovecp = osi_Alloc(sizeof(struct iovec));
1568 setup_uio(auio, iovecp, (char *)address, offset, PAGE_SIZE, UIO_READ,
1571 bypasscache = afs_linux_can_bypass(ip);
1573 /* In the new incarnation of selective caching, a file's caching policy
1574 * can change, eg because file size exceeds threshold, etc. */
1575 trydo_cache_transition(avc, credp, bypasscache);
1580 /* save the page for background map */
1581 auio->uio_iov->iov_base = (void*) pp;
1582 /* the background thread will free this */
1583 ancr = osi_Alloc(sizeof(struct nocache_read_request));
1585 ancr->offset = offset;
1586 ancr->length = PAGE_SIZE;
1588 maybe_lock_kernel();
1589 code = afs_ReadNoCache(avc, ancr, credp);
1590 maybe_unlock_kernel();
1592 goto done; /* skips release page, doing it in bg thread */
1595 #ifdef AFS_LINUX24_ENV
1596 maybe_lock_kernel();
1600 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1601 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1602 99999); /* not a possible code value */
1604 code = afs_rdwr(avc, auio, UIO_READ, 0, credp);
1606 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
1607 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, cnt, ICL_TYPE_INT32,
1609 AFS_DISCON_UNLOCK();
1611 #ifdef AFS_LINUX24_ENV
1612 maybe_unlock_kernel();
1615 /* XXX valid for no-cache also? Check last bits of files... :)
1616 * Cognate code goes in afs_NoCacheFetchProc. */
1617 if (auio->uio_resid) /* zero remainder of page */
1618 memset((void *)(address + (PAGE_SIZE - auio->uio_resid)), 0,
1621 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1622 flush_dcache_page(pp);
1623 SetPageUptodate(pp);
1625 set_bit(PG_uptodate, &pp->flags);
1629 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1633 clear_bit(PG_locked, &pp->flags);
1638 /* do not call afs_GetDCache if cache is bypassed */
1642 /* free if not bypassing cache */
1643 osi_Free(auio, sizeof(struct uio));
1644 osi_Free(iovecp, sizeof(struct iovec));
1646 if (!code && AFS_CHUNKOFFSET(offset) == 0) {
1648 struct vrequest treq;
1651 code = afs_InitReq(&treq, credp);
1652 if (!code && !NBObtainWriteLock(&avc->lock, 534)) {
1653 tdc = afs_FindDCache(avc, offset);
1655 if (!(tdc->mflags & DFNextStarted))
1656 afs_PrefetchChunk(avc, tdc, credp, &treq);
1659 ReleaseWriteLock(&avc->lock);
1666 return afs_convert_code(code);
1669 #if defined(AFS_LINUX24_ENV)
1671 afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1672 unsigned long offset, unsigned int count)
1674 struct vcache *vcp = VTOAFS(ip);
1683 buffer = kmap(pp) + offset;
1684 base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
1687 maybe_lock_kernel();
1689 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1690 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1691 ICL_TYPE_INT32, 99999);
1693 ObtainWriteLock(&vcp->lock, 532);
1694 if (vcp->f.states & CPageWrite) {
1695 ReleaseWriteLock(&vcp->lock);
1697 maybe_unlock_kernel();
1700 /* should mark it dirty? */
1703 vcp->f.states |= CPageWrite;
1704 ReleaseWriteLock(&vcp->lock);
1706 setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1708 code = afs_write(vcp, &tuio, f_flags, credp, 0);
1710 i_size_write(ip, vcp->f.m.Length);
1711 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
1713 ObtainWriteLock(&vcp->lock, 533);
1715 struct vrequest treq;
1717 if (!afs_InitReq(&treq, credp))
1718 code = afs_DoPartialWrite(vcp, &treq);
1720 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
1722 vcp->f.states &= ~CPageWrite;
1723 ReleaseWriteLock(&vcp->lock);
1725 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1726 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1727 ICL_TYPE_INT32, code);
1730 maybe_unlock_kernel();
1739 #ifdef AOP_WRITEPAGE_TAKES_WRITEBACK_CONTROL
1740 afs_linux_writepage(struct page *pp, struct writeback_control *wbc)
1742 afs_linux_writepage(struct page *pp)
1745 struct address_space *mapping = pp->mapping;
1746 struct inode *inode;
1747 unsigned long end_index;
1748 unsigned offset = PAGE_CACHE_SIZE;
1751 if (PageLaunder(pp)) {
1752 return(fail_writepage(pp));
1755 inode = (struct inode *)mapping->host;
1756 end_index = i_size_read(inode) >> PAGE_CACHE_SHIFT;
1759 if (pp->index < end_index)
1761 /* things got complicated... */
1762 offset = i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
1763 /* OK, are we completely out? */
1764 if (pp->index >= end_index + 1 || !offset)
1767 status = afs_linux_writepage_sync(inode, pp, 0, offset);
1768 SetPageUptodate(pp);
1770 if (status == offset)
1776 /* afs_linux_updatepage
1777 * What one would have thought was writepage - write dirty page to file.
1778 * Called from generic_file_write. buffer is still in user space. pagep
1779 * has been filled in with old data if we're updating less than a page.
1782 afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset,
1783 unsigned int count, int sync)
1785 struct vcache *vcp = VTOAFS(FILE_INODE(fp));
1786 u8 *page_addr = (u8 *) afs_linux_page_address(pp);
1792 set_bit(PG_locked, &pp->flags);
1797 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1798 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1799 ICL_TYPE_INT32, 99999);
1800 setup_uio(&tuio, &iovec, page_addr + offset,
1801 (afs_offs_t) (pageoff(pp) + offset), count, UIO_WRITE,
1804 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1806 i_size_write(ip, vcp->f.m.Length);
1807 ip->i_blocks = ((vcp->f.m.Length + 1023) >> 10) << 1;
1810 struct vrequest treq;
1812 ObtainWriteLock(&vcp->lock, 533);
1813 vcp->f.m.Date = osi_Time(); /* set modification time */
1814 if (!afs_InitReq(&treq, credp))
1815 code = afs_DoPartialWrite(vcp, &treq);
1816 ReleaseWriteLock(&vcp->lock);
1819 code = code ? afs_convert_code(code) : count - tuio.uio_resid;
1820 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1821 ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
1822 ICL_TYPE_INT32, code);
1824 AFS_DISCON_UNLOCK();
1828 clear_bit(PG_locked, &pp->flags);
1833 /* afs_linux_permission
1834 * Check access rights - returns error if can't check or permission denied.
1837 #ifdef IOP_PERMISSION_TAKES_NAMEIDATA
1838 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
1840 afs_linux_permission(struct inode *ip, int mode)
1844 cred_t *credp = crref();
1848 if (mode & MAY_EXEC)
1850 if (mode & MAY_READ)
1852 if (mode & MAY_WRITE)
1854 code = afs_access(VTOAFS(ip), tmp, credp);
1858 return afs_convert_code(code);
1861 #if defined(AFS_LINUX24_ENV) && !defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1863 afs_linux_commit_write(struct file *file, struct page *page, unsigned offset,
1868 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
1869 offset, to - offset);
1876 afs_linux_prepare_write(struct file *file, struct page *page, unsigned from,
1879 /* sometime between 2.4.0 and 2.4.19, the callers of prepare_write began to
1880 call kmap directly instead of relying on us to do it */
1886 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1888 afs_linux_write_end(struct file *file, struct address_space *mapping,
1889 loff_t pos, unsigned len, unsigned copied,
1890 struct page *page, void *fsdata)
1893 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
1895 code = afs_linux_writepage_sync(file->f_dentry->d_inode, page,
1898 page_cache_release(page);
1903 afs_linux_write_begin(struct file *file, struct address_space *mapping,
1904 loff_t pos, unsigned len, unsigned flags,
1905 struct page **pagep, void **fsdata)
1908 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1909 #if defined(HAVE_LINUX_GRAB_CACHE_PAGE_WRITE_BEGIN)
1910 page = grab_cache_page_write_begin(mapping, index, flags);
1912 page = __grab_cache_page(mapping, index);
1921 static struct inode_operations afs_file_iops = {
1922 #if defined(AFS_LINUX24_ENV)
1923 .permission = afs_linux_permission,
1924 .revalidate = afs_linux_revalidate,
1925 .setattr = afs_notify_change,
1927 .default_file_ops = &afs_file_fops,
1928 .readpage = afs_linux_readpage,
1929 .revalidate = afs_linux_revalidate,
1930 .updatepage = afs_linux_updatepage,
1934 #if defined(AFS_LINUX24_ENV)
1935 static struct address_space_operations afs_file_aops = {
1936 .readpage = afs_linux_readpage,
1937 .writepage = afs_linux_writepage,
1938 #if defined (STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN)
1939 .write_begin = afs_linux_write_begin,
1940 .write_end = afs_linux_write_end,
1942 .commit_write = afs_linux_commit_write,
1943 .prepare_write = afs_linux_prepare_write,
1949 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1950 * by what sort of operation is allowed.....
1953 static struct inode_operations afs_dir_iops = {
1954 #if !defined(AFS_LINUX24_ENV)
1955 .default_file_ops = &afs_dir_fops,
1957 .setattr = afs_notify_change,
1959 .create = afs_linux_create,
1960 .lookup = afs_linux_lookup,
1961 .link = afs_linux_link,
1962 .unlink = afs_linux_unlink,
1963 .symlink = afs_linux_symlink,
1964 .mkdir = afs_linux_mkdir,
1965 .rmdir = afs_linux_rmdir,
1966 .rename = afs_linux_rename,
1967 .revalidate = afs_linux_revalidate,
1968 .permission = afs_linux_permission,
1971 /* We really need a separate symlink set of ops, since do_follow_link()
1972 * determines if it _is_ a link by checking if the follow_link op is set.
1974 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
1976 afs_symlink_filler(struct file *file, struct page *page)
1978 struct inode *ip = (struct inode *)page->mapping->host;
1979 char *p = (char *)kmap(page);
1982 maybe_lock_kernel();
1984 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
1989 p[code] = '\0'; /* null terminate? */
1990 maybe_unlock_kernel();
1992 SetPageUptodate(page);
1998 maybe_unlock_kernel();
2006 static struct address_space_operations afs_symlink_aops = {
2007 .readpage = afs_symlink_filler
2009 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2011 static struct inode_operations afs_symlink_iops = {
2012 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2013 .readlink = page_readlink,
2014 #if defined(HAVE_KERNEL_PAGE_FOLLOW_LINK)
2015 .follow_link = page_follow_link,
2017 .follow_link = page_follow_link_light,
2018 .put_link = page_put_link,
2020 #else /* !defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE) */
2021 .readlink = afs_linux_readlink,
2022 .follow_link = afs_linux_follow_link,
2023 #if !defined(AFS_LINUX24_ENV)
2024 .permission = afs_linux_permission,
2025 .revalidate = afs_linux_revalidate,
2027 #endif /* USABLE_KERNEL_PAGE_SYMLINK_CACHE */
2028 #if defined(AFS_LINUX24_ENV)
2029 .setattr = afs_notify_change,
2034 afs_fill_inode(struct inode *ip, struct vattr *vattr)
2038 vattr2inode(ip, vattr);
2040 /* Reset ops if symlink or directory. */
2041 if (S_ISREG(ip->i_mode)) {
2042 ip->i_op = &afs_file_iops;
2043 #if defined(AFS_LINUX24_ENV)
2044 ip->i_fop = &afs_file_fops;
2045 ip->i_data.a_ops = &afs_file_aops;
2048 } else if (S_ISDIR(ip->i_mode)) {
2049 ip->i_op = &afs_dir_iops;
2050 #if defined(AFS_LINUX24_ENV)
2051 ip->i_fop = &afs_dir_fops;
2054 } else if (S_ISLNK(ip->i_mode)) {
2055 ip->i_op = &afs_symlink_iops;
2056 #if defined(USABLE_KERNEL_PAGE_SYMLINK_CACHE)
2057 ip->i_data.a_ops = &afs_symlink_aops;
2058 ip->i_mapping = &ip->i_data;