Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Sep 2008 16:55:59 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 149433 for review
Message-ID:  <200809081655.m88GtxbV000906@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=149433

Change 149433 by zec@zec_tpx32 on 2008/09/08 16:55:34

	First-cut replacement of VNET_ITERLOOP_BEGIN() /
	VNET_ITERLOOP_END() kludges with VNET_FOREACH() constructs
	discussed at freebsd-virtualization@
	
	Needs a bit more testing before merging over to
	vimage-commit2 branch.

Affected files ...

.. //depot/projects/vimage/src/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c#3 edit
.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#66 edit
.. //depot/projects/vimage/src/sys/net/if.c#36 edit
.. //depot/projects/vimage/src/sys/net/if_ef.c#6 edit
.. //depot/projects/vimage/src/sys/net80211/ieee80211_ddb.c#8 edit
.. //depot/projects/vimage/src/sys/netgraph/atm/ng_atm.c#6 edit
.. //depot/projects/vimage/src/sys/netgraph/ng_gif.c#7 edit
.. //depot/projects/vimage/src/sys/netinet/igmp.c#15 edit
.. //depot/projects/vimage/src/sys/netinet/in_pcb.c#29 edit
.. //depot/projects/vimage/src/sys/netinet/in_rmx.c#18 edit
.. //depot/projects/vimage/src/sys/netinet/ip_input.c#32 edit
.. //depot/projects/vimage/src/sys/netinet/tcp_subr.c#47 edit
.. //depot/projects/vimage/src/sys/netinet/tcp_timer.c#20 edit
.. //depot/projects/vimage/src/sys/netinet6/frag6.c#17 edit
.. //depot/projects/vimage/src/sys/netipsec/key.c#20 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#63 edit

Differences ...

==== //depot/projects/vimage/src/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c#3 (text+ko) ====

@@ -218,6 +218,7 @@
 static int
 iwch_init_module(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	int err;
 	struct ifnet *ifp;
 
@@ -239,12 +240,13 @@
 
 	/* Register existing TOE interfaces by walking the ifnet chain */
 	IFNET_RLOCK();
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_NET(curvnet);
-	TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-		(void)ifaddr_event_handler(NULL, ifp);
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);	/* XXX CURVNET_SET_QUIET() ? */
+		INIT_VNET_NET(vnet_iter);
+		TAILQ_FOREACH(ifp, &V_ifnet, if_link)
+			(void)ifaddr_event_handler(NULL, ifp);
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
 	IFNET_RUNLOCK();
 	return 0;
 }

==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#66 (text+ko) ====

@@ -187,13 +187,16 @@
 void
 vnet_mod_complete_registration(struct vnet_modlink *vml)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct vnet_modlink *vml_iter;
 
 	TAILQ_INSERT_TAIL(&vnet_modlink_head, vml, vml_mod_le);
 
-	VNET_ITERLOOP_BEGIN_QUIET();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET_QUIET(vnet_iter);
 		vnet_mod_constructor(vml);
-	VNET_ITERLOOP_END();
+		CURVNET_RESTORE();
+	}
 
 	/* Check for pending modules depending on us */
 	do {
@@ -225,6 +228,7 @@
 vnet_mod_deregister_multi(const struct vnet_modinfo *vmi, void *iarg,
     char *iname)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct vnet_modlink *vml;
 
 	TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le)
@@ -234,9 +238,11 @@
 		panic("cannot deregister unregistered vnet module %s",
 		    vmi->vmi_name);
 
-	VNET_ITERLOOP_BEGIN_QUIET();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET_QUIET(vnet_iter);
 		vnet_mod_destructor(vml);
-	VNET_ITERLOOP_END();
+		CURVNET_RESTORE();
+	}
 
 	TAILQ_REMOVE(&vnet_modlink_head, vml, vml_mod_le);
 	vi_free(vml, M_VIMAGE);
@@ -976,9 +982,11 @@
 
 DB_SHOW_COMMAND(vnets, db_show_vnets)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
