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 TryEvictDirDentries(struct inode *inode)
21 struct dentry *dentry;
22 #if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
26 afs_d_alias_lock(inode);
29 #if defined(D_ALIAS_IS_HLIST)
30 # if defined(HLIST_ITERATOR_NO_NODE)
31 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
33 hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
36 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
38 spin_lock(&dentry->d_lock);
39 if (d_unhashed(dentry)) {
40 spin_unlock(&dentry->d_lock);
43 spin_unlock(&dentry->d_lock);
44 afs_linux_dget(dentry);
46 afs_d_alias_unlock(inode);
49 * Once we have dropped the d_alias lock (above), it is no longer safe
50 * to 'continue' our iteration over d_alias because the list may change
51 * out from under us. Therefore, we must either leave the loop, or
52 * restart from the beginning. To avoid looping forever, we must only
53 * restart if we know we've d_drop'd an alias. In all other cases we
54 * must leave the loop.
58 * For a long time we used d_invalidate() for this purpose, but
59 * using shrink_dcache_parent() and checking the refcount ourselves is
60 * better, for two reasons: it avoids causing ENOENT issues for the
61 * CWD in linux versions since 3.11, and it avoids dropping Linux
64 * For non-fakestat, AFS mountpoints look like directories and end up here.
67 shrink_dcache_parent(dentry);
68 spin_lock(&dentry->d_lock);
69 if (afs_dentry_count(dentry) > 1) /* still has references */ {
70 if (dentry->d_inode != NULL) /* is not a negative dentry */ {
71 spin_unlock(&dentry->d_lock);
77 * This is either a negative dentry, or a dentry with no references.
78 * Either way, it is okay to unhash it now.
79 * Do so under the d_lock (that is, via __d_drop() instead of d_drop())
80 * to avoid a race with another process picking up a reference.
83 spin_unlock(&dentry->d_lock);
86 afs_d_alias_lock(inode);
89 afs_d_alias_unlock(inode);
97 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
101 /* First, see if we can evict the inode from the dcache */
102 if (defersleep && avc != afs_globalVp && VREFCOUNT(avc) > 1
103 && avc->opens == 0) {
104 struct inode *ip = AFSTOV(avc);
106 if (osi_vnhold(avc) != 0) {
107 /* Can't grab a ref on avc; bail out. */
111 ReleaseWriteLock(&afs_xvcache);
114 if (S_ISDIR(ip->i_mode))
115 TryEvictDirDentries(ip);
120 ObtainWriteLock(&afs_xvcache, 733);
124 /* See if we can evict it from the VLRUQ */
125 if (VREFCOUNT_GT(avc, 0) && !VREFCOUNT_GT(avc, 1) && avc->opens == 0
126 && (avc->f.states & CUnlinkedDel) == 0) {
127 int didsleep = *slept;
129 code = afs_FlushVCache(avc, slept);
130 /* flushvcache wipes slept; restore slept if we did before */
148 ip = new_inode(afs_globalVFS);
150 osi_Panic("afs_NewVCache: no more inodes");
152 #if defined(STRUCT_SUPER_OPERATIONS_HAS_ALLOC_INODE)
155 tvc = afs_osi_Alloc(sizeof(struct vcache));
156 ip->u.generic_ip = tvc;
160 INIT_LIST_HEAD(&tvc->pagewriters);
161 spin_lock_init(&tvc->pagewriter_lock);
167 osi_PrePopulateVCache(struct vcache *avc)
170 memset(&(avc->f), 0, sizeof(struct fvcache));
175 osi_AttachVnode(struct vcache *avc, int seq)
181 osi_PostPopulateVCache(struct vcache *avc)
187 * osi_ResetRootVCache - Reset the root vcache
188 * Reset the dentry associated with the afs root.
189 * Called from afs_CheckRootVolume when we notice that
190 * the root volume ID has changed.
192 * @volid: volume ID for the afs root
195 osi_ResetRootVCache(afs_uint32 volid)
197 struct vrequest *treq = NULL;
202 struct inode *root = AFSTOV(afs_globalVp);
204 afs_rootFid.Fid.Volume = volid;
205 afs_rootFid.Fid.Vnode = 1;
206 afs_rootFid.Fid.Unique = 1;
209 if (afs_CreateReq(&treq, credp))
211 vcp = afs_GetVCache(&afs_rootFid, treq);
214 afs_getattr(vcp, &vattr, credp);
215 afs_fill_inode(AFSTOV(vcp), &vattr);
217 dp = d_find_alias(root);
219 afs_d_alias_lock(AFSTOV(vcp));
221 spin_lock(&dp->d_lock);
222 #if defined(D_ALIAS_IS_HLIST)
223 hlist_del_init(&dp->d_alias);
224 hlist_add_head(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
226 list_del_init(&dp->d_alias);
227 list_add(&dp->d_alias, &(AFSTOV(vcp)->i_dentry));
229 dp->d_inode = AFSTOV(vcp);
230 spin_unlock(&dp->d_lock);
232 afs_d_alias_unlock(AFSTOV(vcp));
240 afs_DestroyReq(treq);
244 osi_vnhold(struct vcache *avc)
246 VN_HOLD(AFSTOV(avc));