Date: Mon, 27 Apr 2009 07:46:15 GMT From: Marko Zec <zec@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 161161 for review Message-ID: <200904270746.n3R7kFjr012015@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=161161 Change 161161 by zec@zec_amdx2 on 2009/04/27 07:45:47 Integrate vc2 -> vc. vc and vc2 are equal at this point. Affected files ... .. //depot/projects/vimage-commit/src/sys/kern/kern_mib.c#10 integrate .. //depot/projects/vimage-commit/src/sys/kern/kern_sysctl.c#7 integrate .. //depot/projects/vimage-commit/src/sys/kern/kern_vimage.c#11 integrate .. //depot/projects/vimage-commit/src/sys/kern/uipc_socket.c#9 integrate .. //depot/projects/vimage-commit/src/sys/net/if.c#21 integrate .. //depot/projects/vimage-commit/src/sys/net/if_gif.c#13 integrate .. //depot/projects/vimage-commit/src/sys/net/if_mib.c#11 integrate .. //depot/projects/vimage-commit/src/sys/net/if_var.h#13 integrate .. //depot/projects/vimage-commit/src/sys/netinet/accf_http.c#3 integrate .. //depot/projects/vimage-commit/src/sys/netinet/igmp.c#17 integrate .. //depot/projects/vimage-commit/src/sys/netinet/in_pcb.c#14 integrate .. //depot/projects/vimage-commit/src/sys/netinet/in_pcb.h#11 integrate .. //depot/projects/vimage-commit/src/sys/netinet/ip_divert.c#13 integrate .. //depot/projects/vimage-commit/src/sys/netinet/ip_input.c#16 integrate .. //depot/projects/vimage-commit/src/sys/netinet/raw_ip.c#14 integrate .. //depot/projects/vimage-commit/src/sys/netinet/tcp_subr.c#19 integrate .. //depot/projects/vimage-commit/src/sys/netinet/tcp_syncache.c#18 integrate .. //depot/projects/vimage-commit/src/sys/netinet/tcp_syncache.h#9 integrate .. //depot/projects/vimage-commit/src/sys/netinet/tcp_var.h#10 integrate .. //depot/projects/vimage-commit/src/sys/netinet/udp_usrreq.c#15 integrate .. //depot/projects/vimage-commit/src/sys/netinet6/in6_proto.c#9 integrate .. //depot/projects/vimage-commit/src/sys/netinet6/ip6_input.c#15 integrate .. //depot/projects/vimage-commit/src/sys/netinet6/nd6.c#14 integrate .. //depot/projects/vimage-commit/src/sys/netipsec/ipsec.c#17 integrate .. //depot/projects/vimage-commit/src/sys/sys/socketvar.h#6 integrate .. //depot/projects/vimage-commit/src/sys/sys/sysctl.h#9 integrate .. //depot/projects/vimage-commit/src/sys/sys/vimage.h#15 integrate Differences ... ==== //depot/projects/vimage-commit/src/sys/kern/kern_mib.c#10 (text+ko) ==== @@ -208,9 +208,8 @@ SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD, machine_arch, 0, "System architecture"); -#ifndef VIMAGE +/* should become #ifndef VIMAGE */ char hostname[MAXHOSTNAMELEN]; -#endif /* * This mutex is used to protect the hostname and domainname variables, and @@ -349,9 +348,8 @@ 0, 0, sysctl_kern_config, "", "Kernel configuration file"); #endif -#ifndef VIMAGE +/* should become #ifndef VIMAGE */ char domainname[MAXHOSTNAMELEN]; /* Protected by hostname_mtx. */ -#endif static int sysctl_domainname(SYSCTL_HANDLER_ARGS) ==== //depot/projects/vimage-commit/src/sys/kern/kern_sysctl.c#7 (text+ko) ==== @@ -934,7 +934,31 @@ return (error); } +#ifdef VIMAGE +int +sysctl_handle_v_int(SYSCTL_HANDLER_ARGS) +{ + int tmpout, error = 0; + + SYSCTL_RESOLVE_V_ARG1(); + + /* + * Attempt to get a coherent snapshot by making a copy of the data. + */ + tmpout = *(int *)arg1; + error = SYSCTL_OUT(req, &tmpout, sizeof(int)); + if (error || !req->newptr) + return (error); + + if (!arg1) + error = EPERM; + else + error = SYSCTL_IN(req, arg1, sizeof(int)); + return (error); +} +#endif + /* * Based on on sysctl_handle_int() convert milliseconds into ticks. */ @@ -944,7 +968,9 @@ { int error, s, tt; - tt = *(int *)oidp->oid_arg1; + SYSCTL_RESOLVE_V_ARG1(); + + tt = *(int *)arg1; s = (int)((int64_t)tt * 1000 / hz); error = sysctl_handle_int(oidp, &s, 0, req); @@ -955,7 +981,7 @@ if (tt < 1) return (EINVAL); - *(int *)oidp->oid_arg1 = tt; + *(int *)arg1 = tt; return (0); } @@ -1069,6 +1095,47 @@ return (error); } +#ifdef VIMAGE +int +sysctl_handle_v_string(SYSCTL_HANDLER_ARGS) +{ + int error=0; + char *tmparg; + size_t outlen; + + SYSCTL_RESOLVE_V_ARG1(); + + /* + * Attempt to get a coherent snapshot by copying to a + * temporary kernel buffer. + */ +retry: + outlen = strlen((char *)arg1)+1; + tmparg = malloc(outlen, M_SYSCTLTMP, M_WAITOK); + + if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) { + free(tmparg, M_SYSCTLTMP); + goto retry; + } + + error = SYSCTL_OUT(req, tmparg, outlen); + free(tmparg, M_SYSCTLTMP); + + if (error || !req->newptr) + return (error); + + if ((req->newlen - req->newidx) >= arg2) { + error = EINVAL; + } else { + arg2 = (req->newlen - req->newidx); + error = SYSCTL_IN(req, arg1, arg2); + ((char *)arg1)[arg2] = '\0'; + } + + return (error); +} +#endif + /* * Handle any kind of opaque data. * arg1 points to it, arg2 is the size. @@ -1106,6 +1173,35 @@ return (error); } +#ifdef VIMAGE +int +sysctl_handle_v_opaque(SYSCTL_HANDLER_ARGS) +{ + int error, tries; + u_int generation; + struct sysctl_req req2; + + SYSCTL_RESOLVE_V_ARG1(); + + tries = 0; + req2 = *req; +retry: + generation = curthread->td_generation; + error = SYSCTL_OUT(req, arg1, arg2); + if (error) + return (error); + tries++; + if (generation != curthread->td_generation && tries < 3) { + *req = req2; + goto retry; + } + + error = SYSCTL_IN(req, arg1, arg2); + + return (error); +} +#endif + /* * Transfer functions to/from kernel space. * XXX: rather untested at this point ==== //depot/projects/vimage-commit/src/sys/kern/kern_vimage.c#11 (text+ko) ==== @@ -42,6 +42,7 @@ #ifndef VIMAGE_GLOBALS MALLOC_DEFINE(M_VIMAGE, "vimage", "vimage resource container"); +MALLOC_DEFINE(M_VNET, "vnet", "network stack control block"); static TAILQ_HEAD(vnet_modlink_head, vnet_modlink) vnet_modlink_head; static TAILQ_HEAD(vnet_modpending_head, vnet_modlink) vnet_modpending_head; @@ -49,6 +50,12 @@ static int vnet_mod_constructor(struct vnet_modlink *); static int vnet_mod_destructor(struct vnet_modlink *); +#ifdef VIMAGE +/* curvnet should be thread-local - this is only a temporary step */ +struct vnet *curvnet; +struct vnet_list_head vnet_head; +#endif + void vnet_mod_register(const struct vnet_modinfo *vmi) { @@ -263,7 +270,13 @@ for (mapentry = vml->vml_modinfo->vmi_symmap; mapentry->name != NULL; mapentry++) { if (strcmp(symstr, mapentry->name) == 0) { - lookup->symvalue = (u_long) mapentry->base; +#ifdef VIMAGE + lookup->symvalue = + (u_long) curvnet->mod_data[vml->vml_modinfo->vmi_id]; + lookup->symvalue += mapentry->offset; +#else + lookup->symvalue = (u_long) mapentry->offset; +#endif lookup->symsize = mapentry->size; return (0); } @@ -275,9 +288,23 @@ static void vi_init(void *unused) { +#ifdef VIMAGE + struct vnet *vnet; +#endif TAILQ_INIT(&vnet_modlink_head); TAILQ_INIT(&vnet_modpending_head); + +#ifdef VIMAGE + LIST_INIT(&vnet_head); + + vnet = malloc(sizeof(struct vnet), M_VNET, M_NOWAIT | M_ZERO); + if (vnet == NULL) + panic("vi_alloc: malloc failed"); + LIST_INSERT_HEAD(&vnet_head, vnet, vnet_le); + + curvnet = LIST_FIRST(&vnet_head); +#endif } static void ==== //depot/projects/vimage-commit/src/sys/kern/uipc_socket.c#9 (text+ko) ==== @@ -130,6 +130,7 @@ #include <sys/sysctl.h> #include <sys/uio.h> #include <sys/jail.h> +#include <sys/vimage.h> #include <security/mac/mac_framework.h> @@ -284,6 +285,9 @@ mtx_lock(&so_global_mtx); so->so_gencnt = ++so_gencnt; ++numopensockets; +#ifdef VIMAGE + so->so_vnet = curvnet; +#endif mtx_unlock(&so_global_mtx); return (so); } ==== //depot/projects/vimage-commit/src/sys/net/if.c#21 (text+ko) ==== @@ -186,6 +186,7 @@ static const vnet_modinfo_t vnet_net_modinfo = { .vmi_id = VNET_MOD_NET, .vmi_name = "net", + .vmi_size = sizeof(struct vnet_net), .vmi_symmap = vnet_net_symmap, .vmi_iattach = vnet_net_iattach }; @@ -545,6 +546,7 @@ static void if_free_internal(struct ifnet *ifp) { + INIT_VNET_NET(ifp->if_vnet); KASSERT((ifp->if_flags & IFF_DYING), ("if_free_internal: interface not dying")); @@ -582,7 +584,6 @@ void if_free_type(struct ifnet *ifp, u_char type) { - INIT_VNET_NET(curvnet); /* ifp->if_vnet can be NULL here ! */ KASSERT(ifp->if_alloctype == type, ("if_free_type: type (%d) != alloctype (%d)", type, @@ -673,6 +674,10 @@ panic ("%s: BUG: if_attach called without if_alloc'd input()\n", ifp->if_xname); +#ifdef VIMAGE + ifp->if_vnet = curvnet; +#endif + if_addgroup(ifp, IFG_ALL); getmicrotime(&ifp->if_lastchange); @@ -978,6 +983,9 @@ } IF_AFDATA_UNLOCK(ifp); ifq_detach(&ifp->if_snd); +#ifdef VIMAGE + ifp->if_vnet = NULL; +#endif splx(s); } ==== //depot/projects/vimage-commit/src/sys/net/if_gif.c#13 (text+ko) ==== @@ -127,6 +127,7 @@ static const vnet_modinfo_t vnet_gif_modinfo = { .vmi_id = VNET_MOD_GIF, .vmi_name = "gif", + .vmi_size = sizeof(struct vnet_gif), .vmi_dependson = VNET_MOD_NET, .vmi_iattach = vnet_gif_iattach }; @@ -303,8 +304,10 @@ if_clone_detach(&gif_cloner); mtx_destroy(&gif_mtx); #ifdef INET6 +#ifndef VIMAGE V_ip6_gif_hlim = 0; /* XXX -> vnet_gif_idetach() */ #endif +#endif break; default: return EOPNOTSUPP; ==== //depot/projects/vimage-commit/src/sys/net/if_mib.c#11 (text+ko) ==== @@ -77,7 +77,6 @@ static int sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ { - INIT_VNET_NET(curvnet); int *name = (int *)arg1; int error; u_int namelen = arg2; ==== //depot/projects/vimage-commit/src/sys/net/if_var.h#13 (text+ko) ==== @@ -117,6 +117,7 @@ struct ifnet { void *if_softc; /* pointer to driver state */ void *if_l2com; /* pointer to protocol bits */ + struct vnet *if_vnet; /* pointer to vnet */ TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ char if_xname[IFNAMSIZ]; /* external name (name + unit) */ const char *if_dname; /* driver name */ ==== //depot/projects/vimage-commit/src/sys/netinet/accf_http.c#3 (text+ko) ==== ==== //depot/projects/vimage-commit/src/sys/netinet/igmp.c#17 (text+ko) ==== ==== //depot/projects/vimage-commit/src/sys/netinet/in_pcb.c#14 (text+ko) ==== @@ -126,7 +126,9 @@ INIT_VNET_INET(curvnet); int error; - error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req); + SYSCTL_RESOLVE_V_ARG1(); + + error = sysctl_handle_int(oidp, arg1, arg2, req); if (error == 0) { RANGECHK(V_ipport_lowfirstauto, 1, IPPORT_RESERVED - 1); RANGECHK(V_ipport_lowlastauto, 1, IPPORT_RESERVED - 1); ==== //depot/projects/vimage-commit/src/sys/netinet/in_pcb.h#11 (text+ko) ==== @@ -224,6 +224,8 @@ #define in6p_icmp6filt inp_depend6.inp6_icmp6filt #define in6p_cksum inp_depend6.inp6_cksum +#define inp_vnet inp_pcbinfo->ipi_vnet + /* * The range of the generation count, as used in this implementation, is 9e19. * We would have to create 300 billion connections per second for this number @@ -301,8 +303,12 @@ struct rwlock ipi_lock; /* - * vimage 1 - * general use 1 + * Pointer to network stack instance + */ + struct vnet *ipi_vnet; + + /* + * general use 2 */ void *ipi_pspare[2]; }; ==== //depot/projects/vimage-commit/src/sys/netinet/ip_divert.c#13 (text+ko) ==== @@ -162,6 +162,9 @@ INP_INFO_LOCK_INIT(&V_divcbinfo, "div"); LIST_INIT(&V_divcb); V_divcbinfo.ipi_listhead = &V_divcb; +#ifdef VIMAGE + V_divcbinfo.ipi_vnet = curvnet; +#endif /* * XXX We don't use the hash list for divert IP, but it's easier * to allocate a one entry hash list than it is to check all ==== //depot/projects/vimage-commit/src/sys/netinet/ip_input.c#16 (text+ko) ==== @@ -237,6 +237,7 @@ static const vnet_modinfo_t vnet_inet_modinfo = { .vmi_id = VNET_MOD_INET, .vmi_name = "inet", + .vmi_size = sizeof(struct vnet_inet) }; static void vnet_inet_register() ==== //depot/projects/vimage-commit/src/sys/netinet/raw_ip.c#14 (text+ko) ==== @@ -187,6 +187,9 @@ INP_INFO_LOCK_INIT(&V_ripcbinfo, "rip"); LIST_INIT(&V_ripcb); +#ifdef VIMAGE + V_ripcbinfo.ipi_vnet = curvnet; +#endif V_ripcbinfo.ipi_listhead = &V_ripcb; V_ripcbinfo.ipi_hashbase = hashinit(INP_PCBHASH_RAW_SIZE, M_PCB, &V_ripcbinfo.ipi_hashmask); ==== //depot/projects/vimage-commit/src/sys/netinet/tcp_subr.c#19 (text+ko) ==== @@ -359,6 +359,9 @@ INP_INFO_LOCK_INIT(&V_tcbinfo, "tcp"); LIST_INIT(&V_tcb); +#ifdef VIMAGE + V_tcbinfo.ipi_vnet = curvnet; +#endif V_tcbinfo.ipi_listhead = &V_tcb; hashsize = TCBHASHSIZE; TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize); @@ -703,6 +706,9 @@ if (tm == NULL) return (NULL); tp = &tm->tcb; +#ifdef VIMAGE + tp->t_vnet = inp->inp_vnet; +#endif tp->t_timers = &tm->tt; /* LIST_INIT(&tp->t_segq); */ /* XXX covered by M_ZERO */ tp->t_maxseg = tp->t_maxopd = ==== //depot/projects/vimage-commit/src/sys/netinet/tcp_syncache.c#18 (text+ko) ==== @@ -259,6 +259,9 @@ /* Initialize the hash buckets. */ for (i = 0; i < V_tcp_syncache.hashsize; i++) { +#ifdef VIMAGE + V_tcp_syncache.hashbase[i].sch_vnet = curvnet; +#endif TAILQ_INIT(&V_tcp_syncache.hashbase[i].sch_bucket); mtx_init(&V_tcp_syncache.hashbase[i].sch_mtx, "tcp_sc_head", NULL, MTX_DEF); ==== //depot/projects/vimage-commit/src/sys/netinet/tcp_syncache.h#9 (text+ko) ==== @@ -96,6 +96,7 @@ #define SYNCOOKIE_LIFETIME 16 /* seconds */ struct syncache_head { + struct vnet *sch_vnet; struct mtx sch_mtx; TAILQ_HEAD(sch_head, syncache) sch_bucket; struct callout sch_timer; ==== //depot/projects/vimage-commit/src/sys/netinet/tcp_var.h#10 (text+ko) ==== @@ -35,6 +35,8 @@ #include <netinet/tcp.h> +struct vnet; + /* * Kernel variables for tcp. */ @@ -186,7 +188,8 @@ int t_rttlow; /* smallest observerved RTT */ u_int32_t rfbuf_ts; /* recv buffer autoscaling timestamp */ int rfbuf_cnt; /* recv buffer autoscaling byte count */ - void *t_pspare[3]; /* toe usrreqs / toepcb * / congestion algo / vimage / 1 general use */ + struct vnet *t_vnet; /* pointer to parent vnet */ + void *t_pspare[2]; /* toe usrreqs / toepcb * / congestion algo / 1 general use */ struct toe_usrreqs *t_tu; /* offload operations vector */ void *t_toe; /* TOE pcb pointer */ int t_bytes_acked; /* # bytes acked during current RTT */ ==== //depot/projects/vimage-commit/src/sys/netinet/udp_usrreq.c#15 (text+ko) ==== @@ -179,6 +179,9 @@ INP_INFO_LOCK_INIT(&V_udbinfo, "udp"); LIST_INIT(&V_udb); +#ifdef VIMAGE + V_udbinfo.ipi_vnet = curvnet; +#endif V_udbinfo.ipi_listhead = &V_udb; V_udbinfo.ipi_hashbase = hashinit(UDBHASHSIZE, M_PCB, &V_udbinfo.ipi_hashmask); ==== //depot/projects/vimage-commit/src/sys/netinet6/in6_proto.c#9 (text+ko) ==== @@ -446,6 +446,8 @@ int error = 0; int old; + SYSCTL_RESOLVE_V_ARG1(); + error = SYSCTL_OUT(req, arg1, sizeof(int)); if (error || !req->newptr) return (error); @@ -466,6 +468,8 @@ int error = 0; int old; + SYSCTL_RESOLVE_V_ARG1(); + error = SYSCTL_OUT(req, arg1, sizeof(int)); if (error || !req->newptr) return (error); ==== //depot/projects/vimage-commit/src/sys/netinet6/ip6_input.c#15 (text+ko) ==== @@ -161,6 +161,7 @@ static const vnet_modinfo_t vnet_inet6_modinfo = { .vmi_id = VNET_MOD_INET6, .vmi_name = "inet6", + .vmi_size = sizeof(struct vnet_inet6), .vmi_dependson = VNET_MOD_INET /* XXX revisit - TCP/UDP needs this? */ }; ==== //depot/projects/vimage-commit/src/sys/netinet6/nd6.c#14 (text+ko) ==== @@ -191,7 +191,7 @@ /* start timer */ callout_init(&V_nd6_slowtimo_ch, 0); callout_reset(&V_nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, - nd6_slowtimo, NULL); + nd6_slowtimo, curvnet); nd6_init_done = 1; @@ -592,8 +592,8 @@ void nd6_timer(void *arg) { - CURVNET_SET_QUIET((struct vnet *) arg); - INIT_VNET_INET6((struct vnet *) arg); + CURVNET_SET_QUIET((struct vnet *) arg); /* XXX revisit! */ + INIT_VNET_INET6(curvnet); /* XXX revisit! */ int s; struct nd_defrouter *dr; struct nd_prefix *pr; @@ -872,7 +872,6 @@ struct llentry * nd6_lookup(struct in6_addr *addr6, int flags, struct ifnet *ifp) { - INIT_VNET_INET6(curvnet); struct sockaddr_in6 sin6; struct llentry *ln; int llflags = 0; @@ -1669,7 +1668,7 @@ struct ifnet *ifp; callout_reset(&V_nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, - nd6_slowtimo, NULL); + nd6_slowtimo, curvnet); IFNET_RLOCK(); for (ifp = TAILQ_FIRST(&V_ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) { ==== //depot/projects/vimage-commit/src/sys/netipsec/ipsec.c#17 (text+ko) ==== @@ -248,6 +248,7 @@ static const vnet_modinfo_t vnet_ipsec_modinfo = { .vmi_id = VNET_MOD_IPSEC, .vmi_name = "ipsec", + .vmi_size = sizeof(struct vnet_ipsec), .vmi_dependson = VNET_MOD_INET, /* XXX revisit - INET6 ? */ .vmi_iattach = ipsec_iattach }; ==== //depot/projects/vimage-commit/src/sys/sys/socketvar.h#6 (text+ko) ==== @@ -45,6 +45,8 @@ #include <sys/sockopt.h> #endif +struct vnet; + /* * Kernel structure per socket. * Contains send and receive buffer queues, @@ -72,6 +74,7 @@ short so_state; /* (b) internal state flags SS_* */ int so_qstate; /* (e) internal state flags SQ_* */ void *so_pcb; /* protocol control block */ + struct vnet *so_vnet; /* network stack instance */ struct protosw *so_proto; /* (a) protocol handle */ /* * Variables for connection queuing. ==== //depot/projects/vimage-commit/src/sys/sys/sysctl.h#9 (text+ko) ==== @@ -163,6 +163,8 @@ const char *oid_fmt; int oid_refcnt; const char *oid_descr; + short oid_v_subs; + short oid_v_mod; }; #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) @@ -440,6 +442,29 @@ #define FEATURE(name, desc) \ SYSCTL_INT(_kern_features, OID_AUTO, name, CTLFLAG_RD, 0, 1, desc) +/* + * Resolve void *arg1 in a proper virtualization container. + */ +#ifdef VIMAGE +#define SYSCTL_RESOLVE_V_ARG1() do { \ + char *cp; \ + switch (oidp->oid_v_subs) { \ + case V_GLOBAL: \ + /* do nothing - this is NOT a virtualized variable! */ \ + break; \ + case V_NET: \ + cp = (char *) \ + TD_TO_VNET(curthread)->mod_data[oidp->oid_v_mod]; \ + arg1 = cp + (size_t) arg1; \ + break; \ + default: \ + panic("unsupported module id %d", oidp->oid_v_subs); \ + } \ +} while (0) +#else +#define SYSCTL_RESOLVE_V_ARG1() +#endif + #endif /* _KERNEL */ /* ==== //depot/projects/vimage-commit/src/sys/sys/vimage.h#15 (text+ko) ==== @@ -39,6 +39,10 @@ #error "You cannot have both option VIMAGE and option VIMAGE_GLOBALS!" #endif +#ifdef INVARIANTS +#define VNET_DEBUG +#endif + typedef int vnet_attach_fn(const void *); typedef int vnet_detach_fn(const void *); @@ -48,8 +52,8 @@ struct vnet_symmap { char *name; - void *base; - size_t size; + size_t offset; + size_t size; }; typedef struct vnet_symmap vnet_symmap_t; @@ -59,7 +63,7 @@ char *vmi_name; vnet_attach_fn *vmi_iattach; vnet_detach_fn *vmi_idetach; - size_t vmi_struct_size; + size_t vmi_size; struct vnet_symmap *vmi_symmap; }; typedef struct vnet_modinfo vnet_modinfo_t; @@ -71,12 +75,6 @@ const char *vml_iname; }; -#define VNET_SYMMAP(mod, name) \ - { #name, &(vnet_ ## mod ## _0._ ## name), \ - sizeof(vnet_ ## mod ## _0._ ## name) } - -#define VNET_SYMMAP_END { NULL, 0 } - /* stateful modules */ #define VNET_MOD_NET 0 /* MUST be 0 - implicit dependency */ #define VNET_MOD_NETGRAPH 1 @@ -108,7 +106,11 @@ #define VNET_MOD_DYNAMIC_START 32 #define VNET_MOD_MAX 64 -/* Sysctl virtualization macros need these name mappings bellow */ +/* Major module IDs for vimage sysctl virtualization */ +#define V_GLOBAL 0 /* global variable - no indirection */ +#define V_NET 1 + +/* Name mappings for minor module IDs in vimage sysctl virtualization */ #define V_MOD_vnet_net VNET_MOD_NET #define V_MOD_vnet_netgraph VNET_MOD_NETGRAPH #define V_MOD_vnet_inet VNET_MOD_INET @@ -130,27 +132,78 @@ #define VSYM(base, sym) (sym) #else #ifdef VIMAGE -#error "No option VIMAGE yet!" +#define VSYM(base, sym) ((base)->_ ## sym) #else #define VSYM(base, sym) (base ## _0._ ## sym) #endif #endif +#ifndef VIMAGE_GLOBALS +#ifdef VIMAGE +#define VNET_SYMMAP(mod, name) \ + { #name, offsetof(struct vnet_ ## mod, _ ## name), \ + sizeof(((struct vnet_ ## mod *) curthread)->_ ## name) } +#else +#define VNET_SYMMAP(mod, name) \ + { #name, (size_t) &(vnet_ ## mod ## _0._ ## name), \ + sizeof(vnet_ ## mod ## _0._ ## name) } +#endif +#define VNET_SYMMAP_END { NULL, 0 } +#endif /* !VIMAGE_GLOBALS */ + +#ifdef VIMAGE +struct vnet { + void *mod_data[VNET_MOD_MAX]; + LIST_ENTRY(vnet) vnet_le; /* all vnets list */ + u_int vnet_magic_n; +}; +#endif + +#ifdef VIMAGE +extern struct vnet *curvnet; /* XXX will become thread-local soon */ +#else +#define curvnet NULL +#endif + +#ifdef VIMAGE +#ifdef VNET_DEBUG +#define INIT_FROM_VNET(vnet, modindex, modtype, sym) \ + if (vnet == NULL || vnet != curvnet) \ + panic("in %s:%d %s()\n vnet=%p curvnet=%p", \ + __FILE__, __LINE__, __FUNCTION__, \ + vnet, curvnet); \ + modtype *sym = (vnet)->mod_data[modindex]; +#else /* !VNET_DEBUG */ +#define INIT_FROM_VNET(vnet, modindex, modtype, sym) \ + modtype *sym = (vnet)->mod_data[modindex]; +#endif /* !VNET_DEBUG */ +#else /* !VIMAGE */ +#define INIT_FROM_VNET(vnet, modindex, modtype, sym) +#endif + +#ifdef VIMAGE +LIST_HEAD(vnet_list_head, vnet); +extern struct vnet_list_head vnet_head; +#define VNET_ITERATOR_DECL(arg) struct vnet *arg; +#define VNET_FOREACH(arg) LIST_FOREACH(arg, &vnet_head, vnet_le) +#else +#define VNET_ITERATOR_DECL(arg) +#define VNET_FOREACH(arg) +#endif + +#define TD_TO_VNET(td) curvnet + /* Non-VIMAGE null-macros */ #define IS_DEFAULT_VNET(arg) 1 #define CURVNET_SET(arg) #define CURVNET_SET_QUIET(arg) #define CURVNET_RESTORE() #define VNET_ASSERT(condition) -#define INIT_FROM_VNET(vnet, modindex, modtype, sym) -#define VNET_ITERATOR_DECL(arg) -#define VNET_FOREACH(arg) #define VNET_LIST_RLOCK() #define VNET_LIST_RUNLOCK() #define INIT_VPROCG(arg) #define INIT_VCPU(arg) #define TD_TO_VIMAGE(td) -#define TD_TO_VNET(td) #define TD_TO_VPROCG(td) #define TD_TO_VCPU(td) #define P_TO_VIMAGE(p)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904270746.n3R7kFjr012015>