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
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* statistics */
18 /* Linux VM operations
20 * The general model for Linux is to treat vm as a cache that's:
21 * 1) explicitly updated by AFS when AFS writes the data to the cache file.
22 * 2) reads go through the cache. A cache miss is satisfied by the filesystem.
24 * This means flushing VM is not required on this OS.
27 /* Try to discard pages, in order to recycle a vcache entry.
29 * We also make some sanity checks: ref count, open count, held locks.
31 * We also do some non-VM-related chores, such as releasing the cred pointer
32 * (for AIX and Solaris) and releasing the gnode (for AIX).
34 * Locking: afs_xvcache lock is held. It must not be dropped.
37 osi_VM_FlushVCache(struct vcache *avc)
39 struct inode *ip = AFSTOV(avc);
41 if (VREFCOUNT(avc) > 1)
47 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
48 return vmtruncate(ip, 0);
49 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,15)
50 truncate_inode_pages(ip, 0);
52 invalidate_inode_pages(ip);
57 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
58 * try to free pages, when deleting a file.
60 * Locking: the vcache entry's lock is held. It may be dropped and
63 * Since we drop and re-obtain the lock, we can't guarantee that there won't
64 * be some pages around when we return, newly created by concurrent activity.
67 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
69 struct inode *ip = AFSTOV(avc);
71 invalidate_inode_pages(ip);
74 /* Flush and invalidate pages, for fsync() with INVAL flag
76 * Locking: only the global lock is held.
79 osi_VM_FSyncInval(struct vcache *avc)
84 /* Try to store pages to cache, in order to store a file back to the server.
86 * Locking: the vcache entry's lock is held. It will usually be dropped and
90 osi_VM_StoreAllSegments(struct vcache *avc)
92 struct inode *ip = AFSTOV(avc);
94 if (avc->f.states & CPageWrite)
95 return; /* someone already writing */
97 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,5)
98 /* filemap_fdatasync() only exported in 2.4.5 and above */
99 ReleaseWriteLock(&avc->lock);
101 filemap_fdatasync(ip->i_mapping);
102 filemap_fdatawait(ip->i_mapping);
104 ObtainWriteLock(&avc->lock, 121);
108 /* Purge VM for a file when its callback is revoked.
110 * Locking: No lock is held, not even the global lock.
113 /* Note that for speed some of our Linux vnodeops do not initialise credp
114 * before calling osi_FlushPages(). If credp is ever required on Linux,
115 * then these callers should be updated.
118 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
120 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
121 struct inode *ip = AFSTOV(avc);
123 truncate_inode_pages(&ip->i_data, 0);
124 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,15)
125 struct inode *ip = AFSTOV(avc);
127 truncate_inode_pages(ip, 0);
129 invalidate_inode_pages(AFSTOV(avc));
133 /* Purge pages beyond end-of-file, when truncating a file.
135 * Locking: no lock is held, not even the global lock.
136 * activeV is raised. This is supposed to block pageins, but at present
137 * it only works on Solaris.
140 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
142 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
143 vmtruncate(AFSTOV(avc), alen);
144 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,15)
145 struct inode *ip = AFSTOV(avc);
147 truncate_inode_pages(ip, alen);
149 invalidate_inode_pages(AFSTOV(avc));