From nobody Fri Sep 27 15:03:25 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XFYct1j9Xz5Y5r8; Fri, 27 Sep 2024 15:03:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XFYct0qFLz58y0; Fri, 27 Sep 2024 15:03:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eHgnYM/aiegeA+1leYF60pIWH9Ocl0fuW+VW8FYmUWY=; b=OrcjmObsV0JGizZAlyq8DlgroqtHGaNtr04XUDH90Sanz0o+MJAi+oCRwIYK0mCqfbNz13 65PVhO+YfhdtorPpeTcUznJ57gizaoBFx//sJmzJdrdHx328AHWWxKV6ePfsgEP0DLMz63 hYOxoO1DHqqU3fX7sljeruhdrTF5GRgbo6uGn3i8a3pnPV/i2N3Udm/mM1kaY6YQfmevEc DHitL0E+rq6qBAUuRxvwJdwgmayuYjfSxAElL4UeH+YveCL7wi5aTCoc1niOCjCHlvuJr7 be57Ycladm5QjAzhOXJc6uLSJ0IEDLsR2qnvFbYa1F9U2cVHmrNprSjHgAQoRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eHgnYM/aiegeA+1leYF60pIWH9Ocl0fuW+VW8FYmUWY=; b=OBCb5VgzdD6zp8wIaTfptv+VtBnHnPe7M6aVBmU0UkJOdellKlW5R9gVo+V4AcEXMMspdL OI4KefvxNX4ksuTQRDnoMocBXhcrtlb4Ix4bsPhhn0JFVB34HozMefud2eQ7eI0rS+fS8B bfW+7Gv/NJPbWMxijlJ2QrWCWmc9PtP6GWbsBO9XOBL4QECFxaiEw8MJIXcj9LargnRvEC itDeJwlV52m0Mwwvp296iEsY/O1R5AJGn2z4WUiwGYFFBN7GOBv88R1tPSZkHI06iT907y Bgzn2MEHAvGI5elaUkIwXVt17u8DCXJceQQvhQjqZ3V792ToRYn1x8q6sAPTxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727449406; a=rsa-sha256; cv=none; b=gXR8gK9nDWMvCs9uxaqkw9ai0UsiLvY5csX5uP+hzml53H9iICa9CBtchYAYIF1fJdKvCf TO+a+QMrayoThvzP8zGiN1OCMDfQCX1iMRIemXkgpBajiPYpQ8TwfSkFUPRiHvNxU5P6H6 Q/1ji3J47A6O4GVnGd+Xy/aFqJWpq3/tCGB9Gu/paA9TbPN2GpHF2zgaLjd0WoLcgA10xO lnQSjeMeDKbOerdF/j6xgMKJSB/3Y77c54jUmKA/VuitBQ5aXTlhF4rIoYq6dCOhchqSdL yPjOefwtpnqhIEtvIzuZGaek44qrCm9JEEB5ueNFFKdf2J4OQfjxUwInY8G1EQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XFYct0QjBzlWw; Fri, 27 Sep 2024 15:03:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48RF3QeZ009095; Fri, 27 Sep 2024 15:03:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48RF3PMu009092; Fri, 27 Sep 2024 15:03:25 GMT (envelope-from git) Date: Fri, 27 Sep 2024 15:03:25 GMT Message-Id: <202409271503.48RF3PMu009092@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 9c3e516ad081 - main - Add proc_nfiles(9) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9c3e516ad08145ad47248633b54fd1b7fc0ef981 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9c3e516ad08145ad47248633b54fd1b7fc0ef981 commit 9c3e516ad08145ad47248633b54fd1b7fc0ef981 Author: Konstantin Belousov AuthorDate: 2024-09-20 16:28:23 +0000 Commit: Konstantin Belousov CommitDate: 2024-09-27 15:01:56 +0000 Add proc_nfiles(9) which returns a snapshot of the count of the opened files in the process. Reviewed by: markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46747 --- sys/kern/kern_descrip.c | 44 +++++++++++++++++++++++++++++++++----------- sys/sys/filedesc.h | 2 ++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ef7aea82a609..09eeb158f1f5 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -4329,21 +4329,13 @@ filedesc_to_leader_share(struct filedesc_to_leader *fdtol, struct filedesc *fdp) } static int -sysctl_kern_proc_nfds(SYSCTL_HANDLER_ARGS) +filedesc_nfiles(struct filedesc *fdp) { NDSLOTTYPE *map; - struct filedesc *fdp; - u_int namelen; int count, off, minoff; - namelen = arg2; - if (namelen != 1) - return (EINVAL); - - if (*(int *)arg1 != 0) - return (EINVAL); - - fdp = curproc->p_fd; + if (fdp == NULL) + return (0); count = 0; FILEDESC_SLOCK(fdp); map = fdp->fd_map; @@ -4351,7 +4343,37 @@ sysctl_kern_proc_nfds(SYSCTL_HANDLER_ARGS) for (minoff = NDSLOT(0); off >= minoff; --off) count += bitcountl(map[off]); FILEDESC_SUNLOCK(fdp); + return (count); +} + +int +proc_nfiles(struct proc *p) +{ + struct filedesc *fdp; + int res; + + PROC_LOCK(p); + fdp = fdhold(p); + PROC_UNLOCK(p); + res = filedesc_nfiles(fdp); + fddrop(fdp); + return (res); +} + +static int +sysctl_kern_proc_nfds(SYSCTL_HANDLER_ARGS) +{ + u_int namelen; + int count; + + namelen = arg2; + if (namelen != 1) + return (EINVAL); + + if (*(int *)arg1 != 0) + return (EINVAL); + count = filedesc_nfiles(curproc->p_fd); return (SYSCTL_OUT(req, &count, sizeof(count))); } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 53034acb1b54..242f5b8831fd 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -335,6 +335,8 @@ fd_modified(struct filedesc *fdp, int fd, seqc_t seqc) } #endif +int proc_nfiles(struct proc *p); + /* cdir/rdir/jdir manipulation functions. */ struct pwddesc *pdcopy(struct pwddesc *pdp); void pdescfree(struct thread *td);