Linux 3.8: vmtruncate removal
[openafs.git] / src / afs / LINUX / osi_vm.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* statistics */
17
18 #include "osi_compat.h"
19
20 /* Linux VM operations
21  *
22  * The general model for Linux is to treat vm as a cache that's:
23  * 1) explicitly updated by AFS when AFS writes the data to the cache file.
24  * 2) reads go through the cache. A cache miss is satisfied by the filesystem.
25  *
26  * This means flushing VM is not required on this OS.
27  */
28
29 /* Try to discard pages, in order to recycle a vcache entry.
30  *
31  * We also make some sanity checks:  ref count, open count, held locks.
32  *
33  * We also do some non-VM-related chores, such as releasing the cred pointer
34  * (for AIX and Solaris) and releasing the gnode (for AIX).
35  *
36  * Locking:  afs_xvcache lock is held.  If it is dropped and re-acquired,
37  *   *slept should be set to warn the caller.
38  *
39  * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
40  * is not dropped and re-acquired for any platform.  It may be that *slept is
41  * therefore obsolescent.
42  */
43 int
44 osi_VM_FlushVCache(struct vcache *avc, int *slept)
45 {
46     struct inode *ip = AFSTOV(avc);
47
48     if (VREFCOUNT(avc) > 1)
49         return EBUSY;
50
51     if (avc->opens != 0)
52         return EBUSY;
53
54     return afs_truncate(ip, 0);
55 }
56
57 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
58  * try to free pages, when deleting a file.
59  *
60  * Locking:  the vcache entry's lock is held.  It may be dropped and 
61  * re-obtained.
62  *
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.
65  */
66 void
67 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
68 {
69     struct inode *ip = AFSTOV(avc);
70
71     invalidate_remote_inode(ip);
72 }
73
74 /* Flush and invalidate pages, for fsync() with INVAL flag
75  *
76  * Locking:  only the global lock is held.
77  */
78 void
79 osi_VM_FSyncInval(struct vcache *avc)
80 {
81
82 }
83
84 /* Try to store pages to cache, in order to store a file back to the server.
85  *
86  * Locking:  the vcache entry's lock is held.  It will usually be dropped and
87  * re-obtained.
88  */
89 void
90 osi_VM_StoreAllSegments(struct vcache *avc)
91 {
92     struct inode *ip = AFSTOV(avc);
93
94     if (avc->f.states & CPageWrite)
95         return; /* someone already writing */
96
97     /* filemap_fdatasync() only exported in 2.4.5 and above */
98     ReleaseWriteLock(&avc->lock);
99     AFS_GUNLOCK();
100     filemap_fdatawrite(ip->i_mapping);
101     filemap_fdatawait(ip->i_mapping);
102     AFS_GLOCK();
103     ObtainWriteLock(&avc->lock, 121);
104 }
105
106 /* Purge VM for a file when its callback is revoked.
107  *
108  * Locking:  No lock is held, not even the global lock.
109  */
110
111 /* Note that for speed some of our Linux vnodeops do not initialise credp
112  * before calling osi_FlushPages(). If credp is ever required on Linux,
113  * then these callers should be updated.
114  */
115 void
116 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
117 {
118     struct inode *ip = AFSTOV(avc);
119     
120     afs_linux_lock_inode(ip);
121     truncate_inode_pages(&ip->i_data, 0);
122     afs_linux_unlock_inode(ip);
123 }
124
125 /* Purge pages beyond end-of-file, when truncating a file.
126  *
127  * Locking:  no lock is held, not even the global lock.
128  * activeV is raised.  This is supposed to block pageins, but at present
129  * it only works on Solaris.
130  */
131 void
132 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
133 {
134     afs_truncate(AFSTOV(avc), alen);
135 }