From owner-p4-projects@FreeBSD.ORG Thu Jul 20 19:07:46 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 6786716A4EF; Thu, 20 Jul 2006 19:07:46 +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 3E49816A4EA for ; Thu, 20 Jul 2006 19:07:46 +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 DFE2243D53 for ; Thu, 20 Jul 2006 19:07:45 +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 k6KJ7jkA038512 for ; Thu, 20 Jul 2006 19:07:45 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6KJ7jca038509 for perforce@freebsd.org; Thu, 20 Jul 2006 19:07:45 GMT (envelope-from jhb@freebsd.org) Date: Thu, 20 Jul 2006 19:07:45 GMT Message-Id: <200607201907.k6KJ7jca038509@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 102018 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: Thu, 20 Jul 2006 19:07:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=102018 Change 102018 by jhb@jhb_mutex on 2006/07/20 19:07:21 Don't allocate a stream structure for a socket on demand but instead just do it in streamsopen(). This avoids changing f_ops during the life of a struct file which is a Bad Thing(tm). I think it is also unnecessary since all sockets for which stream operations make sense should already be created via streamsopen() anyway. Affected files ... .. //depot/projects/smpng/sys/dev/streams/streams.c#30 edit .. //depot/projects/smpng/sys/notes#86 edit Differences ... ==== //depot/projects/smpng/sys/dev/streams/streams.c#30 (text+ko) ==== @@ -188,6 +188,7 @@ int fd, extraref; struct file *fp; struct socket *so; + struct svr4_strm *st; int error; int family; struct proc *p = td->td_proc; @@ -268,7 +269,19 @@ fp->f_type = DTYPE_SOCKET; FILEDESC_UNLOCK_FAST(p->p_fd); - (void)svr4_stream_get(fp); + /* + * Allocate a stream structure and attach it to this socket. + * We don't bother locking so_emuldata for SVR4 stream sockets as + * its value is constant for the lifetime of the stream once it + * is initialized here. + */ + st = malloc(sizeof(struct svr4_strm), M_TEMP, M_WAITOK); + st->s_family = so->so_proto->pr_domain->dom_family; + st->s_cmd = ~0; + st->s_afd = -1; + st->s_eventmask = 0; + so->so_emuldata = st; + fdrop(fp, td); td->td_dupfd = fd; return ENXIO; @@ -331,41 +344,12 @@ struct file *fp; { struct socket *so; - struct svr4_strm *st; if (fp == NULL || fp->f_type != DTYPE_SOCKET) return NULL; so = fp->f_data; - - /* - * mpfixme: lock socketbuffer here - */ - if (so->so_emuldata) { - return so->so_emuldata; - } - - /* Allocate a new one. */ - st = malloc(sizeof(struct svr4_strm), M_TEMP, M_WAITOK); - st->s_family = so->so_proto->pr_domain->dom_family; - st->s_cmd = ~0; - st->s_afd = -1; - st->s_eventmask = 0; - /* - * avoid a race where we loose due to concurrancy issues - * of two threads trying to allocate the so_emuldata. - */ - if (so->so_emuldata) { - /* lost the race, use the existing emuldata */ - FREE(st, M_TEMP); - st = so->so_emuldata; - } else { - /* we won, or there was no race, use our copy */ - so->so_emuldata = st; - fp->f_ops = &svr4_netops; - } - - return st; + return so->so_emuldata; } static int ==== //depot/projects/smpng/sys/notes#86 (text+ko) ==== @@ -85,7 +85,7 @@ + compat32 - svr4 - svr4_stream_get() and friends - - need to see where this is called and see if all of the files + + need to see where this is called and see if all of the files should already have f_ops set correctly and if we can just allocate so_emuldata directly in streamsopen() + XXX: svr4_add_socket() can add duplicates? it's ok, just