Linux: osi_TryEvictVCache: Don’t skip the first dentry if D_ALIAS_IS_HLIST
[openafs.git] / src / afs / LINUX / osi_vcache.c
index e82d78e..99aab91 100644 (file)
@@ -19,7 +19,9 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) {
 
     struct dentry *dentry;
     struct inode *inode = AFSTOV(avc);
-    struct list_head *cur, *head;
+#if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
+    struct hlist_node *p;
+#endif
 
     /* First, see if we can evict the inode from the dcache */
     if (defersleep && avc != afs_globalVp && VREFCOUNT(avc) > 1 && avc->opens == 0) {
@@ -29,13 +31,9 @@ osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep) {
 
 #if defined(HAVE_DCACHE_LOCK)
         spin_lock(&dcache_lock);
-       head = &inode->i_dentry;
 
 restart:
-        cur = head;
-       while ((cur = cur->next) != head) {
-           dentry = list_entry(cur, struct dentry, d_alias);
-
+       list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
            if (d_unhashed(dentry))
                continue;
            dget_locked(dentry);
@@ -53,13 +51,17 @@ restart:
        spin_unlock(&dcache_lock);
 #else /* HAVE_DCACHE_LOCK */
        spin_lock(&inode->i_lock);
-       head = &inode->i_dentry;
 
 restart:
-       cur = head;
-       while ((cur = cur->next) != head) {
-           dentry = list_entry(cur, struct dentry, d_alias);
-
+#if defined(D_ALIAS_IS_HLIST)
+# if defined(HLIST_ITERATOR_NO_NODE)
+       hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
+# else
+       hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
+# endif
+#else
+       list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
+#endif
            spin_lock(&dentry->d_lock);
            if (d_unhashed(dentry)) {
                spin_unlock(&dentry->d_lock);