Project

General

Profile

Submit #2790 ยป patch-kern_descrip.c

dclink, 02/21/2015 03:59 AM

 
1
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
2
index fb263a9..e293059 100644
3
--- a/sys/kern/kern_descrip.c
4
+++ b/sys/kern/kern_descrip.c
5
@@ -105,6 +105,8 @@ static void fdreserve_locked (struct filedesc *fdp, int fd0, int incr);
6
 static struct file *funsetfd_locked (struct filedesc *fdp, int fd);
7
 static void ffree(struct file *fp);
8
 
9
+static struct filedesc *fdhold(struct proc *p);
10
+
11
 static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
12
 static MALLOC_DEFINE(M_FILEDESC_TO_LEADER, "file desc to leader",
13
 		     "file desc to leader structures");
14
@@ -1483,13 +1485,8 @@ fdrevoke_proc_callback(struct proc *p, void *vinfo)
15
 	/*
16
 	 * Softref the fdp to prevent it from being destroyed
17
 	 */
18
-	spin_lock(&p->p_spin);
19
-	if ((fdp = p->p_fd) == NULL) {
20
-		spin_unlock(&p->p_spin);
21
+	if ((fdp = fdhold(p)) == NULL)
22
 		return(0);
23
-	}
24
-	atomic_add_int(&fdp->fd_softrefs, 1);
25
-	spin_unlock(&p->p_spin);
26
 
27
 	/*
28
 	 * Locate and close any matching file descriptors.
29
@@ -2459,6 +2456,18 @@ closef(struct file *fp, struct proc *p)
30
 	return (fdrop(fp));
31
 }
32
 
33
+struct filedesc *
34
+fdhold(struct proc *p)
35
+{
36
+	struct filedesc *fdp;
37
+	spin_lock(&p->p_spin);
38
+	if ((fdp = p->p_fd) != NULL)
39
+		atomic_add_int(&fdp->fd_softrefs, 1);
40
+	spin_unlock(&p->p_spin);
41
+
42
+	return(fdp);
43
+}
44
+
45
 /*
46
  * MPSAFE
47
  *
48
@@ -2800,13 +2809,8 @@ sysctl_kern_file_callback(struct proc *p, void *data)
49
 	/*
50
 	 * Softref the fdp to prevent it from being destroyed
51
 	 */
52
-	spin_lock(&p->p_spin);
53
-	if ((fdp = p->p_fd) == NULL) {
54
-		spin_unlock(&p->p_spin);
55
+	if ((fdp = fdhold(p)) == NULL)
56
 		return(0);
57
-	}
58
-	atomic_add_int(&fdp->fd_softrefs, 1);
59
-	spin_unlock(&p->p_spin);
60
 
61
 	/*
62
 	 * The fdp's own spinlock prevents the contents from being
    (1-1/1)