Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_descrip.c
Show First 20 Lines • Show All 851 Lines • ▼ Show 20 Lines | if (new >= fdp->fd_nfiles) { | ||||
* The resource limits are here instead of e.g. | * The resource limits are here instead of e.g. | ||||
* fdalloc(), because the file descriptor table may be | * fdalloc(), because the file descriptor table may be | ||||
* shared between processes, so we can't really use | * shared between processes, so we can't really use | ||||
* racct_add()/racct_sub(). Instead of counting the | * racct_add()/racct_sub(). Instead of counting the | ||||
* number of actually allocated descriptors, just put | * number of actually allocated descriptors, just put | ||||
* the limit on the size of the file descriptor table. | * the limit on the size of the file descriptor table. | ||||
*/ | */ | ||||
#ifdef RACCT | #ifdef RACCT | ||||
if (racct_enable) { | |||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
error = racct_set(p, RACCT_NOFILE, new + 1); | error = racct_set(p, RACCT_NOFILE, new + 1); | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
if (error != 0) { | if (error != 0) { | ||||
FILEDESC_XUNLOCK(fdp); | FILEDESC_XUNLOCK(fdp); | ||||
fdrop(fp, td); | fdrop(fp, td); | ||||
return (EMFILE); | return (EMFILE); | ||||
} | } | ||||
} | |||||
#endif | #endif | ||||
fdgrowtable_exp(fdp, new + 1); | fdgrowtable_exp(fdp, new + 1); | ||||
oldfde = &fdp->fd_ofiles[old]; | oldfde = &fdp->fd_ofiles[old]; | ||||
} | } | ||||
newfde = &fdp->fd_ofiles[new]; | newfde = &fdp->fd_ofiles[new]; | ||||
if (newfde->fde_file == NULL) | if (newfde->fde_file == NULL) | ||||
fdused(fdp, new); | fdused(fdp, new); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 750 Lines • ▼ Show 20 Lines | #endif | ||||
* If none is found, grow the file table. | * If none is found, grow the file table. | ||||
*/ | */ | ||||
fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); | fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); | ||||
if (fd >= maxfd) | if (fd >= maxfd) | ||||
return (EMFILE); | return (EMFILE); | ||||
if (fd >= fdp->fd_nfiles) { | if (fd >= fdp->fd_nfiles) { | ||||
allocfd = min(fd * 2, maxfd); | allocfd = min(fd * 2, maxfd); | ||||
#ifdef RACCT | #ifdef RACCT | ||||
if (racct_enable) { | |||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
error = racct_set(p, RACCT_NOFILE, allocfd); | error = racct_set(p, RACCT_NOFILE, allocfd); | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
if (error != 0) | if (error != 0) | ||||
return (EMFILE); | return (EMFILE); | ||||
} | |||||
#endif | #endif | ||||
/* | /* | ||||
* fd is already equal to first free descriptor >= minfd, so | * fd is already equal to first free descriptor >= minfd, so | ||||
* we only need to grow the table and we are done. | * we only need to grow the table and we are done. | ||||
*/ | */ | ||||
fdgrowtable_exp(fdp, allocfd); | fdgrowtable_exp(fdp, allocfd); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 390 Lines • ▼ Show 20 Lines | fdescfree(struct thread *td) | ||||
struct file *fp; | struct file *fp; | ||||
struct vnode *cdir, *jdir, *rdir; | struct vnode *cdir, *jdir, *rdir; | ||||
int i; | int i; | ||||
fdp = td->td_proc->p_fd; | fdp = td->td_proc->p_fd; | ||||
MPASS(fdp != NULL); | MPASS(fdp != NULL); | ||||
#ifdef RACCT | #ifdef RACCT | ||||
if (racct_enable) { | |||||
PROC_LOCK(td->td_proc); | PROC_LOCK(td->td_proc); | ||||
racct_set(td->td_proc, RACCT_NOFILE, 0); | racct_set(td->td_proc, RACCT_NOFILE, 0); | ||||
PROC_UNLOCK(td->td_proc); | PROC_UNLOCK(td->td_proc); | ||||
} | |||||
#endif | #endif | ||||
if (td->td_proc->p_fdtol != NULL) | if (td->td_proc->p_fdtol != NULL) | ||||
fdclearlocks(td); | fdclearlocks(td); | ||||
mtx_lock(&fdesc_mtx); | mtx_lock(&fdesc_mtx); | ||||
td->td_proc->p_fd = NULL; | td->td_proc->p_fd = NULL; | ||||
mtx_unlock(&fdesc_mtx); | mtx_unlock(&fdesc_mtx); | ||||
▲ Show 20 Lines • Show All 1,811 Lines • Show Last 20 Lines |