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_TryEvictDentries(struct vcache *avc)
21 struct dentry *dentry;
22 struct inode *inode = AFSTOV(avc);
23 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
27 #if defined(HAVE_DCACHE_LOCK)
28 spin_lock(&dcache_lock);
31 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
32 if (d_unhashed(dentry))
36 spin_unlock(&dcache_lock);
37 if (d_invalidate(dentry) == -EBUSY) {
39 /* perhaps lock and try to continue? (use cur as head?) */
43 spin_lock(&dcache_lock);
46 spin_unlock(&dcache_lock);
47 #else /* HAVE_DCACHE_LOCK */
48 spin_lock(&inode->i_lock);
51 #if defined(D_ALIAS_IS_HLIST)
52 # if defined(HLIST_ITERATOR_NO_NODE)
53 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
55 hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
58 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
60 spin_lock(&dentry->d_lock);
61 if (d_unhashed(dentry)) {
62 spin_unlock(&dentry->d_lock);
65 spin_unlock(&dentry->d_lock);
68 spin_unlock(&inode->i_lock);
69 if (afs_d_invalidate(dentry) == -EBUSY) {
71 /* perhaps lock and try to continue? (use cur as head?) */
75 spin_lock(&inode->i_lock);
78 spin_unlock(&inode->i_lock);
79 #endif /* HAVE_DCACHE_LOCK */
86 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
90 /* First, see if we can evict the inode from the dcache */
91 if (defersleep && avc != afs_globalVp && VREFCOUNT(avc) > 1
95 ReleaseWriteLock(&afs_xvcache);
98 osi_TryEvictDentries(avc);
101 ObtainWriteLock(&afs_xvcache, 733);
105 /* See if we can evict it from the VLRUQ */
106 if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
107 && (avc->f.states & CUnlinkedDel) == 0) {
108 int didsleep = *slept;
110 code = afs_FlushVCache(avc, slept);
111 /* flushvcache wipes slept; restore slept if we did before */
129 ip = new_inode(afs_globalVFS);
131 osi_Panic("afs_NewVCache: no more inodes");
133 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
136 tvc = afs_osi_Alloc(sizeof(struct vcache));
137 ip->u.generic_ip = tvc;
141 INIT_LIST_HEAD(&tvc->pagewriters);
142 spin_lock_init(&tvc->pagewriter_lock);
148 osi_PrePopulateVCache(struct vcache *avc) {
150 memset(&(avc->f), 0, sizeof(struct fvcache));
155 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
158 osi_PostPopulateVCache(struct vcache *avc) {
163 * osi_ResetRootVCache - Reset the root vcache
164 * Reset the dentry associated with the afs root.
165 * Called from afs_CheckRootVolume when we notice that
166 * the root volume ID has changed.
168 * @volid: volume ID for the afs root
171 osi_ResetRootVCache(afs_uint32 volid)
173 struct vrequest *treq = NULL;
178 struct inode *root = AFSTOV(afs_globalVp);
180 afs_rootFid.Fid.Volume = volid;
181 afs_rootFid.Fid.Vnode = 1;
182 afs_rootFid.Fid.Unique = 1;
185 if (afs_CreateReq(&treq, credp))
187 vcp = afs_GetVCache(&afs_rootFid, treq, NULL, NULL);
190 afs_getattr(vcp, &vattr, credp);
191 afs_fill_inode(AFSTOV(vcp), &vattr);
193 dp = d_find_alias(root);
195 #if defined(HAVE_DCACHE_LOCK)
196 spin_lock(&dcache_lock);
198 spin_lock(&AFSTOV(vcp)->i_lock);
200 spin_lock(&dp->d_lock);
201 #if defined(D_ALIAS_IS_HLIST)
202 hlist_del_init(&dp->d_alias);
203 hlist_add_head(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
205 list_del_init(&dp->d_alias);
206 list_add(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
208 dp->d_inode = AFSTOV(vcp);
209 spin_unlock(&dp->d_lock);
210 #if defined(HAVE_DCACHE_LOCK)
211 spin_unlock(&dcache_lock);
213 spin_unlock(&AFSTOV(vcp)->i_lock);
221 afs_DestroyReq(treq);