Browse Source

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
main
Mark Johnston 1 week ago
parent
commit
d07675a935
  1. 12
      sys/kern/kern_descrip.c
  2. 5
      sys/kern/kern_fork.c
  3. 3
      sys/sys/filedesc.h

12
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)
{

5
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

3
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,

Loading…
Cancel
Save