Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 May 2016 06:32:22 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299412 - in head/sys: kern sys
Message-ID:  <201605110632.u4B6WMQn044697@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed May 11 06:32:22 2016
New Revision: 299412
URL: https://svnweb.freebsd.org/changeset/base/299412

Log:
  Add vfs_hash_ref(9) function, which finds a vnode by the hash value
  and returns it referenced.
  
  The function is similar to vfs_hash_get(9), but unlike the later,
  returned vnode is not locked.  This operation cannot be requested with
  the vget(9) flags.
  
  Reviewed and tested by:	rmacklem
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/kern/vfs_hash.c
  head/sys/sys/vnode.h

Modified: head/sys/kern/vfs_hash.c
==============================================================================
--- head/sys/kern/vfs_hash.c	Wed May 11 06:29:07 2016	(r299411)
+++ head/sys/kern/vfs_hash.c	Wed May 11 06:32:22 2016	(r299412)
@@ -104,6 +104,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) {
+		rw_rlock(&vfs_hash_lock);
+		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);
+			rw_runlock(&vfs_hash_lock);
+			vref(vp);
+			vdrop(vp);
+			*vpp = vp;
+			return;
+		}
+		if (vp == NULL) {
+			rw_runlock(&vfs_hash_lock);
+			*vpp = NULL;
+			return;
+		}
+	}
+}
+
+void
 vfs_hash_remove(struct vnode *vp)
 {
 

Modified: head/sys/sys/vnode.h
==============================================================================
--- head/sys/sys/vnode.h	Wed May 11 06:29:07 2016	(r299411)
+++ head/sys/sys/vnode.h	Wed May 11 06:32:22 2016	(r299412)
@@ -859,6 +859,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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605110632.u4B6WMQn044697>