convert frag6 to mutex

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

convert frag6 to mutex

Florian Obser-2
replace hand rolled LOCK/UNLOCK macros with a mutex like in the v4
case. While here remove the NET_LOCK.

OK?

diff --git frag6.c frag6.c
index a5b8ae261be..390115106c5 100644
--- frag6.c
+++ frag6.c
@@ -34,6 +34,7 @@
 #include <sys/systm.h>
 #include <sys/mbuf.h>
 #include <sys/domain.h>
+#include <sys/mutex.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/errno.h>
@@ -55,7 +56,8 @@
 
 void frag6_freef(struct ip6q *);
 
-static int ip6q_locked;
+struct mutex ip6q_mutex = MUTEX_INITIALIZER(IPL_SOFTNET);
+
 u_int frag6_nfragpackets;
 u_int frag6_nfrags;
 TAILQ_HEAD(ip6q_head, ip6q) frag6_queue; /* ip6 reassemble queue */
@@ -63,57 +65,6 @@ TAILQ_HEAD(ip6q_head, ip6q) frag6_queue; /* ip6 reassemble queue */
 struct pool ip6af_pool;
 struct pool ip6q_pool;
 
-static __inline int ip6q_lock_try(void);
-static __inline void ip6q_unlock(void);
-
-static __inline int
-ip6q_lock_try(void)
-{
- int s;
-
- /* Use splvm() due to mbuf allocation. */
- s = splvm();
- if (ip6q_locked) {
- splx(s);
- return (0);
- }
- ip6q_locked = 1;
- splx(s);
- return (1);
-}
-
-static __inline void
-ip6q_unlock(void)
-{
- int s;
-
- s = splvm();
- ip6q_locked = 0;
- splx(s);
-}
-
-#ifdef DIAGNOSTIC
-#define IP6Q_LOCK() \
-do { \
- if (ip6q_lock_try() == 0) { \
- printf("%s:%d: ip6q already locked\n", __FILE__, __LINE__); \
- panic("ip6q_lock"); \
- } \
-} while (0)
-#define IP6Q_LOCK_CHECK() \
-do { \
- if (ip6q_locked == 0) { \
- printf("%s:%d: ip6q lock not held\n", __FILE__, __LINE__); \
- panic("ip6q lock check"); \
- } \
-} while (0)
-#else
-#define IP6Q_LOCK() (void) ip6q_lock_try()
-#define IP6Q_LOCK_CHECK() /* nothing */
-#endif
-
-#define IP6Q_UNLOCK() ip6q_unlock()
-
 /*
  * Initialise reassembly queue and pools.
  */
@@ -221,7 +172,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto, int af)
  return IPPROTO_DONE;
  }
 
- IP6Q_LOCK();
+ mtx_enter(&ip6q_mutex);
 
  /*
  * Enforce upper bound on number of fragments.
@@ -292,14 +243,14 @@ frag6_input(struct mbuf **mp, int *offp, int proto, int af)
  icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
     offset - sizeof(struct ip6_frag) +
     offsetof(struct ip6_frag, ip6f_offlg));
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return (IPPROTO_DONE);
  }
  } else if (fragoff + frgpartlen > IPV6_MAXPACKET) {
  icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
     offset - sizeof(struct ip6_frag) +
  offsetof(struct ip6_frag, ip6f_offlg));
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return (IPPROTO_DONE);
  }
  /*
@@ -440,13 +391,13 @@ frag6_input(struct mbuf **mp, int *offp, int proto, int af)
     af6 != NULL;
     paf6 = af6, af6 = LIST_NEXT(af6, ip6af_list)) {
  if (af6->ip6af_off != next) {
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return IPPROTO_DONE;
  }
  next += af6->ip6af_frglen;
  }
  if (paf6->ip6af_mff) {
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return IPPROTO_DONE;
  }
 
@@ -512,7 +463,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto, int af)
  *mp = m;
  *offp = offset;
 
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return nxt;
 
  flushfrags:
@@ -530,7 +481,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto, int af)
  dropfrag:
  ip6stat_inc(ip6s_fragdropped);
  m_freem(m);
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
  return IPPROTO_DONE;
 }
 
@@ -567,7 +518,7 @@ frag6_freef(struct ip6q *q6)
 {
  struct ip6asfrag *af6;
 
- IP6Q_LOCK_CHECK();
+ MUTEX_ASSERT_LOCKED(&ip6q_mutex);
 
  while ((af6 = LIST_FIRST(&q6->ip6q_asfrag)) != NULL) {
  struct mbuf *m = af6->ip6af_m;
@@ -610,9 +561,7 @@ frag6_slowtimo(void)
 {
  struct ip6q *q6, *nq6;
 
- NET_LOCK();
-
- IP6Q_LOCK();
+ mtx_enter(&ip6q_mutex);
  TAILQ_FOREACH_SAFE(q6, &frag6_queue, ip6q_queue, nq6)
  if (--q6->ip6q_ttl == 0) {
  ip6stat_inc(ip6s_fragtimeout);
@@ -629,9 +578,7 @@ frag6_slowtimo(void)
  ip6stat_inc(ip6s_fragoverflow);
  frag6_freef(TAILQ_LAST(&frag6_queue, ip6q_head));
  }
- IP6Q_UNLOCK();
-
- NET_UNLOCK();
+ mtx_leave(&ip6q_mutex);
 }
 
 /*
@@ -642,11 +589,11 @@ frag6_drain(void)
 {
  struct ip6q *q6;
 
- if (ip6q_lock_try() == 0)
+ if (mtx_enter_try(&ip6q_mutex) == 0)
  return;
  while ((q6 = TAILQ_FIRST(&frag6_queue)) != NULL) {
  ip6stat_inc(ip6s_fragdropped);
  frag6_freef(q6);
  }
- IP6Q_UNLOCK();
+ mtx_leave(&ip6q_mutex);
 }


--
I'm not entirely sure you are real.

Reply | Threaded
Open this post in threaded view
|

Re: convert frag6 to mutex

Florian Obser-2
please ignore this one, mpi points out that visa has a more
comprehensive diff for this that I missed.

--
I'm not entirely sure you are real.