PERFORCE change 41387 for review

Sam Leffler sam at FreeBSD.org
Tue Nov 4 13:03:31 PST 2003


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

Change 41387 by sam at sam_ebb on 2003/11/04 13:02:57

	wrap rtentry reference count manipulations in macros so we
	can add assertions under INVARIANTS

Affected files ...

.. //depot/projects/netperf/sys/net/route.c#26 edit
.. //depot/projects/netperf/sys/net/route.h#13 edit
.. //depot/projects/netperf/sys/net/rtsock.c#9 edit
.. //depot/projects/netperf/sys/netinet/if_atm.c#8 edit
.. //depot/projects/netperf/sys/netinet/if_ether.c#15 edit
.. //depot/projects/netperf/sys/netinet/in_pcb.c#11 edit
.. //depot/projects/netperf/sys/netinet/in_pcb.h#10 edit
.. //depot/projects/netperf/sys/netinet/ip_dummynet.c#16 edit
.. //depot/projects/netperf/sys/netinet/ip_flow.c#7 edit
.. //depot/projects/netperf/sys/netinet/tcp_output.c#6 edit
.. //depot/projects/netperf/sys/netinet6/in6.c#14 edit
.. //depot/projects/netperf/sys/netinet6/ip6_output.c#22 edit
.. //depot/projects/netperf/sys/netinet6/nd6.c#15 edit
.. //depot/projects/netperf/sys/netinet6/nd6_rtr.c#10 edit

Differences ...

==== //depot/projects/netperf/sys/net/route.c#26 (text+ko) ====

@@ -154,7 +154,7 @@
 				 */
 				newrt = rt;		/* existing route */
 				RT_LOCK(newrt);
-				newrt->rt_refcnt++;
+				RT_ADDREF(newrt);
 				goto miss;
 			}
 			KASSERT(newrt, ("no route and no error"));
@@ -180,7 +180,7 @@
 		} else {
 			KASSERT(rt == newrt, ("locking wrong route"));
 			RT_LOCK(newrt);
-			newrt->rt_refcnt++;
+			RT_ADDREF(newrt);
 		}
 		RADIX_NODE_HEAD_UNLOCK(rnh);
 	} else {
@@ -228,7 +228,8 @@
 	 * decrement the reference count by one and if it reaches 0,
 	 * and there is a close function defined, call the close function
 	 */
-	if (--rt->rt_refcnt > 0)
+	RT_REMREF(rt);
+	if (rt->rt_refcnt > 0)
 		goto done;
 
 	/*
@@ -442,7 +443,7 @@
 		struct rtentry *rt = rtalloc1(gateway, 0, 0UL);
 		if (rt == 0)
 			return (0);
-		--rt->rt_refcnt;
+		RT_REMREF(rt);
 		RT_UNLOCK(rt);
 		if ((ifa = rt->rt_ifa) == 0)
 			return (0);
@@ -661,7 +662,7 @@
 			panic ("rtrequest delete");
 		rt = (struct rtentry *)rn;
 		RT_LOCK(rt);
-		rt->rt_refcnt++;
+		RT_ADDREF(rt);
 		rt->rt_flags &= ~RTF_UP;
 
 		/*
@@ -861,7 +862,7 @@
 		 */
 		if (ret_nrt) {
 			*ret_nrt = rt;
-			rt->rt_refcnt++;
+			RT_ADDREF(rt);
 		}
 		RT_UNLOCK(rt);
 		break;
@@ -1229,7 +1230,7 @@
 				 * We just wanted to add it.. we don't actually
 				 * need a reference.
 				 */
-				rt->rt_refcnt--;
+				RT_REMREF(rt);
 			}
 			RT_UNLOCK(rt);
 		}
@@ -1269,7 +1270,7 @@
 			RT_UNLOCK(rt);
 			rt = rtalloc1(dst, 1, 0UL);
 			if (rt != NULL) {
-				rt->rt_refcnt--;
+				RT_REMREF(rt);
 				RT_UNLOCK(rt);
 			} else
 				senderr(EHOSTUNREACH);

==== //depot/projects/netperf/sys/net/route.h#13 (text+ko) ====

