svn commit: r183795 - in stable/7/sys: . fs/portalfs kern sys

Robert Watson rwatson at FreeBSD.org
Sun Oct 12 10:03:12 UTC 2008


Author: rwatson
Date: Sun Oct 12 10:03:11 2008
New Revision: 183795
URL: http://svn.freebsd.org/changeset/base/183795

Log:
  Merge r183572, r173649, r183650, r183690, and r183764 from head to
  stable/7:
  
    Further minor cleanups to UNIX domain sockets:
  
    - Staticize and locally prototype functions uipc_ctloutput(),
      unp_dispose(), unp_init(), and unp_externalize(), none of which have
      been required outside of uipc_usrreq.c since uipc_proto.c was removed.
    - Remove stale prototype for uipc_usrreq(), which has not existed in the
      code since 1997
    - Forward declare and staticize uipc_usrreqs structure in uipc_usrreq.c
      and not un.h.
    - Comment on why uipc_connect2() is still non-static -- it is used
      directly by fifofs.
    - Remove stale comments, tidy up whitespace.
  
    Use soconnect2() rather than directly invoking uipc_connect2() to
    interconnect two UNIX domain sockets.
  
    Now that portalfs doesn't directly invoke uipc_connect2(), make it a
    static symbol.
  
    Remove stale comment (and XXX saying so) about why we zero the file
    descriptor pointer in unp_freerights: we can no longer recurse into
    unp_gc due to unp_gc being invoked in a deferred way, but it's still
    a good idea.
  
    Remove stale comment: while uipc_connect2() was, until recently, not
    static so it could be used by fifofs (actually portalfs), it is now
    static.
  
    Submitted by:   kensmith
  
  Approved by:	re (kensmith)

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/fs/portalfs/portal_vnops.c
  stable/7/sys/kern/uipc_usrreq.c
  stable/7/sys/sys/un.h

Modified: stable/7/sys/fs/portalfs/portal_vnops.c
==============================================================================
--- stable/7/sys/fs/portalfs/portal_vnops.c	Sun Oct 12 09:58:10 2008	(r183794)
+++ stable/7/sys/fs/portalfs/portal_vnops.c	Sun Oct 12 10:03:11 2008	(r183795)
@@ -197,7 +197,7 @@ portal_connect(so, so2)
 		    M_NOWAIT);
 	so2 = so3;
 
-	return (uipc_connect2(so, so2));
+	return (soconnect2(so, so2));
 }
 
 static int

Modified: stable/7/sys/kern/uipc_usrreq.c
==============================================================================
--- stable/7/sys/kern/uipc_usrreq.c	Sun Oct 12 09:58:10 2008	(r183794)
+++ stable/7/sys/kern/uipc_usrreq.c	Sun Oct 12 10:03:11 2008	(r183795)
@@ -224,10 +224,13 @@ static struct rwlock	unp_global_rwlock;
 #define	UNP_PCB_UNLOCK(unp)		mtx_unlock(&(unp)->unp_mtx)
 #define	UNP_PCB_LOCK_ASSERT(unp)	mtx_assert(&(unp)->unp_mtx, MA_OWNED)
 
+static int	uipc_connect2(struct socket *, struct socket *);
+static int	uipc_ctloutput(struct socket *, struct sockopt *);
 static int	unp_connect(struct socket *, struct sockaddr *,
 		    struct thread *);
 static int	unp_connect2(struct socket *so, struct socket *so2, int);
 static void	unp_disconnect(struct unpcb *unp, struct unpcb *unp2);
+static void	unp_dispose(struct mbuf *);
 static void	unp_shutdown(struct unpcb *);
 static void	unp_drop(struct unpcb *, int);
 static void	unp_gc(__unused void *, int);
