Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jul 2006 21:11:48 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 101964 for review
Message-ID:  <200607192111.k6JLBm3q095075@repoman.freebsd.org>

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

Change 101964 by jhb@jhb_mutex on 2006/07/19 21:11:08

	- Move svr4_delete_socket() over to svr4_socket.c and make all the
	  svr4_sockcache_entry stuff (including svr4_head) private to
	  svr4_socket.c.
	- Add a mutex to protect the svr4 socket cache.

Affected files ...

.. //depot/projects/smpng/sys/compat/svr4/svr4_socket.c#12 edit
.. //depot/projects/smpng/sys/compat/svr4/svr4_socket.h#7 edit
.. //depot/projects/smpng/sys/dev/streams/streams.c#29 edit

Differences ...

==== //depot/projects/smpng/sys/compat/svr4/svr4_socket.c#12 (text+ko) ====

@@ -47,6 +47,7 @@
 #include <sys/systm.h>
 #include <sys/queue.h>
 #include <sys/file.h>
+#include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/socket.h>
@@ -65,6 +66,20 @@
 #include <compat/svr4/svr4_sockmod.h>
 #include <compat/svr4/svr4_proto.h>
 
+struct svr4_sockcache_entry {
+	struct proc *p;		/* Process for the socket		*/
+	void *cookie;		/* Internal cookie used for matching	*/
+	struct sockaddr_un sock;/* Pathname for the socket		*/
+	dev_t dev;		/* Device where the socket lives on	*/
+	ino_t ino;		/* Inode where the socket lives on	*/
+	TAILQ_ENTRY(svr4_sockcache_entry) entries;
+};
+
+static TAILQ_HEAD(, svr4_sockcache_entry) svr4_head =
+    TAILQ_HEAD_INITIALIZER(svr4_head);
+static struct mtx svr4_head_lock;
+MTX_SYSINIT(svr4_head_lock, &svr4_head_lock, "svr4_head", MTX_DEF);
+
 struct sockaddr_un *
 svr4_find_socket(td, fp, dev, ino)
 	struct thread *td;
@@ -76,6 +91,7 @@
 	void *cookie = ((struct socket *)fp->f_data)->so_emuldata;
 
 	DPRINTF(("svr4_find_socket: [%p,%d,%d]: ", td, dev, ino));
+	mtx_lock(&svr4_head_lock);
 	TAILQ_FOREACH(e, &svr4_head, entries)
 		if (e->p == td->td_proc && e->dev == dev && e->ino == ino) {
 #ifdef DIAGNOSTIC
@@ -84,18 +100,15 @@
 #endif
 			e->cookie = cookie;
 			DPRINTF(("%s\n", e->sock.sun_path));
+			mtx_unlock(&svr4_head_lock);
 			return &e->sock;
 		}
 
+	mtx_unlock(&svr4_head_lock);
 	DPRINTF(("not found\n"));
 	return NULL;
 }
 
-
-/*
- * svr4_delete_socket() is in sys/dev/streams.c (because it's called by
- * the streams "soo_close()" routine).
- */
 int
 svr4_add_socket(td, path, st)
 	struct thread *td;
@@ -105,8 +118,6 @@
 	struct svr4_sockcache_entry *e;
 	int len, error;
 
-	mtx_lock(&Giant);
-
 	e = malloc(sizeof(*e), M_TEMP, M_WAITOK);
 	e->cookie = NULL;
 	e->dev = st->st_dev;
@@ -124,13 +135,34 @@
 	e->sock.sun_family = AF_LOCAL;
 	e->sock.sun_len = len;
 
+	mtx_lock(&svr4_head_lock);
 	TAILQ_INSERT_HEAD(&svr4_head, e, entries);
-	mtx_unlock(&Giant);
+	mtx_unlock(&svr4_head_lock);
 	DPRINTF(("svr4_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path,
 		 td->td_proc, e->dev, e->ino));
 	return 0;
 }
 
+void
+svr4_delete_socket(p, fp)
+	struct proc *p;
+	struct file *fp;
+{
+	struct svr4_sockcache_entry *e;
+	void *cookie = ((struct socket *)fp->f_data)->so_emuldata;
+
+	mtx_lock(&svr4_head_lock);
+	TAILQ_FOREACH(e, &svr4_head, entries)
+		if (e->p == p && e->cookie == cookie) {
+			TAILQ_REMOVE(&svr4_head, e, entries);
+			mtx_unlock(&svr4_head_lock);
+			DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n",
+				 e->sock.sun_path, p, (int)e->dev, e->ino));
+			free(e, M_TEMP);
+			return;
+		}
+	mtx_unlock(&svr4_head_lock);
+}
 
 int
 svr4_sys_socket(td, uap)

==== //depot/projects/smpng/sys/compat/svr4/svr4_socket.h#7 (text+ko) ====

@@ -53,17 +53,4 @@
 void svr4_delete_socket(struct proc *, struct file *);
 int svr4_add_socket(struct thread *, const char *, struct stat *);
 
-struct svr4_sockcache_entry {
-	struct proc *p;		/* Process for the socket		*/
-	void *cookie;		/* Internal cookie used for matching	*/
-	struct sockaddr_un sock;/* Pathname for the socket		*/
-	dev_t dev;		/* Device where the socket lives on	*/
-	ino_t ino;		/* Inode where the socket lives on	*/
-	TAILQ_ENTRY(svr4_sockcache_entry) entries;
-};
-
-TAILQ_HEAD(svr4_sockcache_head, svr4_sockcache_entry);
-extern struct svr4_sockcache_head svr4_head;
-extern int svr4_str_initialized;
-
 #endif /* _SVR4_SOCKET_H_ */

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

@@ -68,8 +68,6 @@
 static int svr4_ptm_alloc(struct thread *);
 static  d_open_t	streamsopen;
 
-struct svr4_sockcache_head svr4_head;
-
 /*
  * Device minor numbers
  */
@@ -119,7 +117,6 @@
 {
 	switch (type) {
 	case MOD_LOAD:
-		TAILQ_INIT(&svr4_head);
 		dt_ptm = make_dev(&streams_cdevsw, dev_ptm, 0, 0, 0666,
 			"ptm");
 		dt_arp = make_dev(&streams_cdevsw, dev_arp, 0, 0, 0666,
@@ -371,24 +368,6 @@
 	return st;
 }
 
-void
-svr4_delete_socket(p, fp)
-	struct proc *p;
-	struct file *fp;
-{
-	struct svr4_sockcache_entry *e;
-	void *cookie = ((struct socket *)fp->f_data)->so_emuldata;
-
-	TAILQ_FOREACH(e, &svr4_head, entries)
-		if (e->p == p && e->cookie == cookie) {
-			TAILQ_REMOVE(&svr4_head, e, entries);
-			DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n",
-				 e->sock.sun_path, p, (int)e->dev, e->ino));
-			free(e, M_TEMP);
-			return;
-		}
-}
-
 static int
 svr4_soo_close(struct file *fp, struct thread *td)
 {



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