git: d07675a9352e - main - file: Move code to share fdtol structs into kern_descrip.c
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 04 Aug 2022 13:55:44 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d07675a9352efce5e997e987080b3f98bbfdac96 commit d07675a9352efce5e997e987080b3f98bbfdac96 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-08-04 13:39:25 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-08-04 13:39:25 +0000 file: Move code to share fdtol structs into kern_descrip.c This ensures the filedesc-to-leader code is consistently encapsulated in kern_descrip.c. No functional change intended. Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35988 --- sys/kern/kern_descrip.c | 12 +++++++++++- sys/kern/kern_fork.c | 5 +---- sys/sys/filedesc.h | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 24ab81693e4c..63a7f8b2a6d7 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -4173,7 +4173,8 @@ mountcheckdirs(struct vnode *olddp, struct vnode *newdp) } struct filedesc_to_leader * -filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader) +filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, + struct proc *leader) { struct filedesc_to_leader *fdtol; @@ -4197,6 +4198,15 @@ filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, s return (fdtol); } +struct filedesc_to_leader * +filedesc_to_leader_share(struct filedesc_to_leader *fdtol, struct filedesc *fdp) +{ + FILEDESC_XLOCK(fdp); + fdtol->fdl_refcount++; + FILEDESC_XUNLOCK(fdp); + return (fdtol); +} + static int sysctl_kern_proc_nfds(SYSCTL_HANDLER_ARGS) { diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 60bf8a7093c9..d7f737832824 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -451,10 +451,7 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread * * Shared file descriptor table, and shared * process leaders. */ - fdtol = p1->p_fdtol; - FILEDESC_XLOCK(p1->p_fd); - fdtol->fdl_refcount++; - FILEDESC_XUNLOCK(p1->p_fd); + fdtol = filedesc_to_leader_share(p1->p_fdtol, p1->p_fd); } else { /* * Shared file descriptor table, and different diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 8ecf7d8cb45e..52bd3c97a9ac 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -270,6 +270,9 @@ struct filedesc *fdshare(struct filedesc *fdp); struct filedesc_to_leader * filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp, struct proc *leader); +struct filedesc_to_leader * + filedesc_to_leader_share(struct filedesc_to_leader *fdtol, + struct filedesc *fdp); int getvnode(struct thread *td, int fd, cap_rights_t *rightsp, struct file **fpp); int getvnode_path(struct thread *td, int fd, cap_rights_t *rightsp,