From owner-svn-src-all@FreeBSD.ORG Thu Jul 30 12:41:19 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 99E31106567A; Thu, 30 Jul 2009 12:41:19 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 86B138FC1F; Thu, 30 Jul 2009 12:41:19 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6UCfJ33013947; Thu, 30 Jul 2009 12:41:19 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6UCfJbK013946; Thu, 30 Jul 2009 12:41:19 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <200907301241.n6UCfJbK013946@svn.freebsd.org> From: Robert Watson Date: Thu, 30 Jul 2009 12:41:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195972 - head/sys/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Thu, 30 Jul 2009 12:41:20 -0000 Author: rwatson Date: Thu Jul 30 12:41:19 2009 New Revision: 195972 URL: http://svn.freebsd.org/changeset/base/195972 Log: Reorder and recomment vnet.c and vnet.h on the basis that they are no longer solely about the virtual network stack memory allocator. Approved by: re (vimage blanket) Modified: head/sys/net/vnet.c head/sys/net/vnet.h Modified: head/sys/net/vnet.c ============================================================================== --- head/sys/net/vnet.c Thu Jul 30 09:51:04 2009 (r195971) +++ head/sys/net/vnet.c Thu Jul 30 12:41:19 2009 (r195972) @@ -43,11 +43,20 @@ __FBSDID("$FreeBSD$"); #include /*- - * This is the virtual network stack allocator, which provides storage for - * virtualized global variables. These variables are defined/declared using - * the VNET_DEFINE()/VNET_DECLARE() macros, which place them in the - * 'set_vnet' linker set. The details of the implementation are somewhat - * subtle, but allow the majority of most network subsystems to maintain + * This file implements core functions for virtual network stacks: + * + * - Virtual network stack memory allocator, which virtualized global + * variables in the network stack + * + * - Virtualized SYSINIT's/SYSUNINIT's, which allow network stack subsystems + * to register startup/shutdown events to be run for each virtual network + * stack instance. + * + * The virtual network stack allocator provides storage for virtualized + * global variables. These variables are defined/declared using the + * VNET_DEFINE()/VNET_DECLARE() macros, which place them in the 'set_vnet' + * linker set. The details of the implementation are somewhat subtle, but + * allow the majority of most network subsystems to maintain * virtualization-agnostic. * * The virtual network stack allocator handles variables in the base kernel Modified: head/sys/net/vnet.h ============================================================================== --- head/sys/net/vnet.h Thu Jul 30 09:51:04 2009 (r195971) +++ head/sys/net/vnet.h Thu Jul 30 12:41:19 2009 (r195972) @@ -27,66 +27,36 @@ * $FreeBSD$ */ -/* - * This header file defines two sets of interfaces supporting virtualized - * network stacks: a virtual network stack memory allocator, which provides - * support for virtualized global variables via a special linker set, - * set_vnet, and virtualized sysinits/sysuninits, which allow constructors - * and destructors to be run for each network stack subsystem as virtual - * instances are created and destroyed. If VIMAGE isn't compiled into the - * kernel, virtualized global variables compile to normal global variables, - * and virtualized sysinits to regular sysinits. +/*- + * This header file defines several sets of interfaces supporting virtualized + * network stacks: + * + * - A virtual network stack memory allocator, which provides support for + * virtualized global variables via a special linker set, set_vnet. + * + * - Virtualized sysinits/sysuninits, which allow constructors and + * destructors to be run for each network stack subsystem as virtual + * instances are created and destroyed. + * + * If VIMAGE isn't compiled into the kernel, virtualized global variables + * compile to normal global variables, and virtualized sysinits to regular + * sysinits. */ #ifndef _NET_VNET_H_ #define _NET_VNET_H_ +/* + * Virtual network stack memory allocator, which allows global variables to + * be automatically instantiated for each network stack instance. + */ #if defined(_KERNEL) || defined(_WANT_VNET) - #define VNET_SETNAME "set_vnet" #define VNET_SYMPREFIX "vnet_entry_" - #endif #ifdef _KERNEL #ifdef VIMAGE -#include - -/* - * SYSINIT/SYSUNINIT variants that provide per-vnet constructors and - * destructors. - */ -struct vnet_sysinit { - enum sysinit_sub_id subsystem; - enum sysinit_elem_order order; - sysinit_cfunc_t func; - const void *arg; - TAILQ_ENTRY(vnet_sysinit) link; -}; - -#define VNET_SYSINIT(ident, subsystem, order, func, arg) \ - static struct vnet_sysinit ident ## _vnet_init = { \ - subsystem, \ - order, \ - (sysinit_cfunc_t)(sysinit_nfunc_t)func, \ - (arg) \ - }; \ - SYSINIT(vnet_init_ ## ident, subsystem, order, \ - vnet_register_sysinit, &ident ## _vnet_init); \ - SYSUNINIT(vnet_init_ ## ident, subsystem, order, \ - vnet_deregister_sysinit, &ident ## _vnet_init) - -#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \ - static struct vnet_sysinit ident ## _vnet_uninit = { \ - subsystem, \ - order, \ - (sysinit_cfunc_t)(sysinit_nfunc_t)func, \ - (arg) \ - }; \ - SYSINIT(vnet_uninit_ ## ident, subsystem, order, \ - vnet_register_sysuninit, &ident ## _vnet_uninit); \ - SYSUNINIT(vnet_uninit_ ## ident, subsystem, order, \ - vnet_deregister_sysuninit, &ident ## _vnet_uninit) #if defined(__arm__) __asm__(".section " VNET_SETNAME ", \"aw\", %progbits"); @@ -113,6 +83,20 @@ __asm__(".previous"); #define VNET(n) VNET_VNET(curvnet, n) /* + * Virtual network stack allocator interfaces from the kernel linker. + */ +void *vnet_data_alloc(int size); +void vnet_data_copy(void *start, int size); +void vnet_data_free(void *start_arg, int size); + +/* + * Virtual network stack allocator interfaces for vnet setup/teardown. + */ +struct vnet; +void vnet_data_init(struct vnet *vnet); +void vnet_data_destroy(struct vnet *vnet); + +/* * Sysctl variants for vnet-virtualized global variables. Include * to expose these definitions. * @@ -150,18 +134,51 @@ int vnet_sysctl_handle_uint(SYSCTL_HANDL #endif /* SYSCTL_OID */ /* - * Interfaces from the kernel linker. + * Virtual sysinit mechanism, allowing network stack components to declare + * startup and shutdown methods to be run when virtual network stack + * instances are created and destroyed. */ -void *vnet_data_alloc(int size); -void vnet_data_copy(void *start, int size); -void vnet_data_free(void *start_arg, int size); +#include + +/* + * SYSINIT/SYSUNINIT variants that provide per-vnet constructors and + * destructors. + */ +struct vnet_sysinit { + enum sysinit_sub_id subsystem; + enum sysinit_elem_order order; + sysinit_cfunc_t func; + const void *arg; + TAILQ_ENTRY(vnet_sysinit) link; +}; + +#define VNET_SYSINIT(ident, subsystem, order, func, arg) \ + static struct vnet_sysinit ident ## _vnet_init = { \ + subsystem, \ + order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, \ + (arg) \ + }; \ + SYSINIT(vnet_init_ ## ident, subsystem, order, \ + vnet_register_sysinit, &ident ## _vnet_init); \ + SYSUNINIT(vnet_init_ ## ident, subsystem, order, \ + vnet_deregister_sysinit, &ident ## _vnet_init) + +#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \ + static struct vnet_sysinit ident ## _vnet_uninit = { \ + subsystem, \ + order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, \ + (arg) \ + }; \ + SYSINIT(vnet_uninit_ ## ident, subsystem, order, \ + vnet_register_sysuninit, &ident ## _vnet_uninit); \ + SYSUNINIT(vnet_uninit_ ## ident, subsystem, order, \ + vnet_deregister_sysuninit, &ident ## _vnet_uninit) /* - * Interfaces for vnet setup/teardown. + * Run per-vnet sysinits or sysuninits during vnet creation/destruction. */ -struct vnet; -void vnet_data_init(struct vnet *vnet); -void vnet_data_destroy(struct vnet *vnet); void vnet_sysinit(void); void vnet_sysuninit(void); @@ -183,11 +200,20 @@ void vnet_deregister_sysuninit(void *arg #define VNET_DECLARE(t, n) extern t n #define VNET_DEFINE(t, n) t n #define _VNET_PTR(b, n) &VNET_NAME(n) -#define VNET_SYSINIT(ident, subsystem, order, func, arg) \ - SYSINIT(ident, subsystem, order, func, arg) -#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \ - SYSUNINIT(ident, subsystem, order, func, arg) +/* + * Virtualized global variable accessor macros. + */ +#define VNET_VNET_PTR(vnet, n) (&(n)) +#define VNET_VNET(vnet, n) (n) + +#define VNET_PTR(n) (&(n)) +#define VNET(n) (n) + +/* + * When VIMAGE isn't compiled into the kernel, virtaulized SYSCTLs simply + * become normal SYSCTLs. + */ #ifdef SYSCTL_OID #define SYSCTL_VNET_INT(parent, nbr, name, access, ptr, val, descr) \ SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) @@ -205,16 +231,15 @@ void vnet_deregister_sysuninit(void *arg #endif /* SYSCTL_OID */ /* - * Virtualized global variable accessor macros. + * When VIMAGE isn't compiled into the kernel, VNET_SYSINIT/VNET_SYSUNINIT + * map into normal sysinits, which have the same ordering properties. */ -#define VNET_VNET_PTR(vnet, n) (&(n)) -#define VNET_VNET(vnet, n) (n) - -#define VNET_PTR(n) (&(n)) -#define VNET(n) (n) +#define VNET_SYSINIT(ident, subsystem, order, func, arg) \ + SYSINIT(ident, subsystem, order, func, arg) +#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \ + SYSUNINIT(ident, subsystem, order, func, arg) #endif /* VIMAGE */ - #endif /* _KERNEL */ #endif /* !_NET_VNET_H_ */