+
 	db_printf("      vnet ifs socks");
 	db_printf("        net       inet      inet6      ipsec   netgraph\n");
-	VNET_ITERLOOP_BEGIN_QUIET();
+	VNET_FOREACH(vnet_iter) {
 		db_printf("%p %3d %5d",
 		    vnet_iter, vnet_iter->ifccnt, vnet_iter->sockcnt);
 		db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NET]);
@@ -987,6 +995,6 @@
 		db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_IPSEC]);
 		db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NETGRAPH]);
 		db_printf("\n");
-	VNET_ITERLOOP_END();
+	}
 }
 #endif

==== //depot/projects/vimage/src/sys/net/if.c#36 (text+ko) ====

@@ -1637,19 +1637,24 @@
 static void
 if_slowtimo(void *arg)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ifnet *ifp;
 	int s = splimp();
 
 	IFNET_RLOCK();
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_NET(curvnet);
-	TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-		if (ifp->if_timer == 0 || --ifp->if_timer)
-			continue;
-		if (ifp->if_watchdog)
-			(*ifp->if_watchdog)(ifp);
+	VNET_LIST_REF();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_NET(vnet_iter);
+		TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+			if (ifp->if_timer == 0 || --ifp->if_timer)
+				continue;
+			if (ifp->if_watchdog)
+				(*ifp->if_watchdog)(ifp);
+		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
+	VNET_LIST_UNREF();
 	IFNET_RUNLOCK();
 	splx(s);
 	timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ);

==== //depot/projects/vimage/src/sys/net/if_ef.c#6 (text+ko) ====

@@ -485,46 +485,47 @@
 static int
 ef_load(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ifnet *ifp;
 	struct efnet *efp;
 	struct ef_link *efl = NULL, *efl_temp;
 	int error = 0, d;
 
 	IFNET_RLOCK();
-	{
-		VNET_ITERLOOP_BEGIN_QUIET();
-			INIT_VNET_NET(curvnet);
-			TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-				if (ifp->if_type != IFT_ETHER) continue;
-				EFDEBUG("Found interface %s\n", ifp->if_xname);
-				efl = (struct ef_link*)malloc(sizeof(struct ef_link), 
-				    M_IFADDR, M_WAITOK | M_ZERO);
-				if (efl == NULL) {
-					error = ENOMEM;
-					break;
-				}
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_NET(vnet_iter);
+		TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+			if (ifp->if_type != IFT_ETHER) continue;
+			EFDEBUG("Found interface %s\n", ifp->if_xname);
+			efl = (struct ef_link*)malloc(sizeof(struct ef_link), 
+			    M_IFADDR, M_WAITOK | M_ZERO);
+			if (efl == NULL) {
+				error = ENOMEM;
+				break;
+			}
 
-				efl->el_ifp = ifp;
+			efl->el_ifp = ifp;
 #ifdef ETHER_II
-				error = ef_clone(efl, ETHER_FT_EII);
-				if (error) break;
+			error = ef_clone(efl, ETHER_FT_EII);
+			if (error) break;
 #endif
 #ifdef ETHER_8023
-				error = ef_clone(efl, ETHER_FT_8023);
-				if (error) break;
+			error = ef_clone(efl, ETHER_FT_8023);
+			if (error) break;
 #endif
 #ifdef ETHER_8022
-				error = ef_clone(efl, ETHER_FT_8022);
-				if (error) break;
+			error = ef_clone(efl, ETHER_FT_8022);
+			if (error) break;
 #endif
 #ifdef ETHER_SNAP
-				error = ef_clone(efl, ETHER_FT_SNAP);
-				if (error) break;
+			error = ef_clone(efl, ETHER_FT_SNAP);
+			if (error) break;
 #endif
-				efcount++;
-				SLIST_INSERT_HEAD(&efdev, efl, el_next);
-			}
-		VNET_ITERLOOP_END();
+			efcount++;
+			SLIST_INSERT_HEAD(&efdev, efl, el_next);
+		}
+		CURVNET_RESTORE();
 	}
 	IFNET_RUNLOCK();
 	if (error) {

==== //depot/projects/vimage/src/sys/net80211/ieee80211_ddb.c#8 (text+ko) ====

@@ -184,6 +184,7 @@
 
 DB_SHOW_ALL_COMMAND(vaps, db_show_all_vaps)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	const struct ifnet *ifp;
 	int i, showall = 0;
 
@@ -194,24 +195,25 @@
 			break;
 		}
 
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_NET(vnet_iter);
-	TAILQ_FOREACH(ifp, &V_ifnet, if_list)
-		if (ifp->if_type == IFT_IEEE80211) {
-			const struct ieee80211com *ic = ifp->if_l2com;
+	VNET_FOREACH(vnet_iter) {
+		INIT_VNET_NET(vnet_iter);
+		TAILQ_FOREACH(ifp, &V_ifnet, if_list)
+			if (ifp->if_type == IFT_IEEE80211) {
+				const struct ieee80211com *ic = ifp->if_l2com;
 
-			if (!showall) {
-				const struct ieee80211vap *vap;
-				db_printf("%s: com %p vaps:",
-				    ifp->if_xname, ic);
-				TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
-					db_printf(" %s(%p)",
-					    vap->iv_ifp->if_xname, vap);
-				db_printf("\n");
-			} else
-				_db_show_com(ic, 1, 1, 1);
-		}
-	VNET_ITERLOOP_END();
+				if (!showall) {
+					const struct ieee80211vap *vap;
+					db_printf("%s: com %p vaps:",
+					    ifp->if_xname, ic);
+					TAILQ_FOREACH(vap, &ic->ic_vaps,
+					    iv_next)
+						db_printf(" %s(%p)",
+						    vap->iv_ifp->if_xname, vap);
+					db_printf("\n");
+				} else
+					_db_show_com(ic, 1, 1, 1);
+			}
+	}
 }
 
 static void