@@ -266,19 +266,32 @@
 #define	RT_LOCK_DESTROY(_rt)	mtx_destroy(&(_rt)->rt_mtx)
 #define	RT_LOCK_ASSERT(_rt)	mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
 
-#define	RTFREE_LOCKED(_rt) do {				\
-		if ((_rt)->rt_refcnt <= 1)		\
-			rtfree(_rt);			\
-		else {					\
-			(_rt)->rt_refcnt--;		\
-			RT_UNLOCK(_rt);			\
-		}					\
-		/* guard against invalid refs */	\
-		_rt = 0;				\
+#define	RT_ADDREF(_rt)	do {					\
+	RT_LOCK_ASSERT(_rt);					\
+	KASSERT((_rt)->rt_refcnt >= 0,				\
+		("negative refcnt %ld", (_rt)->rt_refcnt));	\
+	(_rt)->rt_refcnt++;					\
+} while (0);
+#define	RT_REMREF(_rt)	do {					\
+	RT_LOCK_ASSERT(_rt);					\
+	KASSERT((_rt)->rt_refcnt > 0,				\
+		("bogus refcnt %ld", (_rt)->rt_refcnt));	\
+	(_rt)->rt_refcnt--;					\
+} while (0);
+
+#define	RTFREE_LOCKED(_rt) do {					\
+		if ((_rt)->rt_refcnt <= 1)			\
+			rtfree(_rt);				\
+		else {						\
+			RT_REMREF(_rt);				\
+			RT_UNLOCK(_rt);				\
+		}						\
+		/* guard against invalid refs */		\
+		_rt = 0;					\
 	} while (0)
-#define	RTFREE(_rt) do {				\
-		RT_LOCK(_rt);				\
-		RTFREE_LOCKED(_rt);			\
+#define	RTFREE(_rt) do {					\
+		RT_LOCK(_rt);					\
+		RTFREE_LOCKED(_rt);				\
 	} while (0)
 
 extern struct radix_node_head *rt_tables[AF_MAX+1];

==== //depot/projects/netperf/sys/net/rtsock.c#9 (text+ko) ====

@@ -357,7 +357,7 @@
 			saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
 			saved_nrt->rt_rmx.rmx_locks |=
 				(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
-			saved_nrt->rt_refcnt--;
+			RT_REMREF(saved_nrt);
 			saved_nrt->rt_genmask = info.rti_info[RTAX_GENMASK];
 			RT_UNLOCK(saved_nrt);
 		}
@@ -386,7 +386,7 @@
 		if (rt == NULL)		/* XXX looks bogus */
 			senderr(ESRCH);
 		RT_LOCK(rt);
