fd: move out actual fp installation to _finstall
Use it in fd passing functions as the first step towards fd code cleanup.
This commit is contained in:
parent
3768a5dfb5
commit
ea31808c3b
@ -1750,26 +1750,18 @@ falloc_noinstall(struct thread *td, struct file **resultfp)
|
||||
/*
|
||||
* Install a file in a file descriptor table.
|
||||
*/
|
||||
int
|
||||
finstall(struct thread *td, struct file *fp, int *fd, int flags,
|
||||
void
|
||||
_finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
|
||||
struct filecaps *fcaps)
|
||||
{
|
||||
struct filedesc *fdp = td->td_proc->p_fd;
|
||||
struct filedescent *fde;
|
||||
int error;
|
||||
|
||||
KASSERT(fd != NULL, ("%s: fd == NULL", __func__));
|
||||
KASSERT(fp != NULL, ("%s: fp == NULL", __func__));
|
||||
MPASS(fp != NULL);
|
||||
if (fcaps != NULL)
|
||||
filecaps_validate(fcaps, __func__);
|
||||
FILEDESC_XLOCK_ASSERT(fdp);
|
||||
|
||||
FILEDESC_XLOCK(fdp);
|
||||
if ((error = fdalloc(td, 0, fd))) {
|
||||
FILEDESC_XUNLOCK(fdp);
|
||||
return (error);
|
||||
}
|
||||
fhold(fp);
|
||||
fde = &fdp->fd_ofiles[*fd];
|
||||
fde = &fdp->fd_ofiles[fd];
|
||||
#ifdef CAPABILITIES
|
||||
seq_write_begin(&fde->fde_seq);
|
||||
#endif
|
||||
@ -1783,6 +1775,24 @@ finstall(struct thread *td, struct file *fp, int *fd, int flags,
|
||||
#ifdef CAPABILITIES
|
||||
seq_write_end(&fde->fde_seq);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
finstall(struct thread *td, struct file *fp, int *fd, int flags,
|
||||
struct filecaps *fcaps)
|
||||
{
|
||||
struct filedesc *fdp = td->td_proc->p_fd;
|
||||
int error;
|
||||
|
||||
MPASS(fd != NULL);
|
||||
|
||||
FILEDESC_XLOCK(fdp);
|
||||
if ((error = fdalloc(td, 0, fd))) {
|
||||
FILEDESC_XUNLOCK(fdp);
|
||||
return (error);
|
||||
}
|
||||
fhold(fp);
|
||||
_finstall(fdp, fp, *fd, flags, fcaps);
|
||||
FILEDESC_XUNLOCK(fdp);
|
||||
return (0);
|
||||
}
|
||||
|
@ -1736,7 +1736,7 @@ unp_externalize(struct mbuf *control, struct mbuf **controlp, int flags)
|
||||
int i;
|
||||
int *fdp;
|
||||
struct filedesc *fdesc = td->td_proc->p_fd;
|
||||
struct filedescent *fde, **fdep;
|
||||
struct filedescent **fdep;
|
||||
void *data;
|
||||
socklen_t clen = control->m_len, datalen;
|
||||
int error, newfds;
|
||||
@ -1795,13 +1795,10 @@ unp_externalize(struct mbuf *control, struct mbuf **controlp, int flags)
|
||||
goto next;
|
||||
}
|
||||
for (i = 0; i < newfds; i++, fdp++) {
|
||||
fde = &fdesc->fd_ofiles[*fdp];
|
||||
fde->fde_file = fdep[i]->fde_file;
|
||||
filecaps_move(&fdep[i]->fde_caps,
|
||||
&fde->fde_caps);
|
||||
if ((flags & MSG_CMSG_CLOEXEC) != 0)
|
||||
fde->fde_flags |= UF_EXCLOSE;
|
||||
unp_externalize_fp(fde->fde_file);
|
||||
_finstall(fdesc, fdep[i]->fde_file, *fdp,
|
||||
(flags & MSG_CMSG_CLOEXEC) != 0 ? UF_EXCLOSE : 0,
|
||||
&fdep[i]->fde_caps);
|
||||
unp_externalize_fp(fdep[i]->fde_file);
|
||||
}
|
||||
FILEDESC_XUNLOCK(fdesc);
|
||||
free(fdep[0], M_FILECAPS);
|
||||
|
@ -147,7 +147,9 @@ int dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
|
||||
int falloc(struct thread *td, struct file **resultfp, int *resultfd,
|
||||
int flags);
|
||||
int falloc_noinstall(struct thread *td, struct file **resultfp);
|
||||
int finstall(struct thread *td, struct file *fp, int *resultfp, int flags,
|
||||
void _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
|
||||
struct filecaps *fcaps);
|
||||
int finstall(struct thread *td, struct file *fp, int *resultfd, int flags,
|
||||
struct filecaps *fcaps);
|
||||
int fdalloc(struct thread *td, int minfd, int *result);
|
||||
int fdallocn(struct thread *td, int minfd, int *fds, int n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user