diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-08-01 19:26:27 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-08-01 19:26:27 +0000 |
commit | fb9ffed6504601ed9da2c6b9a620b133c838964c (patch) | |
tree | 6dc533c8b591922258259a32957fdee2632a29ac /sys/kern | |
parent | 2d4b24984c5d2ea2556ae2b1ef1df7f0833dc1b5 (diff) | |
download | FreeBSD-src-fb9ffed6504601ed9da2c6b9a620b133c838964c.zip FreeBSD-src-fb9ffed6504601ed9da2c6b9a620b133c838964c.tar.gz |
Merge the remainder of kern_vimage.c and vimage.h into vnet.c and
vnet.h, we now use jails (rather than vimages) as the abstraction
for virtualization management, and what remained was specific to
virtual network stacks. Minor cleanups are done in the process,
and comments updated to reflect these changes.
Reviewed by: bz
Approved by: re (vimage blanket)
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_jail.c | 5 | ||||
-rw-r--r-- | sys/kern/kern_linker.c | 3 | ||||
-rw-r--r-- | sys/kern/kern_poll.c | 1 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 1 | ||||
-rw-r--r-- | sys/kern/kern_uuid.c | 1 | ||||
-rw-r--r-- | sys/kern/kern_vimage.c | 186 | ||||
-rw-r--r-- | sys/kern/sys_socket.c | 2 | ||||
-rw-r--r-- | sys/kern/uipc_domain.c | 4 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 3 | ||||
-rw-r--r-- | sys/kern/uipc_syscalls.c | 3 | ||||
-rw-r--r-- | sys/kern/uipc_usrreq.c | 3 |
11 files changed, 16 insertions, 196 deletions
diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 03612d7..cf5dfd8 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -58,9 +58,12 @@ __FBSDID("$FreeBSD$"); #include <sys/syscallsubr.h> #include <sys/sysctl.h> #include <sys/vnode.h> -#include <sys/vimage.h> + #include <net/if.h> +#include <net/vnet.h> + #include <netinet/in.h> + #ifdef DDB #include <ddb/ddb.h> #ifdef INET6 diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index 73cee6c..9387ba8 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -51,7 +51,8 @@ __FBSDID("$FreeBSD$"); #include <sys/vnode.h> #include <sys/syscallsubr.h> #include <sys/sysctl.h> -#include <sys/vimage.h> + +#include <net/vnet.h> #include <security/mac/mac_framework.h> diff --git a/sys/kern/kern_poll.c b/sys/kern/kern_poll.c index 5396240..5df26bb 100644 --- a/sys/kern/kern_poll.c +++ b/sys/kern/kern_poll.c @@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$"); #include <sys/sockio.h> #include <sys/sysctl.h> #include <sys/syslog.h> -#include <sys/vimage.h> #include <net/if.h> /* for IFF_* flags */ #include <net/netisr.h> /* for NETISR_POLL */ diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 535ea81..bb5b6a0 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$"); #include <sys/sx.h> #include <sys/sysproto.h> #include <sys/uio.h> -#include <sys/vimage.h> #ifdef KTRACE #include <sys/ktrace.h> #endif diff --git a/sys/kern/kern_uuid.c b/sys/kern/kern_uuid.c index cd88538..e7e4123 100644 --- a/sys/kern/kern_uuid.c +++ b/sys/kern/kern_uuid.c @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include <sys/sysproto.h> #include <sys/systm.h> #include <sys/uuid.h> -#include <sys/vimage.h> #include <net/if.h> #include <net/if_dl.h> diff --git a/sys/kern/kern_vimage.c b/sys/kern/kern_vimage.c deleted file mode 100644 index 9c86b75..0000000 --- a/sys/kern/kern_vimage.c +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * Copyright (c) 2004-2009 University of Zagreb - * Copyright (c) 2006-2009 FreeBSD Foundation - * - * This software was developed by the University of Zagreb and the - * FreeBSD Foundation under sponsorship by the Stichting NLnet and the - * FreeBSD Foundation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include "opt_ddb.h" - -#include <sys/param.h> -#include <sys/jail.h> -#include <sys/kernel.h> -#include <sys/lock.h> -#include <sys/malloc.h> -#include <sys/socket.h> -#include <sys/sockio.h> -#include <sys/sx.h> -#include <sys/vimage.h> -#ifdef DDB -#include <ddb/ddb.h> -#endif - -#include <net/if.h> -#include <net/route.h> -#include <net/vnet.h> - -MALLOC_DEFINE(M_VNET, "vnet", "network stack control block"); - -struct rwlock vnet_rwlock; -struct sx vnet_sxlock; - -#define VNET_LIST_WLOCK() do { \ - sx_xlock(&vnet_sxlock); \ - rw_wlock(&vnet_rwlock); \ -} while (0) - -#define VNET_LIST_WUNLOCK() do { \ - rw_wunlock(&vnet_rwlock); \ - sx_xunlock(&vnet_sxlock); \ -} while (0) - -struct vnet_list_head vnet_head; -struct vnet *vnet0; - - -struct vnet * -vnet_alloc(void) -{ - struct vnet *vnet; - - vnet = malloc(sizeof(struct vnet), M_VNET, M_WAITOK | M_ZERO); - vnet->vnet_magic_n = VNET_MAGIC_N; - vnet_data_init(vnet); - - /* Initialize / attach vnet module instances. */ - CURVNET_SET_QUIET(vnet); - - sx_xlock(&vnet_sxlock); - vnet_sysinit(); - CURVNET_RESTORE(); - - rw_wlock(&vnet_rwlock); - LIST_INSERT_HEAD(&vnet_head, vnet, vnet_le); - VNET_LIST_WUNLOCK(); - - return (vnet); -} - -void -vnet_destroy(struct vnet *vnet) -{ - struct ifnet *ifp, *nifp; - - KASSERT(vnet->vnet_sockcnt == 0, - ("%s: vnet still has sockets", __func__)); - - VNET_LIST_WLOCK(); - LIST_REMOVE(vnet, vnet_le); - rw_wunlock(&vnet_rwlock); - - CURVNET_SET_QUIET(vnet); - - /* Return all inherited interfaces to their parent vnets. */ - TAILQ_FOREACH_SAFE(ifp, &V_ifnet, if_link, nifp) { - if (ifp->if_home_vnet != ifp->if_vnet) - if_vmove(ifp, ifp->if_home_vnet); - } - - vnet_sysuninit(); - sx_xunlock(&vnet_sxlock); - - CURVNET_RESTORE(); - - /* Hopefully, we are OK to free the vnet container itself. */ - vnet_data_destroy(vnet); - vnet->vnet_magic_n = 0xdeadbeef; - free(vnet, M_VNET); -} - -void -vnet_foreach(void (*vnet_foreach_fn)(struct vnet *, void *), void *arg) -{ - struct vnet *vnet; - - VNET_LIST_RLOCK(); - LIST_FOREACH(vnet, &vnet_head, vnet_le) - vnet_foreach_fn(vnet, arg); - VNET_LIST_RUNLOCK(); -} - -static void -vnet_init_prelink(void *arg) -{ - - rw_init(&vnet_rwlock, "vnet_rwlock"); - sx_init(&vnet_sxlock, "vnet_sxlock"); - LIST_INIT(&vnet_head); -} -SYSINIT(vnet_init_prelink, SI_SUB_VNET_PRELINK, SI_ORDER_FIRST, - vnet_init_prelink, NULL); - -static void -vnet0_init(void *arg) -{ - - /* - * We MUST clear curvnet in vi_init_done() before going SMP, - * otherwise CURVNET_SET() macros would scream about unnecessary - * curvnet recursions. - */ - curvnet = prison0.pr_vnet = vnet0 = vnet_alloc(); -} -SYSINIT(vnet0_init, SI_SUB_VNET, SI_ORDER_FIRST, vnet0_init, NULL); - -static void -vnet_init_done(void *unused) -{ - - curvnet = NULL; -} - -SYSINIT(vnet_init_done, SI_SUB_VNET_DONE, SI_ORDER_FIRST, vnet_init_done, - NULL); - -#ifdef DDB -DB_SHOW_COMMAND(vnets, db_show_vnets) -{ - VNET_ITERATOR_DECL(vnet_iter); - -#if SIZE_MAX == UINT32_MAX /* 32-bit arch */ - db_printf(" vnet ifs socks\n"); -#else /* 64-bit arch, most probaly... */ - db_printf(" vnet ifs socks\n"); -#endif - VNET_FOREACH(vnet_iter) { - db_printf("%p %3d %5d\n", vnet_iter, vnet_iter->vnet_ifcnt, - vnet_iter->vnet_sockcnt); - } -} -#endif diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index c29ecc6..717ef3e 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -48,10 +48,10 @@ __FBSDID("$FreeBSD$"); #include <sys/stat.h> #include <sys/uio.h> #include <sys/ucred.h> -#include <sys/vimage.h> #include <net/if.h> #include <net/route.h> +#include <net/vnet.h> #include <security/mac/mac_framework.h> diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index dd0602e..257e9fa 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -43,7 +43,9 @@ __FBSDID("$FreeBSD$"); #include <sys/mutex.h> #include <sys/socketvar.h> #include <sys/systm.h> -#include <sys/vimage.h> + +#include <net/vnet.h> + #include <vm/uma.h> /* diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 29b400c..2f4dd92 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -129,7 +129,8 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <sys/uio.h> #include <sys/jail.h> -#include <sys/vimage.h> + +#include <net/vnet.h> #include <security/mac/mac_framework.h> diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 21ee53d..9717679 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -64,12 +64,13 @@ __FBSDID("$FreeBSD$"); #include <sys/syscallsubr.h> #include <sys/sysctl.h> #include <sys/uio.h> -#include <sys/vimage.h> #include <sys/vnode.h> #ifdef KTRACE #include <sys/ktrace.h> #endif +#include <net/vnet.h> + #include <security/audit/audit.h> #include <security/mac/mac_framework.h> diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index cfaf47f..e002b2a 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -88,7 +88,8 @@ __FBSDID("$FreeBSD$"); #include <sys/un.h> #include <sys/unpcb.h> #include <sys/vnode.h> -#include <sys/vimage.h> + +#include <net/vnet.h> #ifdef DDB #include <ddb/ddb.h> |