10fb5cf0687aabba00f7a102883af05bf774ace1
[openafs.git] / src / afs / LINUX / osi_vcache.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 #include "afs/sysincludes.h"    /*Standard vendor system headers */
14 #include "afsincludes.h"        /*AFS-based standard headers */
15
16 int
17 osi_TryEvictVCache(struct vcache *avc, int *slept) {
18     int code;
19
20     struct dentry *dentry;
21     struct list_head *cur, *head;
22
23     /* First, see if we can evict the inode from the dcache */
24     if (avc != afs_globalVp && VREFCOUNT(avc) > 1 && avc->opens == 0) {
25         *slept = 1;
26         ReleaseWriteLock(&afs_xvcache);
27         AFS_GUNLOCK();
28         spin_lock(&dcache_lock);
29         head = &(AFSTOV(avc))->i_dentry;
30
31 restart:
32         cur = head;
33         while ((cur = cur->next) != head) {
34             dentry = list_entry(cur, struct dentry, d_alias);
35
36             if (d_unhashed(dentry))
37                 continue;
38
39             dget_locked(dentry);
40
41             spin_unlock(&dcache_lock);
42             if (d_invalidate(dentry) == -EBUSY) {
43                 dput(dentry);
44                 /* perhaps lock and try to continue? (use cur as head?) */
45                 goto inuse;
46             }
47             dput(dentry);
48             spin_lock(&dcache_lock);
49             goto restart;
50         }
51         spin_unlock(&dcache_lock);
52 inuse:
53         AFS_GLOCK();
54         ObtainWriteLock(&afs_xvcache, 733);
55     }
56
57     /* See if we can evict it from the VLRUQ */
58     if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
59         && (avc->f.states & CUnlinkedDel) == 0) {
60         int didsleep = *slept;
61
62         code = afs_FlushVCache(avc, slept);
63         /* flushvcache wipes slept; restore slept if we did before */
64         if (didsleep)
65             *slept = didsleep;
66
67         if (code == 0)
68             return 1;
69     }
70
71     return 0;
72 }
73
74 struct vcache *
75 osi_NewVnode(void)
76 {
77     struct inode *ip;
78     struct vcache *tvc;
79
80     AFS_GUNLOCK();
81     ip = new_inode(afs_globalVFS);
82     if (!ip)
83         osi_Panic("afs_NewVCache: no more inodes");
84     AFS_GLOCK();
85 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
86     tvc = VTOAFS(ip);
87 #else
88     tvc = afs_osi_Alloc(sizeof(struct vcache));
89     ip->u.generic_ip = tvc;
90     tvc->v = ip;
91 #endif
92
93     return tvc;
94 }
95
96 void
97 osi_PrePopulateVCache(struct vcache *avc) {
98     avc->uncred = 0;
99     memset(&(avc->f), 0, sizeof(struct fvcache));
100     avc->cred = NULL;
101 }
102
103 void
104 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
105
106 void
107 osi_PostPopulateVCache(struct vcache *avc) {
108     vSetType(avc, VREG);
109 }
110