Tue Apr 17 08:36:11 2018 UTC ()
Pull up following revision(s) (requested by hannken in ticket #772):

	sys/miscfs/procfs/procfs_subr.c: revision 1.112

Change procfs_revoke_vnodes() to use vrecycle()/vgone() instead
of VOP_REVOKE().

Gets rid of a bunch of suspensions on /proc as vrecycle() will
succeed most time and we suspend at most once per call.


(martin)
diff -r1.108.6.1 -r1.108.6.2 src/sys/miscfs/procfs/procfs_subr.c

cvs diff -r1.108.6.1 -r1.108.6.2 src/sys/miscfs/procfs/procfs_subr.c (expand / switch to unified diff)

--- src/sys/miscfs/procfs/procfs_subr.c 2018/04/12 13:42:48 1.108.6.1
+++ src/sys/miscfs/procfs/procfs_subr.c 2018/04/17 08:36:11 1.108.6.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: procfs_subr.c,v 1.108.6.1 2018/04/12 13:42:48 martin Exp $ */ 1/* $NetBSD: procfs_subr.c,v 1.108.6.2 2018/04/17 08:36:11 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -92,33 +92,34 @@ @@ -92,33 +92,34 @@
92 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 92 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
95 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 95 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
96 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 96 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
97 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 97 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
98 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 98 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 * SUCH DAMAGE. 99 * SUCH DAMAGE.
100 * 100 *
101 * @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95 101 * @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95
102 */ 102 */
103 103
104#include <sys/cdefs.h> 104#include <sys/cdefs.h>
105__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.108.6.1 2018/04/12 13:42:48 martin Exp $"); 105__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.108.6.2 2018/04/17 08:36:11 martin Exp $");
106 106
107#include <sys/param.h> 107#include <sys/param.h>
108#include <sys/systm.h> 108#include <sys/systm.h>
109#include <sys/time.h> 109#include <sys/time.h>
110#include <sys/kernel.h> 110#include <sys/kernel.h>
111#include <sys/proc.h> 111#include <sys/proc.h>
 112#include <sys/fstrans.h>
112#include <sys/vnode.h> 113#include <sys/vnode.h>
113#include <sys/stat.h> 114#include <sys/stat.h>
114#include <sys/file.h> 115#include <sys/file.h>
115#include <sys/filedesc.h> 116#include <sys/filedesc.h>
116#include <sys/kauth.h> 117#include <sys/kauth.h>
117 118
118#include <miscfs/procfs/procfs.h> 119#include <miscfs/procfs/procfs.h>
119 120
120/* 121/*
121 * Allocate a pfsnode/vnode pair. The vnode is referenced. 122 * Allocate a pfsnode/vnode pair. The vnode is referenced.
122 * The pid, type, and file descriptor uniquely identify a pfsnode. 123 * The pid, type, and file descriptor uniquely identify a pfsnode.
123 */ 124 */
124int 125int
@@ -353,41 +354,58 @@ procfs_revoke_selector(void *arg, struct @@ -353,41 +354,58 @@ procfs_revoke_selector(void *arg, struct
353 struct proc *p = arg; 354 struct proc *p = arg;
354 struct pfsnode *pfs; 355 struct pfsnode *pfs;
355 356
356 KASSERT(mutex_owned(vp->v_interlock)); 357 KASSERT(mutex_owned(vp->v_interlock));
357 358
358 pfs = VTOPFS(vp); 359 pfs = VTOPFS(vp);
359 360
360 return (pfs != NULL && pfs->pfs_pid == p->p_pid); 361 return (pfs != NULL && pfs->pfs_pid == p->p_pid);
361} 362}
362 363
363void 364void
364procfs_revoke_vnodes(struct proc *p, void *arg) 365procfs_revoke_vnodes(struct proc *p, void *arg)
365{ 366{
 367 int error;
 368 bool suspended;
366 struct vnode *vp; 369 struct vnode *vp;
367 struct vnode_iterator *marker; 370 struct vnode_iterator *marker;
368 struct mount *mp = (struct mount *)arg; 371 struct mount *mp = (struct mount *)arg;
369 372
370 if (!(p->p_flag & PK_SUGID)) 373 if (!(p->p_flag & PK_SUGID))
371 return; 374 return;
372 375
 376 suspended = false;
373 vfs_vnode_iterator_init(mp, &marker); 377 vfs_vnode_iterator_init(mp, &marker);
374 378
375 while ((vp = vfs_vnode_iterator_next(marker, 379 while ((vp = vfs_vnode_iterator_next(marker,
376 procfs_revoke_selector, p)) != NULL) { 380 procfs_revoke_selector, p)) != NULL) {
377 VOP_REVOKE(vp, REVOKEALL); 381 if (vrecycle(vp))
378 vrele(vp); 382 continue;
 383 /* Vnode is busy, we have to suspend the mount for vgone(). */
 384 while (! suspended) {
 385 error = vfs_suspend(mp, 0);
 386 if (error == 0) {
 387 suspended = true;
 388 } else if (error != EINTR && error != ERESTART) {
 389 KASSERT(error == EOPNOTSUPP);
 390 break;
 391 }
 392 }
 393 vgone(vp);
379 } 394 }
380 395
 396 if (suspended)
 397 vfs_resume(mp);
 398
381 vfs_vnode_iterator_destroy(marker); 399 vfs_vnode_iterator_destroy(marker);
382} 400}
383 401
384int 402int
385procfs_proc_lock(int pid, struct proc **bunghole, int notfound) 403procfs_proc_lock(int pid, struct proc **bunghole, int notfound)
386{ 404{
387 struct proc *tp; 405 struct proc *tp;
388 int error = 0; 406 int error = 0;
389 407
390 mutex_enter(proc_lock); 408 mutex_enter(proc_lock);
391 409
392 if (pid == 0) 410 if (pid == 0)
393 tp = &proc0; 411 tp = &proc0;