Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 2006 19:24:07 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 102021 for review
Message-ID:  <200607201924.k6KJO7JR039567@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=102021

Change 102021 by jhb@jhb_mutex on 2006/07/20 19:24:01

	- Use fdclose() to do the extraref stuff.
	- Conditionally grab Giant around socreate().
	- Remove D_NEEDGIANT.

Affected files ...

.. //depot/projects/smpng/sys/dev/streams/streams.c#31 edit

Differences ...

==== //depot/projects/smpng/sys/dev/streams/streams.c#31 (text+ko) ====

@@ -99,7 +99,6 @@
  
 static struct cdevsw streams_cdevsw = {
 	.d_version =	D_VERSION,
-	.d_flags =	D_NEEDGIANT,
 	.d_open =	streamsopen,
 	.d_name =	"streams",
 };
@@ -184,14 +183,12 @@
 static  int
 streamsopen(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
-	int type, protocol;
-	int fd, extraref;
+	struct filedesc *fdp;
+	struct svr4_strm *st;
+	struct socket *so;
 	struct file *fp;
-	struct socket *so;
-	struct svr4_strm *st;
-	int error;
-	int family;
-	struct proc *p = td->td_proc;
+	int family, type, protocol;
+	int error, fd;
 	
 	if (td->td_dupfd >= 0)
 	  return ENODEV;
@@ -242,32 +239,26 @@
 	  return EOPNOTSUPP;
 	}
 
+	fdp = td->td_proc->p_fd;
 	if ((error = falloc(td, &fp, &fd)) != 0)
 	  return error;
 	/* An extra reference on `fp' has been held for us by falloc(). */
 
-	if ((error = socreate(family, &so, type, protocol,
-	    td->td_ucred, td)) != 0) {
-	  FILEDESC_LOCK_FAST(p->p_fd);
-	  /* Check the fd table entry hasn't changed since we made it. */
-	  extraref = 0;
-	  if (p->p_fd->fd_ofiles[fd] == fp) {
-	    p->p_fd->fd_ofiles[fd] = NULL;
-	    extraref = 1;
-	  }
-	  FILEDESC_UNLOCK_FAST(p->p_fd);
-	  if (extraref)
-	    fdrop(fp, td);
-	  fdrop(fp, td);
-	  return error;
+	NET_LOCK_GIANT();
+	error = socreate(family, &so, type, protocol, td->td_ucred, td);
+	NET_UNLOCK_GIANT();
+	if (error) {
+	   fdclose(fdp, fp, fd, td);
+	   fdrop(fp, td);
+	   return error;
 	}
 
-	FILEDESC_LOCK_FAST(p->p_fd);
+	FILEDESC_LOCK_FAST(fdp);
 	fp->f_data = so;
 	fp->f_flag = FREAD|FWRITE;
 	fp->f_ops = &svr4_netops;
 	fp->f_type = DTYPE_SOCKET;
-	FILEDESC_UNLOCK_FAST(p->p_fd);
+	FILEDESC_UNLOCK_FAST(fdp);
 
 	/*
 	 * Allocate a stream structure and attach it to this socket.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607201924.k6KJO7JR039567>