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 */
16 #include "osi_compat.h"
19 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) {
22 struct dentry *dentry;
23 struct inode *inode = AFSTOV(avc);
24 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
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);
38 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
39 if (d_unhashed(dentry))
43 spin_unlock(&dcache_lock);
44 if (d_invalidate(dentry) == -EBUSY) {
46 /* perhaps lock and try to continue? (use cur as head?) */
50 spin_lock(&dcache_lock);
53 spin_unlock(&dcache_lock);
54 #else /* HAVE_DCACHE_LOCK */
55 spin_lock(&inode->i_lock);
58 #if defined(D_ALIAS_IS_HLIST)
59 # if defined(HLIST_ITERATOR_NO_NODE)
60 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
62 hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
65 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
67 spin_lock(&dentry->d_lock);
68 if (d_unhashed(dentry)) {
69 spin_unlock(&dentry->d_lock);
72 spin_unlock(&dentry->d_lock);
75 spin_unlock(&inode->i_lock);
76 if (afs_d_invalidate(dentry) == -EBUSY) {
78 /* perhaps lock and try to continue? (use cur as head?) */
82 spin_lock(&inode->i_lock);
85 spin_unlock(&inode->i_lock);
86 #endif /* HAVE_DCACHE_LOCK */
89 ObtainWriteLock(&afs_xvcache, 733);
92 /* See if we can evict it from the VLRUQ */
93 if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
94 && (avc->f.states & CUnlinkedDel) == 0) {
95 int didsleep = *slept;
97 code = afs_FlushVCache(avc, slept);
98 /* flushvcache wipes slept; restore slept if we did before */
116 ip = new_inode(afs_globalVFS);
118 osi_Panic("afs_NewVCache: no more inodes");
120 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
123 tvc = afs_osi_Alloc(sizeof(struct vcache));
124 ip->u.generic_ip = tvc;
128 INIT_LIST_HEAD(&tvc->pagewriters);
129 spin_lock_init(&tvc->pagewriter_lock);
135 osi_PrePopulateVCache(struct vcache *avc) {
137 memset(&(avc->f), 0, sizeof(struct fvcache));
142 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
145 osi_PostPopulateVCache(struct vcache *avc) {
150 * osi_ResetRootVCache - Reset the root vcache
151 * Reset the dentry associated with the afs root.
152 * Called from afs_CheckRootVolume when we notice that
153 * the root volume ID has changed.
155 * @volid: volume ID for the afs root
158 osi_ResetRootVCache(afs_uint32 volid)
160 struct vrequest *treq = NULL;
165 struct inode *root = AFSTOV(afs_globalVp);
167 afs_rootFid.Fid.Volume = volid;
168 afs_rootFid.Fid.Vnode = 1;
169 afs_rootFid.Fid.Unique = 1;
172 if (afs_CreateReq(&treq, credp))
174 vcp = afs_GetVCache(&afs_rootFid, treq, NULL, NULL);
177 afs_getattr(vcp, &vattr, credp);
178 afs_fill_inode(AFSTOV(vcp), &vattr);
180 dp = d_find_alias(root);
182 #if defined(HAVE_DCACHE_LOCK)
183 spin_lock(&dcache_lock);
185 spin_lock(&AFSTOV(vcp)->i_lock);
187 spin_lock(&dp->d_lock);
188 #if defined(D_ALIAS_IS_HLIST)
189 hlist_del_init(&dp->d_alias);
190 hlist_add_head(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
192 list_del_init(&dp->d_alias);
193 list_add(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
195 dp->d_inode = AFSTOV(vcp);
196 spin_unlock(&dp->d_lock);
197 #if defined(HAVE_DCACHE_LOCK)
198 spin_unlock(&dcache_lock);
200 spin_unlock(&AFSTOV(vcp)->i_lock);
208 afs_DestroyReq(treq);