-		rt->rt_refcnt++;
+		RT_ADDREF(rt);
 
 		switch(rtm->rtm_type) {
 

==== //depot/projects/netperf/sys/netinet/if_atm.c#8 (text+ko) ====

@@ -320,7 +320,7 @@
 		rt = RTALLOC1(dst, 0);
 		if (rt == NULL)
 			goto bad;	/* failed */
-		rt->rt_refcnt--;	/* don't keep LL references */
+		RT_REMREF(rt);		/* don't keep LL references */
 		if ((rt->rt_flags & RTF_GATEWAY) != 0 || 
 		    (rt->rt_flags & RTF_LLINFO) == 0 ||
 		    /* XXX: are we using LLINFO? */

==== //depot/projects/netperf/sys/netinet/if_ether.c#15 (text+ko) ====

@@ -954,7 +954,7 @@
 		return (0);
 #undef ISDYNCLONE
 	} else {
-		rt->rt_refcnt--;
+		RT_REMREF(rt);
 		RT_UNLOCK(rt);
 		return ((struct llinfo_arp *)rt->rt_llinfo);
 	}

==== //depot/projects/netperf/sys/netinet/in_pcb.c#11 (text+ko) ====


==== //depot/projects/netperf/sys/netinet/in_pcb.h#10 (text+ko) ====


==== //depot/projects/netperf/sys/netinet/ip_dummynet.c#16 (text+ko) ====

@@ -1197,9 +1197,7 @@
 	pkt->ro = *(fwa->ro);
 	if (pkt->ro.ro_rt) {
 	    RT_LOCK(pkt->ro.ro_rt);
-	    pkt->ro.ro_rt->rt_refcnt++ ;
-	    KASSERT(pkt->ro.ro_rt->rt_refcnt > 0,
-		("bogus refcnt %ld", pkt->ro.ro_rt->rt_refcnt));
+	    RT_ADDREF(pkt->ro.ro_rt) ;
 	    RT_UNLOCK(pkt->ro.ro_rt);
 	}
 	if (fwa->dst == (struct sockaddr_in *)&fwa->ro->ro_dst) /* dst points into ro */

==== //depot/projects/netperf/sys/netinet/ip_flow.c#7 (text+ko) ====

@@ -353,7 +353,7 @@
 	 */
 	ipf->ipf_ro = *ro;
 	RT_LOCK(ro->ro_rt);
-	ro->ro_rt->rt_refcnt++;
+	RT_ADDREF(ro->ro_rt);
 	RT_UNLOCK(ro->ro_rt);
 	ipf->ipf_timer = IPFLOW_TIMER;
 	/*

==== //depot/projects/netperf/sys/netinet/tcp_output.c#6 (text+ko) ====

@@ -134,7 +134,7 @@
 #endif
 
 #ifndef INET6
-	mtx_assert(&tp->t_inpcb->inp_mtx, MA_OWNED);
+	INP_LOCK_ASSERT(tp->t_inpcb);
 #endif
 
 	/*

==== //depot/projects/netperf/sys/netinet6/in6.c#14 (text+ko) ====

@@ -197,7 +197,7 @@
 			rtfree(nrt);
 		} else {
 			/* the cmd must be RTM_ADD here */
-			nrt->rt_refcnt--;
+			RT_REMREF(nrt);
 			RT_UNLOCK(nrt);
 		}
 	}

==== //depot/projects/netperf/sys/netinet6/ip6_output.c#22 (text+ko) ====

@@ -2908,7 +2908,7 @@
 		*opt = *stickyopt;
 		if (opt->ip6po_nextroute.ro_rt) {
 			RT_LOCK(opt->ip6po_nextroute.ro_rt);
-			opt->ip6po_nextroute.ro_rt->rt_refcnt++;
+			RT_ADDREF(opt->ip6po_nextroute.ro_rt);
 			RT_UNLOCK(opt->ip6po_nextroute.ro_rt);
 		}
 	} else

==== //depot/projects/netperf/sys/netinet6/nd6.c#15 (text+ko) ====

@@ -838,7 +838,7 @@
 			return (NULL);
 	}
 	RT_LOCK_ASSERT(rt);
-	rt->rt_refcnt--;
+	RT_REMREF(rt);
 	/*
 	 * Validation for the entry.
 	 * Note that the check for rt_llinfo is necessary because a cloned
@@ -1834,7 +1834,7 @@
 		if ((rt->rt_flags & RTF_UP) == 0) {
 			rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL);
 			if (rt != NULL) {
-				rt->rt_refcnt--;
+				RT_REMREF(rt);
 				RT_UNLOCK(rt);
 				if (rt->rt_ifp != ifp) {
 					/* XXX: loop care? */

==== //depot/projects/netperf/sys/netinet6/nd6_rtr.c#10 (text+ko) ====

@@ -478,7 +478,7 @@
 	if (newrt) {
 		RT_LOCK(newrt);
 		nd6_rtmsg(RTM_ADD, newrt); /* tell user process */
-		newrt->rt_refcnt--;
+		RT_REMREF(newrt);
 		RT_UNLOCK(newrt);
 	}
 	return;
@@ -524,7 +524,7 @@
 		if (newrt) {
 			RT_LOCK(newrt);
 			nd6_rtmsg(RTM_ADD, newrt);
-			newrt->rt_refcnt--;
+			RT_REMREF(newrt);
 			RT_UNLOCK(newrt);
 		}
 	}
@@ -1470,7 +1470,7 @@
 
 	if (rt != NULL) {
 		RT_LOCK(rt);
-		rt->rt_refcnt--;
+		RT_REMREF(rt);
 		RT_UNLOCK(rt);
 	}
 


More information about the p4-projects mailing list