From owner-svn-src-all@FreeBSD.ORG Tue Feb 17 19:32:12 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B4E431E4; Tue, 17 Feb 2015 19:32:12 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8606883A; Tue, 17 Feb 2015 19:32:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1HJWCLP092412; Tue, 17 Feb 2015 19:32:12 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1HJWCWk092408; Tue, 17 Feb 2015 19:32:12 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201502171932.t1HJWCWk092408@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 17 Feb 2015 19:32:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278914 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Feb 2015 19:32:12 -0000 Author: glebius Date: Tue Feb 17 19:32:11 2015 New Revision: 278914 URL: https://svnweb.freebsd.org/changeset/base/278914 Log: Use anonymous unions to add possibility to put mbufs into queue(3) STAILQs and SLISTs using the same structure field as good old m_next and m_nextpkt linkage occupy. New code is encouraged to use queue(3) macros, instead of implementing the wheel. However, better not to have a mixture of old style and queue(3) in one file or subsystem. Reviewed by: rwatson, rrs, rpaulo Differential Revision: D1499 Modified: head/sys/kern/uipc_mbuf.c head/sys/sys/mbuf.h Modified: head/sys/kern/uipc_mbuf.c ============================================================================== --- head/sys/kern/uipc_mbuf.c Tue Feb 17 19:27:14 2015 (r278913) +++ head/sys/kern/uipc_mbuf.c Tue Feb 17 19:32:11 2015 (r278914) @@ -120,6 +120,18 @@ CTASSERT(sizeof(struct struct_m_ext) == #endif /* + * Assert that the queue(3) macros produce code of the same size as an old + * plain pointer does. + */ +#ifdef INVARIANTS +static struct mbuf m_assertbuf; +CTASSERT(sizeof(m_assertbuf.m_slist) == sizeof(m_assertbuf.m_next)); +CTASSERT(sizeof(m_assertbuf.m_stailq) == sizeof(m_assertbuf.m_next)); +CTASSERT(sizeof(m_assertbuf.m_slistpkt) == sizeof(m_assertbuf.m_nextpkt)); +CTASSERT(sizeof(m_assertbuf.m_stailqpkt) == sizeof(m_assertbuf.m_nextpkt)); +#endif + +/* * m_get2() allocates minimum mbuf that would fit "size" argument. */ struct mbuf * Modified: head/sys/sys/mbuf.h ============================================================================== --- head/sys/sys/mbuf.h Tue Feb 17 19:27:14 2015 (r278913) +++ head/sys/sys/mbuf.h Tue Feb 17 19:32:11 2015 (r278914) @@ -184,8 +184,16 @@ struct mbuf { * Compile-time assertions in uipc_mbuf.c test these values to ensure * that they are correct. */ - struct mbuf *m_next; /* next buffer in chain */ - struct mbuf *m_nextpkt; /* next chain in queue/record */ + union { /* next buffer in chain */ + struct mbuf *m_next; + SLIST_ENTRY(mbuf) m_slist; + STAILQ_ENTRY(mbuf) m_stailq; + }; + union { /* next chain in queue/record */ + struct mbuf *m_nextpkt; + SLIST_ENTRY(mbuf) m_slistpkt; + STAILQ_ENTRY(mbuf) m_stailqpkt; + }; caddr_t m_data; /* location of data */ int32_t m_len; /* amount of data in this mbuf */ uint32_t m_type:8, /* type of data in this mbuf */