fbe6fd8770cf02c6f1931fd5c398d4493b445799
[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         AFS_GUNLOCK();
26         spin_lock(&dcache_lock);
27         head = &(AFSTOV(avc))->i_dentry;
28
29 restart:
30         cur = head;
31         while ((cur = cur->next) != head) {
32             dentry = list_entry(cur, struct dentry, d_alias);
33
34             if (d_unhashed(dentry))
35                 continue;
36
37             dget_locked(dentry);
38
39             spin_unlock(&dcache_lock);
40             if (d_invalidate(dentry) == -EBUSY) {
41                 dput(dentry);
42                 /* perhaps lock and try to continue? (use cur as head?) */
43                 goto inuse;
44             }
45             dput(dentry);
46             spin_lock(&dcache_lock);
47             goto restart;
48         }
49         spin_unlock(&dcache_lock);
50 inuse:
51         AFS_GLOCK();
52     }
53
54     /* See if we can evict it from the VLRUQ */
55     if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
56         && (avc->f.states & CUnlinkedDel) == 0) {
57
58         code = afs_FlushVCache(avc, slept);
59         if (code == 0)
60            return 1;
61     }
62
63     return 0;
64 }
65
66 struct vcache *
67 osi_NewVnode(void)
68 {
69     struct inode *ip;
70     struct vcache *tvc;
71
72     AFS_GUNLOCK();
73     ip = new_inode(afs_globalVFS);
74     if (!ip)
75         osi_Panic("afs_NewVCache: no more inodes");
76     AFS_GLOCK();
77 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
78     tvc = VTOAFS(ip);
79 #else
80     tvc = afs_osi_Alloc(sizeof(struct vcache));
81     ip->u.generic_ip = tvc;
82     tvc->v = ip;
83 #endif
84
85     return tvc;
86 }
87
88 void
89 osi_PrePopulateVCache(struct vcache *avc) {
90     avc->uncred = 0;
91     memset(&(avc->f), 0, sizeof(struct fvcache));
92     avc->cred = NULL;
93 }
94
95 void
96 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
97
98 void
99 osi_PostPopulateVCache(struct vcache *avc) {
100     vSetType(avc, VREG);
101 }
102