From owner-p4-projects@FreeBSD.ORG Wed Jul 19 21:11:49 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5347F16A4E0; Wed, 19 Jul 2006 21:11:49 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2DA0B16A4DE for ; Wed, 19 Jul 2006 21:11:49 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E1F3343D46 for ; Wed, 19 Jul 2006 21:11:48 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k6JLBmmK095078 for ; Wed, 19 Jul 2006 21:11:48 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6JLBm3q095075 for perforce@freebsd.org; Wed, 19 Jul 2006 21:11:48 GMT (envelope-from jhb@freebsd.org) Date: Wed, 19 Jul 2006 21:11:48 GMT Message-Id: <200607192111.k6JLBm3q095075@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 101964 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jul 2006 21:11:49 -0000 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 #include #include +#include #include #include #include @@ -65,6 +66,20 @@ #include #include +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) {