svn commit: r300140 - in stable/10/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Wed May 18 11:58:18 UTC 2016


Author: kib
Date: Wed May 18 11:58:16 2016
New Revision: 300140
URL: https://svnweb.freebsd.org/changeset/base/300140

Log:
  MFC r299412:
  Add vfs_hash_ref(9) function, which finds a vnode by the hash value
  and returns it referenced.

Modified:
  stable/10/sys/kern/vfs_hash.c
  stable/10/sys/sys/vnode.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_hash.c
==============================================================================
--- stable/10/sys/kern/vfs_hash.c	Wed May 18 11:51:17 2016	(r300139)
+++ stable/10/sys/kern/vfs_hash.c	Wed May 18 11:58:16 2016	(r300140)
@@ -103,6 +103,36 @@ vfs_hash_get(const struct mount *mp, u_i
 }
 
 void
+vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td,
+    struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg)
+{
+	struct vnode *vp;
+
+	while (1) {
+		mtx_lock(&vfs_hash_mtx);
+		LIST_FOREACH(vp, vfs_hash_bucket(mp, hash), v_hashlist) {
+			if (vp->v_hash != hash)
+				continue;
+			if (vp->v_mount != mp)
+				continue;
+			if (fn != NULL && fn(vp, arg))
+				continue;
+			vhold(vp);
+			mtx_unlock(&vfs_hash_mtx);
+			vref(vp);
+			vdrop(vp);
+			*vpp = vp;
+			return;
+		}
+		if (vp == NULL) {
+			mtx_unlock(&vfs_hash_mtx);
+			*vpp = NULL;
+			return;
+		}
+	}
+}
+
+void
 vfs_hash_remove(struct vnode *vp)
 {
 

Modified: stable/10/sys/sys/vnode.h
==============================================================================
--- stable/10/sys/sys/vnode.h	Wed May 18 11:51:17 2016	(r300139)
+++ stable/10/sys/sys/vnode.h	Wed May 18 11:58:16 2016	(r300140)
@@ -849,6 +849,8 @@ int vfs_hash_get(const struct mount *mp,
 u_int vfs_hash_index(struct vnode *vp);
 int vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td,
     struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg);
+void vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td,
+    struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg);
 void vfs_hash_rehash(struct vnode *vp, u_int hash);
 void vfs_hash_remove(struct vnode *vp);
 


More information about the svn-src-all mailing list