From owner-svn-src-head@freebsd.org Wed May 11 06:32:23 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CA5EAB364CF; Wed, 11 May 2016 06:32:23 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7AED41BE2; Wed, 11 May 2016 06:32:23 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4B6WMOS044699; Wed, 11 May 2016 06:32:22 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4B6WMQn044697; Wed, 11 May 2016 06:32:22 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201605110632.u4B6WMQn044697@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 11 May 2016 06:32:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299412 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2016 06:32:23 -0000 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);