Project

General

Profile

Submit #2790 ยป patch-kern_descrip.c

dclink, 02/21/2015 03:59 AM

 
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index fb263a9..e293059 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -105,6 +105,8 @@ static void fdreserve_locked (struct filedesc *fdp, int fd0, int incr);
static struct file *funsetfd_locked (struct filedesc *fdp, int fd);
static void ffree(struct file *fp);
+static struct filedesc *fdhold(struct proc *p);
+
static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
static MALLOC_DEFINE(M_FILEDESC_TO_LEADER, "file desc to leader",
"file desc to leader structures");
@@ -1483,13 +1485,8 @@ fdrevoke_proc_callback(struct proc *p, void *vinfo)
/*
* Softref the fdp to prevent it from being destroyed
*/
- spin_lock(&p->p_spin);
- if ((fdp = p->p_fd) == NULL) {
- spin_unlock(&p->p_spin);
+ if ((fdp = fdhold(p)) == NULL)
return(0);
- }
- atomic_add_int(&fdp->fd_softrefs, 1);
- spin_unlock(&p->p_spin);
/*
* Locate and close any matching file descriptors.
@@ -2459,6 +2456,18 @@ closef(struct file *fp, struct proc *p)
return (fdrop(fp));
}
+struct filedesc *
+fdhold(struct proc *p)
+{
+ struct filedesc *fdp;
+ spin_lock(&p->p_spin);
+ if ((fdp = p->p_fd) != NULL)
+ atomic_add_int(&fdp->fd_softrefs, 1);
+ spin_unlock(&p->p_spin);
+
+ return(fdp);
+}
+
/*
* MPSAFE
*
@@ -2800,13 +2809,8 @@ sysctl_kern_file_callback(struct proc *p, void *data)
/*
* Softref the fdp to prevent it from being destroyed
*/
- spin_lock(&p->p_spin);
- if ((fdp = p->p_fd) == NULL) {
- spin_unlock(&p->p_spin);
+ if ((fdp = fdhold(p)) == NULL)
return(0);
- }
- atomic_add_int(&fdp->fd_softrefs, 1);
- spin_unlock(&p->p_spin);
/*
* The fdp's own spinlock prevents the contents from being
    (1-1/1)