2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include "afs/param.h"
13 #include "afs/sysincludes.h" /*Standard vendor system headers */
14 #include "afsincludes.h" /*AFS-based standard headers */
17 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) {
20 struct dentry *dentry;
21 struct inode *inode = AFSTOV(avc);
22 #if defined(D_ALIAS_IS_HLIST)
23 struct hlist_node *cur, *head, *list_end;
25 struct list_head *cur, *head, *list_end;
28 /* First, see if we can evict the inode from the dcache */
29 if (defersleep && avc != afs_globalVp && VREFCOUNT(avc) > 1 && avc->opens == 0) {
31 ReleaseWriteLock(&afs_xvcache);
34 #if defined(HAVE_DCACHE_LOCK)
35 spin_lock(&dcache_lock);
36 head = &inode->i_dentry;
40 while ((cur = cur->next) != head) {
41 dentry = list_entry(cur, struct dentry, d_alias);
43 if (d_unhashed(dentry))
47 spin_unlock(&dcache_lock);
48 if (d_invalidate(dentry) == -EBUSY) {
50 /* perhaps lock and try to continue? (use cur as head?) */
54 spin_lock(&dcache_lock);
57 spin_unlock(&dcache_lock);
58 #else /* HAVE_DCACHE_LOCK */
59 spin_lock(&inode->i_lock);
60 #if defined(D_ALIAS_IS_HLIST)
61 head = inode->i_dentry.first;
64 head = &inode->i_dentry;
70 while ((cur = cur->next) != list_end) {
71 #if defined(D_ALIAS_IS_HLIST)
72 dentry = hlist_entry(cur, struct dentry, d_alias);
74 dentry = list_entry(cur, struct dentry, d_alias);
77 spin_lock(&dentry->d_lock);
78 if (d_unhashed(dentry)) {
79 spin_unlock(&dentry->d_lock);
82 spin_unlock(&dentry->d_lock);
85 spin_unlock(&inode->i_lock);
86 if (d_invalidate(dentry) == -EBUSY) {
88 /* perhaps lock and try to continue? (use cur as head?) */
92 spin_lock(&inode->i_lock);
95 spin_unlock(&inode->i_lock);
96 #endif /* HAVE_DCACHE_LOCK */
99 ObtainWriteLock(&afs_xvcache, 733);
102 /* See if we can evict it from the VLRUQ */
103 if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
104 && (avc->f.states & CUnlinkedDel) == 0) {
105 int didsleep = *slept;
107 code = afs_FlushVCache(avc, slept);
108 /* flushvcache wipes slept; restore slept if we did before */
126 ip = new_inode(afs_globalVFS);
128 osi_Panic("afs_NewVCache: no more inodes");
130 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
133 tvc = afs_osi_Alloc(sizeof(struct vcache));
134 ip->u.generic_ip = tvc;
142 osi_PrePopulateVCache(struct vcache *avc) {
144 memset(&(avc->f), 0, sizeof(struct fvcache));
149 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
152 osi_PostPopulateVCache(struct vcache *avc) {