Date: Sat, 5 Oct 2024 07:11:22 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: e05087ee1c7b - stable/14 - Add proc_nfiles(9) Message-ID: <202410050711.4957BM2p001396@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=e05087ee1c7b850a331b8a326c9b21b05cfefa5e commit e05087ee1c7b850a331b8a326c9b21b05cfefa5e Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-09-20 16:28:23 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410050711.4957BM2p001396>