Allow fdinit() to be called with a NULL fdp argument so we can use

it when setting up init.

Make fdinit() lock the fdp argument as needed.
This commit is contained in:
Poul-Henning Kamp 2004-11-07 12:39:28 +00:00
parent 5ecb9278bc
commit 8ec21e3a68
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=137331
3 changed files with 19 additions and 33 deletions

View File

@ -91,7 +91,6 @@ static struct pgrp pgrp0;
struct proc proc0;
struct thread thread0;
struct ksegrp ksegrp0;
static struct filedesc0 filedesc0;
struct vmspace vmspace0;
struct proc *initproc;
@ -314,9 +313,8 @@ struct sysentvec null_sysvec = {
static void
proc0_init(void *dummy __unused)
{
register struct proc *p;
register struct filedesc0 *fdp;
register unsigned i;
struct proc *p;
unsigned i;
struct thread *td;
struct ksegrp *kg;
@ -406,17 +404,8 @@ proc0_init(void *dummy __unused)
siginit(&proc0);
/* Create the file descriptor table. */
/* XXX this duplicates part of fdinit() */
fdp = &filedesc0;
p->p_fd = &fdp->fd_fd;
p->p_fd = fdinit(NULL);
p->p_fdtol = NULL;
mtx_init(&fdp->fd_fd.fd_mtx, FILEDESC_LOCK_DESC, NULL, MTX_DEF);
fdp->fd_fd.fd_refcnt = 1;
fdp->fd_fd.fd_cmask = CMASK;
fdp->fd_fd.fd_ofiles = fdp->fd_dfiles;
fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
fdp->fd_fd.fd_nfiles = NDFILE;
fdp->fd_fd.fd_map = fdp->fd_dmap;
/* Create the limits structures. */
p->p_limit = lim_alloc();

View File

@ -1403,22 +1403,21 @@ fdinit(fdp)
{
struct filedesc0 *newfdp;
FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
FILEDESC_UNLOCK(fdp);
MALLOC(newfdp, struct filedesc0 *, sizeof(struct filedesc0),
M_FILEDESC, M_WAITOK | M_ZERO);
FILEDESC_LOCK(fdp);
newfdp = malloc(sizeof *newfdp, M_FILEDESC, M_WAITOK | M_ZERO);
mtx_init(&newfdp->fd_fd.fd_mtx, FILEDESC_LOCK_DESC, NULL, MTX_DEF);
newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
if (newfdp->fd_fd.fd_cdir)
VREF(newfdp->fd_fd.fd_cdir);
newfdp->fd_fd.fd_rdir = fdp->fd_rdir;
if (newfdp->fd_fd.fd_rdir)
VREF(newfdp->fd_fd.fd_rdir);
newfdp->fd_fd.fd_jdir = fdp->fd_jdir;
if (newfdp->fd_fd.fd_jdir)
VREF(newfdp->fd_fd.fd_jdir);
if (fdp != NULL) {
FILEDESC_LOCK(fdp);
newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
if (newfdp->fd_fd.fd_cdir)
VREF(newfdp->fd_fd.fd_cdir);
newfdp->fd_fd.fd_rdir = fdp->fd_rdir;
if (newfdp->fd_fd.fd_rdir)
VREF(newfdp->fd_fd.fd_rdir);
newfdp->fd_fd.fd_jdir = fdp->fd_jdir;
if (newfdp->fd_fd.fd_jdir)
VREF(newfdp->fd_fd.fd_jdir);
FILEDESC_UNLOCK(fdp);
}
/* Create the file descriptor table. */
newfdp->fd_fd.fd_refcnt = 1;
@ -1460,7 +1459,9 @@ fdcopy(fdp)
return (NULL);
FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
FILEDESC_UNLOCK(fdp);
newfdp = fdinit(fdp);
FILEDESC_LOCK(fdp);
while (fdp->fd_lastfile >= newfdp->fd_nfiles) {
FILEDESC_UNLOCK(fdp);
FILEDESC_LOCK(newfdp);

View File

@ -225,9 +225,7 @@ fork1(td, flags, pages, procp)
*/
if (flags & RFCFDG) {
struct filedesc *fdtmp;
FILEDESC_LOCK(td->td_proc->p_fd);
fdtmp = fdinit(td->td_proc->p_fd);
FILEDESC_UNLOCK(td->td_proc->p_fd);
fdfree(td);
p1->p_fd = fdtmp;
}
@ -423,9 +421,7 @@ fork1(td, flags, pages, procp)
* Copy filedesc.
*/
if (flags & RFCFDG) {
FILEDESC_LOCK(td->td_proc->p_fd);
fd = fdinit(td->td_proc->p_fd);
FILEDESC_UNLOCK(td->td_proc->p_fd);
fdtol = NULL;
} else if (flags & RFFDG) {
FILEDESC_LOCK(p1->p_fd);