==== //depot/projects/vimage/src/sys/netgraph/atm/ng_atm.c#6 (text+ko) ====

@@ -1380,6 +1380,7 @@
 static int
 ng_atm_mod_event(module_t mod, int event, void *data)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ifnet *ifp;
 	int error = 0;
 
@@ -1402,15 +1403,15 @@
 		ng_atm_input_orphan_p = ng_atm_input_orphans;
 		ng_atm_event_p = ng_atm_event;
 
-		{
-		        VNET_ITERLOOP_BEGIN_QUIET();
-        			INIT_VNET_NET(curvnet);
-				/* Create nodes for existing ATM interfaces */
-				TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-					if (ifp->if_type == IFT_ATM)
-						ng_atm_attach(ifp);
-				}
-		        VNET_ITERLOOP_END();
+		VNET_FOREACH(vnet_iter) {
+			CURVNET_SET_QUIET(vnet_iter);
+       			INIT_VNET_NET(vnet_iter);
+			/* Create nodes for existing ATM interfaces */
+			TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+				if (ifp->if_type == IFT_ATM)
+					ng_atm_attach(ifp);
+			}
+			CURVNET_RESTORE();
 		}
 		IFNET_RUNLOCK();
 		break;
@@ -1425,14 +1426,14 @@
 		ng_atm_input_orphan_p = NULL;
 		ng_atm_event_p = NULL;
 
-		{
-		        VNET_ITERLOOP_BEGIN_QUIET();
-        			INIT_VNET_NET(curvnet);
-				TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-					if (ifp->if_type == IFT_ATM)
-						ng_atm_detach(ifp);
-				}
-		        VNET_ITERLOOP_END();
+		VNET_FOREACH(vnet_iter) {
+			CURVNET_SET_QUIET(vnet_iter);
+       			INIT_VNET_NET(vnet_iter);
+			TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+				if (ifp->if_type == IFT_ATM)
+					ng_atm_detach(ifp);
+			}
+			CURVNET_RESTORE();
 		}
 		IFNET_RUNLOCK();
 		break;

