e3e3003ef1dc142781c9960e926ddb9549e2927b
[openafs.git] / src / afs / LINUX24 / 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 #if defined(AFS_LINUX24_ENV)
17 # define afs_linux_lock_dcache() spin_lock(&dcache_lock)
18 # define afs_linux_unlock_dcache() spin_unlock(&dcache_lock)
19 #else
20 # define afs_linux_lock_dcache()
21 # define afs_linux_unlock_dcache()
22 #endif
23
24 int
25 osi_TryEvictVCache(struct vcache *avc, int *slept) {
26     int code;
27     struct dentry *dentry;
28     struct list_head *cur, *head;
29
30     /* First, see if we can evict the inode from the dcache */
31     if (avc != afs_globalVp && VREFCOUNT(avc) > 1 && avc->opens == 0) {
32         AFS_GUNLOCK();
33         afs_linux_lock_dcache();
34         head = &(AFSTOV(avc))->i_dentry;
35
36 restart:
37         cur = head;
38         while ((cur = cur->next) != head) {
39             dentry = list_entry(cur, struct dentry, d_alias);
40
41             if (d_unhashed(dentry))
42                 continue;
43
44             dget_locked(dentry);
45
46             afs_linux_unlock_dcache();
47
48             if (d_invalidate(dentry) == -EBUSY) {
49                 dput(dentry);
50                 /* perhaps lock and try to continue? (use cur as head?) */
51                 goto inuse;
52             }
53             dput(dentry);
54             afs_linux_lock_dcache();
55             goto restart;
56         }
57         afs_linux_unlock_dcache();
58 inuse:
59         AFS_GLOCK();
60     }
61
62     /* See if we can evict it from the VLRUQ */
63     if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
64         && (avc->f.states & CUnlinkedDel) == 0) {
65
66         code = afs_FlushVCache(avc, slept);
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     osi_Assert(tvc != NULL);
90     ip->u.generic_ip = tvc;
91     tvc->v = ip;
92 #endif
93
94     return tvc;
95 }
96
97 /* XXX - This should probably be inline */
98 void
99 osi_PrePopulateVCache(struct vcache *avc) {
100     avc->uncred = 0;
101     memset(&(avc->f), 0, sizeof(struct fvcache));
102 }
103
104 /* XXX - This should become inline, or a #define */
105 void
106 osi_AttachVnode(struct vcache *avc, int seq) { }
107
108 /* XXX - Again, inline or a #define */
109 void
110 osi_PostPopulateVCache(struct vcache *avc) {
111     vSetType(avc, VREG);
112 }
113