@@ -235,13 +238,16 @@ static void	unp_scan(struct mbuf *, void
 static void	unp_mark(struct file *);
 static void	unp_discard(struct file *);
 static void	unp_freerights(struct file **, int);
+static void	unp_init(void);
 static int	unp_internalize(struct mbuf **, struct thread *);
+static int	unp_externalize(struct mbuf *, struct mbuf **);
 static struct mbuf	*unp_addsockcred(struct thread *, struct mbuf *);
 
 /*
  * Definitions of protocols supported in the LOCAL domain.
  */
 static struct domain localdomain;
+static struct pr_usrreqs uipc_usrreqs;
 static struct protosw localsw[] = {
 {
 	.pr_type =		SOCK_STREAM,
@@ -520,7 +526,7 @@ uipc_close(struct socket *so)
 	UNP_GLOBAL_WUNLOCK();
 }
 
-int
+static int
 uipc_connect2(struct socket *so1, struct socket *so2)
 {
 	struct unpcb *unp, *unp2;
@@ -540,8 +546,6 @@ uipc_connect2(struct socket *so1, struct
 	return (error);
 }
 
-/* control is EOPNOTSUPP */
-
 static void
 uipc_detach(struct socket *so)
 {
@@ -986,7 +990,7 @@ uipc_sockaddr(struct socket *so, struct 
 	return (0);
 }
 
-struct pr_usrreqs uipc_usrreqs = {
+static struct pr_usrreqs uipc_usrreqs = {
 	.pru_abort = 		uipc_abort,
 	.pru_accept =		uipc_accept,
 	.pru_attach =		uipc_attach,
@@ -1005,7 +1009,7 @@ struct pr_usrreqs uipc_usrreqs = {
 	.pru_close =		uipc_close,
 };
 
-int
+static int
 uipc_ctloutput(struct socket *so, struct sockopt *sopt)
 {
 	struct unpcb *unp;
@@ -1494,7 +1498,6 @@ unp_drop(struct unpcb *unp, int errno)
 	unp2 = unp->unp_conn;
 	if (unp2 == NULL)
 		return;
-
 	UNP_PCB_LOCK(unp2);
 	unp_disconnect(unp, unp2);
 	UNP_PCB_UNLOCK(unp2);
@@ -1507,19 +1510,13 @@ unp_freerights(struct file **rp, int fdc
 	struct file *fp;
 
 	for (i = 0; i < fdcount; i++) {
-		/*
-		 * Zero the pointer before calling unp_discard since it may
-		 * end up in unp_gc()..
-		 *
-		 * XXXRW: This is less true than it used to be.
-		 */
 		fp = *rp;
 		*rp++ = NULL;
 		unp_discard(fp);
 	}
 }
 
-int
+static int
 unp_externalize(struct mbuf *control, struct mbuf **controlp)
 {
 	struct thread *td = curthread;		/* XXX */
@@ -1539,16 +1536,13 @@ unp_externalize(struct mbuf *control, st
 	error = 0;
 	if (controlp != NULL) /* controlp == NULL => free control messages */
 		*controlp = NULL;
-
 	while (cm != NULL) {
 		if (sizeof(*cm) > clen || cm->cmsg_len > clen) {
 			error = EINVAL;
 			break;
 		}
-
 		data = CMSG_DATA(cm);
 		datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
-
 		if (cm->cmsg_level == SOL_SOCKET
 		    && cm->cmsg_type == SCM_RIGHTS) {
 			newfds = datalen / sizeof(struct file *);
@@ -1614,7 +1608,6 @@ unp_externalize(struct mbuf *control, st
 			    CMSG_DATA(mtod(*controlp, struct cmsghdr *)),
 			    datalen);
 		}
-
 		controlp = &(*controlp)->m_next;
 
 next:
@@ -1629,7 +1622,6 @@ next:
 	}
 
 	m_freem(control);
-
 	return (error);
 }
 
@@ -1640,7 +1632,7 @@ unp_zone_change(void *tag)
 	uma_zone_set_max(unp_zone, maxsockets);
 }
 
-void
+static void
 unp_init(void)
 {
 
@@ -1678,14 +1670,12 @@ unp_internalize(struct mbuf **controlp, 
 
 	error = 0;
 	*controlp = NULL;
-
 	while (cm != NULL) {
 		if (sizeof(*cm) > clen || cm->cmsg_level != SOL_SOCKET
 		    || cm->cmsg_len > clen) {
 			error = EINVAL;
 			goto out;
 		}
-
 		data = CMSG_DATA(cm);
 		datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
 
@@ -1700,7 +1690,6 @@ unp_internalize(struct mbuf **controlp, 
 				error = ENOBUFS;
 				goto out;
 			}
-
 			cmcred = (struct cmsgcred *)
 			    CMSG_DATA(mtod(*controlp, struct cmsghdr *));
 			cmcred->cmcred_pid = p->p_pid;
@@ -1708,7 +1697,7 @@ unp_internalize(struct mbuf **controlp, 
 			cmcred->cmcred_gid = td->td_ucred->cr_rgid;
 			cmcred->cmcred_euid = td->td_ucred->cr_uid;
 			cmcred->cmcred_ngroups = MIN(td->td_ucred->cr_ngroups,
-							CMGROUP_MAX);
+			    CMGROUP_MAX);
 			for (i = 0; i < cmcred->cmcred_ngroups; i++)
 				cmcred->cmcred_groups[i] =
 				    td->td_ucred->cr_groups[i];
@@ -1740,8 +1729,8 @@ unp_internalize(struct mbuf **controlp, 
 			}
 
 			/*
-			 * Now replace the integer FDs with pointers to
-			 * the associated global file table entry..
+			 * Now replace the integer FDs with pointers to the
+			 * associated global file table entry..
 			 */
 			newlen = oldfds * sizeof(struct file *);
 			*controlp = sbcreatecontrol(NULL, newlen,
@@ -1751,7 +1740,6 @@ unp_internalize(struct mbuf **controlp, 
 				error = E2BIG;
 				goto out;
 			}
-
 			fdp = data;
 			rp = (struct file **)
 			    CMSG_DATA(mtod(*controlp, struct cmsghdr *));
@@ -1787,7 +1775,6 @@ unp_internalize(struct mbuf **controlp, 
 		}
 
 		controlp = &(*controlp)->m_next;
-
 		if (CMSG_SPACE(datalen) < clen) {
 			clen -= CMSG_SPACE(datalen);
 			cm = (struct cmsghdr *)
@@ -1800,7 +1787,6 @@ unp_internalize(struct mbuf **controlp, 
 
 out:
 	m_freem(control);
-
 	return (error);
 }
 
@@ -1814,7 +1800,6 @@ unp_addsockcred(struct thread *td, struc
 	int i;
 
 	ngroups = MIN(td->td_ucred->cr_ngroups, CMGROUP_MAX);
-
 	m = sbcreatecontrol(NULL, SOCKCREDSIZE(ngroups), SCM_CREDS, SOL_SOCKET);
 	if (m == NULL)
 		return (control);
@@ -1851,7 +1836,6 @@ unp_addsockcred(struct thread *td, struc
 
 	/* Prepend it to the head. */
 	m->m_next = control;
-
 	return (m);
 }
 
@@ -2091,7 +2075,7 @@ again:
 	free(extra_ref, M_TEMP);
 }
 
-void
+static void
 unp_dispose(struct mbuf *m)
 {
 

Modified: stable/7/sys/sys/un.h
==============================================================================
--- stable/7/sys/sys/un.h	Sun Oct 12 09:58:10 2008	(r183794)
+++ stable/7/sys/sys/un.h	Sun Oct 12 10:03:11 2008	(r183795)
@@ -57,27 +57,13 @@ struct sockaddr_un {
 #define	LOCAL_CREDS		0x002	/* pass credentials to receiver */
 #define	LOCAL_CONNWAIT		0x004	/* connects block until accepted */
 
-#ifdef _KERNEL
-struct mbuf;
-struct socket;
-struct sockopt;
-
-int	uipc_connect2(struct socket *so1, struct socket *so2);
-int	uipc_ctloutput(struct socket *so, struct sockopt *sopt);
-int	uipc_usrreq(struct socket *so, int req, struct mbuf *m,
-		struct mbuf *nam, struct mbuf *control);
-void	unp_dispose(struct mbuf *m);
-int	unp_externalize(struct mbuf *mbuf, struct mbuf **controlp);
-void	unp_init(void);
-extern	struct pr_usrreqs uipc_usrreqs;
-
-#else /* !_KERNEL */
+#ifndef _KERNEL
 
 /* actual length of an initialized sockaddr_un */
 #define SUN_LEN(su) \
 	(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
 
-#endif /* _KERNEL */
+#endif /* !_KERNEL */
 
 #endif /* __BSD_VISIBLE */
 


More information about the svn-src-all mailing list