==== //depot/projects/vimage/src/sys/netgraph/ng_gif.c#7 (text+ko) ====

@@ -542,6 +542,7 @@
 static int
 ng_gif_mod_event(module_t mod, int event, void *data)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ifnet *ifp;
 	int error = 0;
 	int s;
@@ -562,13 +563,15 @@
 
 		/* Create nodes for any already-existing gif interfaces */
 		IFNET_RLOCK();
-		VNET_ITERLOOP_BEGIN_QUIET();
-		INIT_VNET_NET(curvnet);
-		TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
-			if (ifp->if_type == IFT_GIF)
-				ng_gif_attach(ifp);
+		VNET_FOREACH(vnet_iter) {
+			CURVNET_SET_QUIET(vnet_iter); /* XXX revisit quiet */
+			INIT_VNET_NET(curvnet);
+			TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
+				if (ifp->if_type == IFT_GIF)
+					ng_gif_attach(ifp);
+			}
+			CURVNET_RESTORE();
 		}
-		VNET_ITERLOOP_END();
 		IFNET_RUNLOCK();
 		break;
 

==== //depot/projects/vimage/src/sys/netinet/igmp.c#15 (text+ko) ====

@@ -426,6 +426,7 @@
 void
 igmp_fasttimo(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	register struct in_multi *inm;
 	struct in_multistep step;
 
@@ -439,41 +440,46 @@
 
 	IN_MULTI_LOCK();
 	igmp_timers_are_running = 0;
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(vnet_iter);
-	IN_FIRST_MULTI(step, inm);
-	while (inm != NULL) {
-		if (inm->inm_timer == 0) {
-			/* do nothing */
-		} else if (--inm->inm_timer == 0) {
-			igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
-			inm->inm_state = IGMP_IREPORTEDLAST;
-		} else {
-			igmp_timers_are_running = 1;
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET(vnet_iter);
+		IN_FIRST_MULTI(step, inm);
+		while (inm != NULL) {
+			if (inm->inm_timer == 0) {
+				/* do nothing */
+			} else if (--inm->inm_timer == 0) {
+				igmp_sendpkt(inm, inm->inm_rti->rti_type, 0);
+				inm->inm_state = IGMP_IREPORTEDLAST;
+			} else {
+				igmp_timers_are_running = 1;
+			}
+			IN_NEXT_MULTI(step, inm);
 		}
-		IN_NEXT_MULTI(step, inm);
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
 	IN_MULTI_UNLOCK();
 }
 
 void
 igmp_slowtimo(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct router_info *rti;
 
 	IGMP_PRINTF("[igmp.c,_slowtimo] -- > entering \n");
 	mtx_lock(&igmp_mtx);
-	VNET_ITERLOOP_BEGIN()
-	INIT_VNET_INET(vnet_iter);
-	SLIST_FOREACH(rti, &V_router_info_head, rti_list) {
-		if (rti->rti_type == IGMP_V1_ROUTER) {
-			rti->rti_time++;
-			if (rti->rti_time >= IGMP_AGE_THRESHOLD)
-				rti->rti_type = IGMP_V2_ROUTER;
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET(vnet_iter);
+		SLIST_FOREACH(rti, &V_router_info_head, rti_list) {
+			if (rti->rti_type == IGMP_V1_ROUTER) {
+				rti->rti_time++;
+				if (rti->rti_time >= IGMP_AGE_THRESHOLD)
+					rti->rti_type = IGMP_V2_ROUTER;
+			}
 		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END()
 	mtx_unlock(&igmp_mtx);
 	IGMP_PRINTF("[igmp.c,_slowtimo] -- > exiting \n");
 }

==== //depot/projects/vimage/src/sys/netinet/in_pcb.c#29 (text+ko) ====

@@ -1221,16 +1221,20 @@
 void
 ipport_tick(void *xtp)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(curvnet);
-	if (V_ipport_tcpallocs <= V_ipport_tcplastcount + V_ipport_randomcps) {
-		if (V_ipport_stoprandom > 0)
-			V_ipport_stoprandom--;
-	} else
-		V_ipport_stoprandom = V_ipport_randomtime;
-	V_ipport_tcplastcount = V_ipport_tcpallocs;
-	VNET_ITERLOOP_END();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);	/* XXX appease INVARIANTS here */
+		INIT_VNET_INET(vnet_iter);
+		if (V_ipport_tcpallocs <=
+		    V_ipport_tcplastcount + V_ipport_randomcps) {
+			if (V_ipport_stoprandom > 0)
+				V_ipport_stoprandom--;
+		} else
+			V_ipport_stoprandom = V_ipport_randomtime;
+		V_ipport_tcplastcount = V_ipport_tcpallocs;
+		CURVNET_RESTORE();
+	}
 	callout_reset(&ipport_tick_callout, hz, ipport_tick, NULL);
 }
 

==== //depot/projects/vimage/src/sys/netinet/in_rmx.c#18 (text+ko) ====

@@ -336,25 +336,28 @@
 void
 in_rtqdrain(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct radix_node_head *rnh;
 	struct rtqk_arg arg;
 	int 	fibnum;
 
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_NET(vnet_iter);
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_NET(vnet_iter);
 
-	for ( fibnum = 0; fibnum < rt_numfibs; fibnum++) {
-		rnh = V_rt_tables[fibnum][AF_INET];
-		arg.found = arg.killed = 0;
-		arg.rnh = rnh;
-		arg.nextstop = 0;
-		arg.draining = 1;
-		arg.updating = 0;
-		RADIX_NODE_HEAD_LOCK(rnh);
-		rnh->rnh_walktree(rnh, in_rtqkill, &arg);
-		RADIX_NODE_HEAD_UNLOCK(rnh);
+		for ( fibnum = 0; fibnum < rt_numfibs; fibnum++) {
+			rnh = V_rt_tables[fibnum][AF_INET];
+			arg.found = arg.killed = 0;
+			arg.rnh = rnh;
+			arg.nextstop = 0;
+			arg.draining = 1;
+			arg.updating = 0;
+			RADIX_NODE_HEAD_LOCK(rnh);
+			rnh->rnh_walktree(rnh, in_rtqkill, &arg);
+			RADIX_NODE_HEAD_UNLOCK(rnh);
+		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
 }
 
 static int _in_rt_was_here;

==== //depot/projects/vimage/src/sys/netinet/ip_input.c#32 (text+ko) ====

@@ -1145,39 +1145,45 @@
 void
 ip_slowtimo(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ipq *fp;
 	int i;
 
 	IPQ_LOCK();
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(vnet_iter);
-	for (i = 0; i < IPREASS_NHASH; i++) {
-		for(fp = TAILQ_FIRST(&V_ipq[i]); fp;) {
-			struct ipq *fpp;
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET(vnet_iter);
+		for (i = 0; i < IPREASS_NHASH; i++) {
+			for(fp = TAILQ_FIRST(&V_ipq[i]); fp;) {
+				struct ipq *fpp;
 
-			fpp = fp;
-			fp = TAILQ_NEXT(fp, ipq_list);
-			if(--fpp->ipq_ttl == 0) {
-				V_ipstat.ips_fragtimeout += fpp->ipq_nfrags;
-				ip_freef(&V_ipq[i], fpp);
+				fpp = fp;
+				fp = TAILQ_NEXT(fp, ipq_list);
+				if(--fpp->ipq_ttl == 0) {
+					V_ipstat.ips_fragtimeout +=
+					    fpp->ipq_nfrags;
+					ip_freef(&V_ipq[i], fpp);
+				}
 			}
 		}
-	}
-	/*
-	 * If we are over the maximum number of fragments
-	 * (due to the limit being lowered), drain off
-	 * enough to get down to the new limit.
-	 */
-	if (V_maxnipq >= 0 && V_nipq > V_maxnipq) {
-		for (i = 0; i < IPREASS_NHASH; i++) {
-			while (V_nipq > V_maxnipq && !TAILQ_EMPTY(&V_ipq[i])) {
-				V_ipstat.ips_fragdropped +=
-				    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
-				ip_freef(&V_ipq[i], TAILQ_FIRST(&V_ipq[i]));
+		/*
+		 * If we are over the maximum number of fragments
+		 * (due to the limit being lowered), drain off
+		 * enough to get down to the new limit.
+		 */
+		if (V_maxnipq >= 0 && V_nipq > V_maxnipq) {
+			for (i = 0; i < IPREASS_NHASH; i++) {
+				while (V_nipq > V_maxnipq &&
+				    !TAILQ_EMPTY(&V_ipq[i])) {
+					V_ipstat.ips_fragdropped +=
+					    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
+					ip_freef(&V_ipq[i],
+					    TAILQ_FIRST(&V_ipq[i]));
+				}
 			}
 		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
 	IPQ_UNLOCK();
 }
 
@@ -1187,19 +1193,22 @@
 void
 ip_drain(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	int     i;
 
 	IPQ_LOCK();
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(vnet_iter);
-	for (i = 0; i < IPREASS_NHASH; i++) {
-		while(!TAILQ_EMPTY(&V_ipq[i])) {
-			V_ipstat.ips_fragdropped +=
-			    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
-			ip_freef(&V_ipq[i], TAILQ_FIRST(&V_ipq[i]));
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET(vnet_iter);
+		for (i = 0; i < IPREASS_NHASH; i++) {
+			while(!TAILQ_EMPTY(&V_ipq[i])) {
+				V_ipstat.ips_fragdropped +=
+				    TAILQ_FIRST(&V_ipq[i])->ipq_nfrags;
+				ip_freef(&V_ipq[i], TAILQ_FIRST(&V_ipq[i]));
+			}
 		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END();
 	IPQ_UNLOCK();
 	in_rtqdrain();
 }

==== //depot/projects/vimage/src/sys/netinet/tcp_subr.c#47 (text+ko) ====

@@ -903,8 +903,13 @@
 void
 tcp_drain(void)
 {
-	if (do_tcpdrain) {
-		VNET_ITERLOOP_BEGIN();
+	VNET_ITERATOR_DECL(vnet_iter);
+
+	if (!do_tcpdrain)
+		return;
+
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
 		INIT_VNET_INET(vnet_iter);
 		struct inpcb *inpb;
 		struct tcpcb *tcpb;
@@ -937,7 +942,7 @@
 			INP_WUNLOCK(inpb);
 		}
 		INP_INFO_RUNLOCK(&V_tcbinfo);
-		VNET_ITERLOOP_END();
+		CURVNET_RESTORE();
 	}
 }
 
@@ -1546,18 +1551,22 @@
 static void
 tcp_isn_tick(void *xtp)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	u_int32_t projected_offset;
 
 	ISN_LOCK();
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(curvnet);
-	projected_offset = V_isn_offset_old + ISN_BYTES_PER_SECOND / 100;
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter); /* XXX appease INVARIANTS */
+		INIT_VNET_INET(curvnet);
+		projected_offset =
+		    V_isn_offset_old + ISN_BYTES_PER_SECOND / 100;
 
-	if (SEQ_GT(projected_offset, V_isn_offset))
-		V_isn_offset = projected_offset;
+		if (SEQ_GT(projected_offset, V_isn_offset))
+			V_isn_offset = projected_offset;
 
-	V_isn_offset_old = V_isn_offset;
-	VNET_ITERLOOP_END();
+		V_isn_offset_old = V_isn_offset;
+		CURVNET_RESTORE();
+	}
 	callout_reset(&isn_callout, hz/100, tcp_isn_tick, NULL);
 	ISN_UNLOCK();
 }

==== //depot/projects/vimage/src/sys/netinet/tcp_timer.c#20 (text+ko) ====

@@ -126,14 +126,17 @@
 void
 tcp_slowtimo(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 
-	VNET_ITERLOOP_BEGIN();
-	INIT_VNET_INET(vnet_iter);
-	tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
-	INP_INFO_WLOCK(&V_tcbinfo);
-	(void) tcp_tw_2msl_scan(0);
-	INP_INFO_WUNLOCK(&V_tcbinfo);
-	VNET_ITERLOOP_END();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET(vnet_iter);
+		tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
+		INP_INFO_WLOCK(&V_tcbinfo);
+		(void) tcp_tw_2msl_scan(0);
+		INP_INFO_WUNLOCK(&V_tcbinfo);
+		CURVNET_RESTORE();
+	}
 }
 
 int	tcp_syn_backoff[TCP_MAXRXTSHIFT + 1] =

==== //depot/projects/vimage/src/sys/netinet6/frag6.c#17 (text+ko) ====

@@ -693,34 +693,37 @@
 void
 frag6_slowtimo(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	struct ip6q *q6;
 
 	IP6Q_LOCK();
-	VNET_ITERLOOP_BEGIN()
-	INIT_VNET_INET6(curvnet);
-	q6 = V_ip6q.ip6q_next;
-	if (q6)
-		while (q6 != &V_ip6q) {
-			--q6->ip6q_ttl;
-			q6 = q6->ip6q_next;
-			if (q6->ip6q_prev->ip6q_ttl == 0) {
-				V_ip6stat.ip6s_fragtimeout++;
-				/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
-				frag6_freef(q6->ip6q_prev);
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET6(curvnet);
+		q6 = V_ip6q.ip6q_next;
+		if (q6)
+			while (q6 != &V_ip6q) {
+				--q6->ip6q_ttl;
+				q6 = q6->ip6q_next;
+				if (q6->ip6q_prev->ip6q_ttl == 0) {
+					V_ip6stat.ip6s_fragtimeout++;
+					/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
+					frag6_freef(q6->ip6q_prev);
+				}
 			}
+		/*
+		 * If we are over the maximum number of fragments
+		 * (due to the limit being lowered), drain off
+		 * enough to get down to the new limit.
+		 */
+		while (V_frag6_nfragpackets > (u_int)V_ip6_maxfragpackets &&
+		    V_ip6q.ip6q_prev) {
+			V_ip6stat.ip6s_fragoverflow++;
+			/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
+			frag6_freef(V_ip6q.ip6q_prev);
 		}
-	/*
-	 * If we are over the maximum number of fragments
-	 * (due to the limit being lowered), drain off
-	 * enough to get down to the new limit.
-	 */
-	while (V_frag6_nfragpackets > (u_int)V_ip6_maxfragpackets &&
-	    V_ip6q.ip6q_prev) {
-		V_ip6stat.ip6s_fragoverflow++;
-		/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
-		frag6_freef(V_ip6q.ip6q_prev);
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END()
 	IP6Q_UNLOCK();
 
 #if 0
@@ -746,16 +749,19 @@
 void
 frag6_drain(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 
 	if (IP6Q_TRYLOCK() == 0)
 		return;
-	VNET_ITERLOOP_BEGIN()
-	INIT_VNET_INET6(curvnet);
-	while (V_ip6q.ip6q_next != &V_ip6q) {
-		V_ip6stat.ip6s_fragdropped++;
-		/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
-		frag6_freef(V_ip6q.ip6q_next);
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		INIT_VNET_INET6(vnet_iter);
+		while (V_ip6q.ip6q_next != &V_ip6q) {
+			V_ip6stat.ip6s_fragdropped++;
+			/* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */
+			frag6_freef(V_ip6q.ip6q_next);
+		}
+		CURVNET_RESTORE();
 	}
-	VNET_ITERLOOP_END()
 	IP6Q_UNLOCK();
 }

==== //depot/projects/vimage/src/sys/netipsec/key.c#20 (text+ko) ====

@@ -4344,14 +4344,17 @@
 void
 key_timehandler(void)
 {
+	VNET_ITERATOR_DECL(vnet_iter);
 	time_t now = time_second;
 	
-	VNET_ITERLOOP_BEGIN();
-	key_flush_spd(now);
-	key_flush_sad(now);
-	key_flush_acq(now);
-	key_flush_spacq(now);
-	VNET_ITERLOOP_END();
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET(vnet_iter);
+		key_flush_spd(now);
+		key_flush_sad(now);
+		key_flush_acq(now);
+		key_flush_spacq(now);
+		CURVNET_RESTORE();
+	}
 
 #ifndef IPSEC_DEBUG2
 	/* do exchange to tick time !! */

==== //depot/projects/vimage/src/sys/sys/vimage.h#63 (text+ko) ====

@@ -219,23 +219,6 @@
 		      vnet, curvnet);					\
 	modtype *sym = (vnet)->mod_data[modindex];
 
-#define VNET_ITERLOOP_BEGIN()						\
-	struct vnet *vnet_iter;						\
-	VNET_LIST_REF();						\
-	LIST_FOREACH(vnet_iter, &vnet_head, vnet_le) {			\
-		CURVNET_SET(vnet_iter);
-
-#define VNET_ITERLOOP_BEGIN_QUIET()					\
-	struct vnet *vnet_iter;						\
-	VNET_LIST_REF();						\
-	LIST_FOREACH(vnet_iter, &vnet_head, vnet_le) {			\
-		CURVNET_SET_QUIET(vnet_iter);
-
-#define VNET_ITERLOOP_END()						\
-		CURVNET_RESTORE();					\
-	}								\
-	VNET_LIST_UNREF();
-
 #else /* !VNET_DEBUG */
 
 #define VNET_ASSERT(condition)
@@ -253,20 +236,10 @@
 #define INIT_FROM_VNET(vnet, modindex, modtype, sym)			\
 	modtype *sym = (vnet)->mod_data[modindex];
 
-#define VNET_ITERLOOP_BEGIN()						\
-	struct vnet *vnet_iter;						\
-	VNET_LIST_REF();						\
-	LIST_FOREACH(vnet_iter, &vnet_head, vnet_le) {			\
-		CURVNET_SET(vnet_iter);
+#endif /* !VNET_DEBUG */
 
-#define VNET_ITERLOOP_BEGIN_QUIET()	VNET_ITERLOOP_BEGIN()	
-
-#define VNET_ITERLOOP_END()						\
-		CURVNET_RESTORE();					\
-	}								\
-	VNET_LIST_UNREF();
-
-#endif /* !VNET_DEBUG */
+#define VNET_ITERATOR_DECL(arg)	struct vnet *arg;
+#define VNET_FOREACH(arg) LIST_FOREACH(arg, &vnet_head, vnet_le)
 
 #define INIT_VPROCG(arg)	struct vprocg *vprocg = (arg);
 
@@ -301,9 +274,10 @@
 #define VNET_ASSERT(condition)
 #define VSYM(base, sym) (sym)
 #define INIT_FROM_VNET(vnet, modindex, modtype, sym)
-#define VNET_ITERLOOP_BEGIN()
-#define VNET_ITERLOOP_BEGIN_QUIET()
-#define VNET_ITERLOOP_END()
+#define VNET_ITERATOR_DECL(arg)
+#define VNET_FOREACH(arg)
+#define VNET_LIST_REF()
+#define VNET_LIST_UNREF()
 #define INIT_VPROCG(arg)
 #define VPROCG_ITERLOOP_BEGIN()
 #define VPROCG_ITERLOOP_END()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809081655.m88GtxbV000906>