diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-08-01 21:54:15 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-08-01 21:54:15 +0000 |
commit | 648ff244308cdbfdfbafe6cae0d808d8ee29cb4b (patch) | |
tree | 58f25081dd4f020d6ef4ddca19dec5bc30b7c940 /sys/net/vnet.c | |
parent | e3917e768dd62864bffbab302c81220b6903a864 (diff) | |
download | FreeBSD-src-648ff244308cdbfdfbafe6cae0d808d8ee29cb4b.zip FreeBSD-src-648ff244308cdbfdfbafe6cae0d808d8ee29cb4b.tar.gz |
Make the vnet alloc/destroy paths a bit easier to followg by merging
vnet_data_init/vnet_data_destroy into vnet_alloc/vnet_destroy.
Reviewed by: bz, zec
Approved by: re (vimage blanket)
Diffstat (limited to 'sys/net/vnet.c')
-rw-r--r-- | sys/net/vnet.c | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/sys/net/vnet.c b/sys/net/vnet.c index a7b23b1..f5d336a 100644 --- a/sys/net/vnet.c +++ b/sys/net/vnet.c @@ -211,7 +211,20 @@ vnet_alloc(void) vnet = malloc(sizeof(struct vnet), M_VNET, M_WAITOK | M_ZERO); vnet->vnet_magic_n = VNET_MAGIC_N; - vnet_data_init(vnet); + + /* + * Allocate storage for virtualized global variables and copy in + * initial values form our 'master' copy. + */ + vnet->vnet_data_mem = malloc(VNET_SIZE, M_VNET_DATA, M_WAITOK); + memcpy(vnet->vnet_data_mem, (void *)VNET_START, VNET_BYTES); + + /* + * All use of vnet-specific data will immediately subtract VNET_START + * from the base memory pointer, so pre-calculate that now to avoid + * it on each use. + */ + vnet->vnet_data_base = (uintptr_t)vnet->vnet_data_mem - VNET_START; /* Initialize / attach vnet module instances. */ CURVNET_SET_QUIET(vnet); @@ -255,8 +268,12 @@ vnet_destroy(struct vnet *vnet) CURVNET_RESTORE(); - /* Hopefully, we are OK to free the vnet container itself. */ - vnet_data_destroy(vnet); + /* + * Release storage for the virtual network stack instance. + */ + free(vnet->vnet_data_mem, M_VNET_DATA); + vnet->vnet_data_mem = NULL; + vnet->vnet_data_base = 0; vnet->vnet_magic_n = 0xdeadbeef; free(vnet, M_VNET); } @@ -299,37 +316,6 @@ SYSINIT(vnet_init_done, SI_SUB_VNET_DONE, SI_ORDER_FIRST, vnet_init_done, NULL); /* - * Allocate storage for virtualized global variables in a new virtual network - * stack instance, and copy in initial values from our 'master' copy. - */ -void -vnet_data_init(struct vnet *vnet) -{ - - vnet->vnet_data_mem = malloc(VNET_SIZE, M_VNET_DATA, M_WAITOK); - memcpy(vnet->vnet_data_mem, (void *)VNET_START, VNET_BYTES); - - /* - * All use of vnet-specific data will immediately subtract VNET_START - * from the base memory pointer, so pre-calculate that now to avoid - * it on each use. - */ - vnet->vnet_data_base = (uintptr_t)vnet->vnet_data_mem - VNET_START; -} - -/* - * Release storage for a virtual network stack instance. - */ -void -vnet_data_destroy(struct vnet *vnet) -{ - - free(vnet->vnet_data_mem, M_VNET_DATA); - vnet->vnet_data_mem = NULL; - vnet->vnet_data_base = 0; -} - -/* * Once on boot, initialize the modspace freelist to entirely cover modspace. */ static void |