afs: Remove 'slept' from osi_VM_FlushVCache
[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. It must not be dropped.
37  */
38 int
39 osi_VM_FlushVCache(struct vcache *avc)
40 {
41     struct inode *ip = AFSTOV(avc);
42
43     if (VREFCOUNT(avc) > 1)
44         return EBUSY;
45
46     if (avc->opens != 0)
47         return EBUSY;
48
49     return afs_truncate(ip, 0);
50 }
51
52 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
53  * try to free pages, when deleting a file.
54  *
55  * Locking:  the vcache entry's lock is held.  It may be dropped and 
56  * re-obtained.
57  *
58  * Since we drop and re-obtain the lock, we can't guarantee that there won't
59  * be some pages around when we return, newly created by concurrent activity.
60  */
61 void
62 osi_VM_TryToSmush(struct vcache *avc, afs_ucred_t *acred, int sync)
63 {
64     struct inode *ip = AFSTOV(avc);
65
66     invalidate_remote_inode(ip);
67 }
68
69 /* Flush and invalidate pages, for fsync() with INVAL flag
70  *
71  * Locking:  only the global lock is held.
72  */
73 void
74 osi_VM_FSyncInval(struct vcache *avc)
75 {
76
77 }
78
79 /* Try to store pages to cache, in order to store a file back to the server.
80  *
81  * Locking:  the vcache entry's lock is held.  It will usually be dropped and
82  * re-obtained.
83  */
84 void
85 osi_VM_StoreAllSegments(struct vcache *avc)
86 {
87     struct inode *ip = AFSTOV(avc);
88
89     if (avc->f.states & CPageWrite)
90         return; /* someone already writing */
91
92     /* filemap_fdatasync() only exported in 2.4.5 and above */
93     ReleaseWriteLock(&avc->lock);
94     AFS_GUNLOCK();
95     filemap_fdatawrite(ip->i_mapping);
96     filemap_fdatawait(ip->i_mapping);
97     AFS_GLOCK();
98     ObtainWriteLock(&avc->lock, 121);
99 }
100
101 /* Purge VM for a file when its callback is revoked.
102  *
103  * Locking:  No lock is held, not even the global lock.
104  */
105
106 /* Note that for speed some of our Linux vnodeops do not initialise credp
107  * before calling osi_FlushPages(). If credp is ever required on Linux,
108  * then these callers should be updated.
109  */
110 void
111 osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
112 {
113     struct inode *ip = AFSTOV(avc);
114     
115     afs_linux_lock_inode(ip);
116     truncate_inode_pages(&ip->i_data, 0);
117     afs_linux_unlock_inode(ip);
118 }
119
120 /* Purge pages beyond end-of-file, when truncating a file.
121  *
122  * Locking:  no lock is held, not even the global lock.
123  * activeV is raised.  This is supposed to block pageins, but at present
124  * it only works on Solaris.
125  */
126 void
127 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
128 {
129     afs_truncate(AFSTOV(avc), alen);
130 }