From owner-p4-projects@FreeBSD.ORG Tue Apr 28 08:43:23 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B26DA1065672; Tue, 28 Apr 2009 08:43:23 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 72A62106566B for ; Tue, 28 Apr 2009 08:43:23 +0000 (UTC) (envelope-from zec@fer.hr) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 60B078FC13 for ; Tue, 28 Apr 2009 08:43:23 +0000 (UTC) (envelope-from zec@fer.hr) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n3S8hN72036474 for ; Tue, 28 Apr 2009 08:43:23 GMT (envelope-from zec@fer.hr) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n3S8hMLI036472 for perforce@freebsd.org; Tue, 28 Apr 2009 08:43:22 GMT (envelope-from zec@fer.hr) Date: Tue, 28 Apr 2009 08:43:22 GMT Message-Id: <200904280843.n3S8hMLI036472@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@fer.hr using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 161227 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2009 08:43:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=161227 Change 161227 by zec@zec_amdx2 on 2009/04/28 08:43:18 Make curvnet a thread-local variable (actually an alias to curthread->td_vnet), import CURVNET_SET() / CURVNET_RESTORE() infrastructure from vimage branch, and unbreak both GENERIC and VIMAGE builds. Affected files ... .. //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#19 edit .. //depot/projects/vimage-commit2/src/sys/net/bpf.c#13 edit .. //depot/projects/vimage-commit2/src/sys/net/if.c#50 edit .. //depot/projects/vimage-commit2/src/sys/net/if_var.h#19 edit .. //depot/projects/vimage-commit2/src/sys/netinet6/nd6.c#30 edit .. //depot/projects/vimage-commit2/src/sys/nfsclient/nfs_vnops.c#18 edit .. //depot/projects/vimage-commit2/src/sys/sys/vimage.h#44 edit Differences ... ==== //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#19 (text+ko) ==== @@ -51,8 +51,6 @@ 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 ==== //depot/projects/vimage-commit2/src/sys/net/bpf.c#13 (text+ko) ==== @@ -1431,31 +1431,8 @@ struct bpf_if *bp; struct ifnet *theywant; -#define IMUNES_BPF_HACK -#if defined(VIMAGE) && defined(IMUNES_BPF_HACK) - struct vnet *target_vnet = curvnet; - char *c; - - /* Hack to support tapping in foreign vnets */ - c = rindex(ifr->ifr_name, '@'); - if ( c != NULL ) { -printf("bpf_setif: %s\n", c); - struct vimage *target_vimage; - - *c++ = 0; - target_vimage = vimage_by_name(TD_TO_VIMAGE(curthread), c); - if (target_vimage == NULL) - return ENXIO; - target_vnet = target_vimage->v_net; - } - CURVNET_SET_QUIET(target_vnet); -#endif - theywant = ifunit(ifr->ifr_name); if (theywant == NULL || theywant->if_bpf == NULL) { -#if defined(VIMAGE) && defined(IMUNES_BPF_HACK) - CURVNET_RESTORE(); -#endif return (ENXIO); } ==== //depot/projects/vimage-commit2/src/sys/net/if.c#50 (text+ko) ==== @@ -445,7 +445,7 @@ return (0); } -static void +void if_grow(void) { INIT_VNET_NET(curvnet); @@ -584,7 +584,6 @@ void if_free_type(struct ifnet *ifp, u_char type) { - INIT_VNET_NET(ifp->if_vnet); KASSERT(ifp->if_alloctype == type, ("if_free_type: type (%d) != alloctype (%d)", type, ==== //depot/projects/vimage-commit2/src/sys/net/if_var.h#19 (text+ko) ==== @@ -731,7 +731,9 @@ * to call ifnet_byindex() instead if ifnet_byindex_ref(). */ struct ifnet *ifnet_byindex(u_short idx); +struct ifnet *ifnet_byindex_locked(u_short idx); struct ifnet *ifnet_byindex_ref(u_short idx); +void ifnet_setbyindex(u_short idx, struct ifnet *ifp); /* * Given the index, ifaddr_byindex() returns the one and only @@ -755,6 +757,7 @@ struct ifnet* if_alloc(u_char); void if_attach(struct ifnet *); void if_dead(struct ifnet *); +void if_grow(void); int if_delmulti(struct ifnet *, struct sockaddr *); void if_delmulti_ifma(struct ifmultiaddr *); void if_detach(struct ifnet *); ==== //depot/projects/vimage-commit2/src/sys/netinet6/nd6.c#30 (text+ko) ==== @@ -489,6 +489,14 @@ if ((ifp = ((ln->lle_tbl != NULL) ? ln->lle_tbl->llt_ifp : NULL)) == NULL) panic("ln ifp == NULL"); +/* + * XXX XXX XXX XXX XXX + * + * Why the ^%(@)*&%^) is this #define MIN() needed for CURVNET_SET()?!? + * And #define MIN() is in sys/param.h already, which is #included first + * here?!? + */ +#define MIN(a,b) (((a)<(b))?(a):(b)) CURVNET_SET(ifp->if_vnet); INIT_VNET_INET6(curvnet); ==== //depot/projects/vimage-commit2/src/sys/nfsclient/nfs_vnops.c#18 (text+ko) ==== @@ -1522,7 +1522,6 @@ if (v3) { tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED); if (fmode & O_EXCL) { - CURVNET_SET(VFSTONFS(dvp->v_mount)->nm_so->so_vnet); *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE); tl = nfsm_build(u_int32_t *, NFSX_V3CREATEVERF); #ifdef INET @@ -1533,7 +1532,6 @@ #endif *tl++ = create_verf; *tl = ++create_verf; - CURVNET_RESTORE(); } else { *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED); nfsm_v3attrbuild(vap, FALSE); ==== //depot/projects/vimage-commit2/src/sys/sys/vimage.h#44 (text+ko) ==== @@ -33,6 +33,7 @@ #ifndef _SYS_VIMAGE_H_ #define _SYS_VIMAGE_H_ +#include #include #if defined(VIMAGE) && defined(VIMAGE_GLOBALS) @@ -156,17 +157,71 @@ void *mod_data[VNET_MOD_MAX]; LIST_ENTRY(vnet) vnet_le; /* all vnets list */ u_int vnet_magic_n; + u_int ifccnt; + u_int sockcnt; }; #endif #ifdef VIMAGE -extern struct vnet *curvnet; /* XXX will become thread-local soon */ +#define curvnet curthread->td_vnet #else #define curvnet NULL #endif +#define VNET_MAGIC_N 0x3e0d8f29 + #ifdef VIMAGE #ifdef VNET_DEBUG +#define VNET_ASSERT(condition) \ + if (!(condition)) { \ + printf("VNET_ASSERT @ %s:%d %s():\n", \ + __FILE__, __LINE__, __FUNCTION__); \ + panic(#condition); \ + } + +#define CURVNET_SET_QUIET(arg) \ + VNET_ASSERT((arg)->vnet_magic_n == VNET_MAGIC_N); \ + struct vnet *saved_vnet = curvnet; \ + const char *saved_vnet_lpush = curthread->td_vnet_lpush; \ + curvnet = arg; \ + curthread->td_vnet_lpush = __FUNCTION__; + +#define CURVNET_SET_VERBOSE(arg) \ + CURVNET_SET_QUIET(arg) \ + if (saved_vnet) \ + printf("curvnet_set(%p) in %s() on cpu %d, prev %p in %s()\n", curvnet, \ + curthread->td_vnet_lpush, curcpu, \ + saved_vnet, saved_vnet_lpush); + +#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg) + +#define CURVNET_RESTORE() \ + VNET_ASSERT(saved_vnet == NULL || \ + saved_vnet->vnet_magic_n == VNET_MAGIC_N); \ + curvnet = saved_vnet; \ + curthread->td_vnet_lpush = saved_vnet_lpush; +#else /* !VNET_DEBUG */ +#define VNET_ASSERT(condition) + +#define CURVNET_SET(arg) \ + struct vnet *saved_vnet = curvnet; \ + curvnet = arg; + +#define CURVNET_SET_VERBOSE(arg) CURVNET_SET(arg) +#define CURVNET_SET_QUIET(arg) CURVNET_SET(arg) + +#define CURVNET_RESTORE() \ + curvnet = saved_vnet; +#endif /* !VNET_DEBUG */ +#else /* !VIMAGE */ +#define VNET_ASSERT(condition) +#define CURVNET_SET(arg) +#define CURVNET_SET_QUIET(arg) +#define CURVNET_RESTORE() +#endif /* !VIMAGE */ + +#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", \ @@ -195,10 +250,6 @@ /* 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 VNET_LIST_RLOCK() #define VNET_LIST_RUNLOCK() #define INIT_VPROCG(arg)