Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / afs / LINUX / osi_vm.c
1 /* Copyright (C) 1998 Transarc Corporation - All rights reserved. */
2 /*
3  * (C) COPYRIGHT IBM CORPORATION 1987, 1988
4  * LICENSED MATERIALS - PROPERTY OF IBM
5  */
6
7 #include "../afs/param.h"       /* Should be always first */
8 #include "../afs/sysincludes.h" /* Standard vendor system headers */
9 #include "../afs/afsincludes.h" /* Afs-based standard headers */
10 #include "../afs/afs_stats.h"   /* statistics */
11
12 /* Linux VM operations
13  *
14  * The general model for Linux is to treat vm as a cache that's:
15  * 1) explicitly updated by AFS when AFS writes the data to the cache file.
16  * 2) reads go through the cache. A cache miss is satisfied by the filesystem.
17  *
18  * This means flushing VM is not required on this OS.
19  */
20
21 /* Try to discard pages, in order to recycle a vcache entry.
22  *
23  * We also make some sanity checks:  ref count, open count, held locks.
24  *
25  * We also do some non-VM-related chores, such as releasing the cred pointer
26  * (for AIX and Solaris) and releasing the gnode (for AIX).
27  *
28  * Locking:  afs_xvcache lock is held.  If it is dropped and re-acquired,
29  *   *slept should be set to warn the caller.
30  *
31  * Formerly, afs_xvcache was dropped and re-acquired for Solaris, but now it
32  * is not dropped and re-acquired for any platform.  It may be that *slept is
33  * therefore obsolescent.
34  */
35 int osi_VM_FlushVCache(struct vcache *avc, int *slept)
36 {
37     struct inode *ip = (struct inode*)avc;
38
39     if (avc->vrefCount != 0)
40         return EBUSY;
41
42     if (avc->opens != 0)
43         return EBUSY;
44
45     invalidate_inode_pages(ip);
46     return 0;
47 }
48
49 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
50  * try to free pages, when deleting a file.
51  *
52  * Locking:  the vcache entry's lock is held.  It may be dropped and 
53  * re-obtained.
54  *
55  * Since we drop and re-obtain the lock, we can't guarantee that there won't
56  * be some pages around when we return, newly created by concurrent activity.
57  */
58 void osi_VM_TryToSmush(struct vcache *avc, struct AFS_UCRED *acred, int sync)
59 {
60     invalidate_inode_pages((struct inode *)avc);
61 }
62
63 /* Flush and invalidate pages, for fsync() with INVAL flag
64  *
65  * Locking:  only the global lock is held.
66  */
67 void osi_VM_FSyncInval(struct vcache *avc)
68 {
69
70 }
71
72 /* Try to store pages to cache, in order to store a file back to the server.
73  *
74  * Locking:  the vcache entry's lock is held.  It will usually be dropped and
75  * re-obtained.
76  */
77 void osi_VM_StoreAllSegments(struct vcache *avc)
78 {
79
80 }
81
82 /* Purge VM for a file when its callback is revoked.
83  *
84  * Locking:  No lock is held, not even the global lock.
85  */
86 void osi_VM_FlushPages(struct vcache *avc, struct AFS_UCRED *credp)
87 {
88     invalidate_inode_pages((struct inode*)avc);
89 }
90
91 /* Purge pages beyond end-of-file, when truncating a file.
92  *
93  * Locking:  no lock is held, not even the global lock.
94  * activeV is raised.  This is supposed to block pageins, but at present
95  * it only works on Solaris.
96  */
97 void osi_VM_Truncate(struct vcache *avc, int alen, struct AFS_UCRED *acred)
98 {
99     invalidate_inode_pages((struct inode*)avc);
100 }