PERFORCE change 161227 for review

Marko Zec zec at FreeBSD.org
Tue Apr 28 08:43:24 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=161227

Change 161227 by zec at 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 <sys/proc.h>
 #include <sys/queue.h>
 
 #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)


More information about the p4-projects mailing list