From nobody Sat Oct 5 07:11:22 2024 X-Original-To: dev-commits-src-branches@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 4XLGmW2DDsz5XrPt; Sat, 05 Oct 2024 07:11:23 +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 4XLGmW0dR9z4NF1; Sat, 5 Oct 2024 07:11:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112283; 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=/Cl5rPdnxEXBVYzR8PY8Y4iKKW8JiCyfjmNgRHYC9HA=; b=evb896bM6/34NBtfMu7SHq5Q18yTC6GBX7gbGBroyDuq2O/8Hp3lMRm2Shbbpn1Z0Gh4TE SBEQNb0oJo/caeFxYZTd89Vx3+aiMDTtbeVIb/0OdgnT6ehm1Hcv1r6v1aGVh5HLqI51Ju QNMu76djdqeLVgKd3rLswDfPTMKVMXh0q6HEv9BOynT7MhpZmJHS5tDeaZOQp6uNKN/o3W y4BEV+eHNqbrTvW/G7SqjY3LcIEoIs1186aYgObrEbSW7gq5sx/bctLY5DuYOJJ3L+U/Wn zWd3hg+0Br1ikb9Id+MjNqnkvPpllKAAiRCID55YaHX1eYypikgr+vqp0WIEag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112283; 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=/Cl5rPdnxEXBVYzR8PY8Y4iKKW8JiCyfjmNgRHYC9HA=; b=wuKoW81SkcPNSudF/38BV9JUCvn8LpDMMFCo9NO6RwPnZH5wpDafj1RkwBz5sBA3sxtV9p QXIzYQO3xWnpYH+uBvie8INxV7XLQNA6KqTFlMo2AKYpSRpEBQS2ayAK4zcxWdYyWbicuc jtpZy6mDukBWSolCfhLm2ucb6Bu8p5OVOtx3aQKPVuZOe/2R3APnkq4bLq6VcnNtYzEthK 29Sn22mH3IlsPJJDt0zGIalqe9OyY/krXyAr+oQ0ShsbvJJuyyN6YdwTDMH06K0oD0uNLr rq7iOL1iRLCuP4p0sAfWR4ENJOF0liGCcjqihVPdKkuegjqrelwzRy0594BJng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112283; a=rsa-sha256; cv=none; b=PWJDoKfdLAORIX86YCBi0kRIn9rP8zTRPBgk1COS8XKYAsbtwNLK8rdzTn0NZWlbBcthE1 Twan6TPe8RumqcRiBuTbs1dx0UP8afTjF8QsDz4fGjj6FV16B/K3rBF1tpEkcveUMcjnXe 5ZfECLHZDiScHOx1epeG669nGDLFu/Mb9G8hj+YPvXEkrgB4R9SL83VvM3B/rRPWBizQZU p4ssjCHU/J66pgnS2JSE+BmGUp00+fvrtUs5QZO63uOHeaR6YOCrqJjO1OIMv2sOrZBZZJ +lAWp2RFDFsGcWLmehcxVfmOjQi4toE+TTs54eaoX7WSOH22asWevMm6EHqmXQ== 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 4XLGmW0Fz8z1862; Sat, 5 Oct 2024 07:11:23 +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 4957BMZ6001399; Sat, 5 Oct 2024 07:11:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957BM2p001396; Sat, 5 Oct 2024 07:11:22 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:22 GMT Message-Id: <202410050711.4957BM2p001396@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: e05087ee1c7b - stable/14 - Add proc_nfiles(9) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: e05087ee1c7b850a331b8a326c9b21b05cfefa5e Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=e05087ee1c7b850a331b8a326c9b21b05cfefa5e commit e05087ee1c7b850a331b8a326c9b21b05cfefa5e Author: Konstantin Belousov AuthorDate: 2024-09-20 16:28:23 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:55 +0000 Add proc_nfiles(9) (cherry picked from commit 9c3e516ad08145ad47248633b54fd1b7fc0ef981) --- 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 35e9afea4625..9036e3a25ab8 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -4331,21 +4331,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; @@ -4353,7 +4345,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 06e086fba152..c0fb4e3834e1 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -337,6 +337,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);