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) {
32 ReleaseWriteLock(&afs_xvcache);
35 #if defined(HAVE_DCACHE_LOCK)
36 spin_lock(&dcache_lock);
39 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
40 if (d_unhashed(dentry))
44 spin_unlock(&dcache_lock);
45 if (d_invalidate(dentry) == -EBUSY) {
47 /* perhaps lock and try to continue? (use cur as head?) */
51 spin_lock(&dcache_lock);
54 spin_unlock(&dcache_lock);
55 #else /* HAVE_DCACHE_LOCK */
56 spin_lock(&inode->i_lock);
59 #if defined(D_ALIAS_IS_HLIST)
60 # if defined(HLIST_ITERATOR_NO_NODE)
61 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
63 hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
66 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
68 spin_lock(&dentry->d_lock);
69 if (d_unhashed(dentry)) {
70 spin_unlock(&dentry->d_lock);
73 spin_unlock(&dentry->d_lock);
76 spin_unlock(&inode->i_lock);
77 if (afs_d_invalidate(dentry) == -EBUSY) {
79 /* perhaps lock and try to continue? (use cur as head?) */
83 spin_lock(&inode->i_lock);
86 spin_unlock(&inode->i_lock);
87 #endif /* HAVE_DCACHE_LOCK */
90 ObtainWriteLock(&afs_xvcache, 733);
94 /* See if we can evict it from the VLRUQ */
95 if (VREFCOUNT_GT(avc,0) && !VREFCOUNT_GT(avc,1) && avc->opens == 0
96 && (avc->f.states & CUnlinkedDel) == 0) {
97 int didsleep = *slept;
99 code = afs_FlushVCache(avc, slept);
100 /* flushvcache wipes slept; restore slept if we did before */
118 ip = new_inode(afs_globalVFS);
120 osi_Panic("afs_NewVCache: no more inodes");
122 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
125 tvc = afs_osi_Alloc(sizeof(struct vcache));
126 ip->u.generic_ip = tvc;
130 INIT_LIST_HEAD(&tvc->pagewriters);
131 spin_lock_init(&tvc->pagewriter_lock);
137 osi_PrePopulateVCache(struct vcache *avc) {
139 memset(&(avc->f), 0, sizeof(struct fvcache));
144 osi_AttachVnode(struct vcache *avc, int seq) { /* Nada */ }
147 osi_PostPopulateVCache(struct vcache *avc) {
152 * osi_ResetRootVCache - Reset the root vcache
153 * Reset the dentry associated with the afs root.
154 * Called from afs_CheckRootVolume when we notice that
155 * the root volume ID has changed.
157 * @volid: volume ID for the afs root
160 osi_ResetRootVCache(afs_uint32 volid)
162 struct vrequest *treq = NULL;
167 struct inode *root = AFSTOV(afs_globalVp);
169 afs_rootFid.Fid.Volume = volid;
170 afs_rootFid.Fid.Vnode = 1;
171 afs_rootFid.Fid.Unique = 1;
174 if (afs_CreateReq(&treq, credp))
176 vcp = afs_GetVCache(&afs_rootFid, treq, NULL, NULL);
179 afs_getattr(vcp, &vattr, credp);
180 afs_fill_inode(AFSTOV(vcp), &vattr);
182 dp = d_find_alias(root);
184 #if defined(HAVE_DCACHE_LOCK)
185 spin_lock(&dcache_lock);
187 spin_lock(&AFSTOV(vcp)->i_lock);
189 spin_lock(&dp->d_lock);
190 #if defined(D_ALIAS_IS_HLIST)
191 hlist_del_init(&dp->d_alias);
192 hlist_add_head(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
194 list_del_init(&dp->d_alias);
195 list_add(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
197 dp->d_inode = AFSTOV(vcp);
198 spin_unlock(&dp->d_lock);
199 #if defined(HAVE_DCACHE_LOCK)
200 spin_unlock(&dcache_lock);
202 spin_unlock(&AFSTOV(vcp)->i_lock);
210 afs_DestroyReq(treq);