summaryrefslogtreecommitdiffstats
path: root/sys/dev/sr
diff options
context:
space:
mode:
authorjlemon <jlemon@FreeBSD.org>2000-11-25 07:35:38 +0000
committerjlemon <jlemon@FreeBSD.org>2000-11-25 07:35:38 +0000
commit954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85 (patch)
tree0a4e9f6dcd5fa64a78f5991ac425f3ca97aba154 /sys/dev/sr
parent2daca11cae375091daf49a7cd704e5e4e1be27db (diff)
downloadFreeBSD-src-954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85.zip
FreeBSD-src-954e1d2ccdb661d5c8b7f69340d118fa7ba7fb85.tar.gz
Lock down the network interface queues. The queue mutex must be obtained
before adding/removing packets from the queue. Also, the if_obytes and if_omcasts fields should only be manipulated under protection of the mutex. IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on the queue. An IF_LOCK macro is provided, as well as the old (mutex-less) versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which needs them, but their use is discouraged. Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF, which takes care of locking/enqueue, and also statistics updating/start if necessary.
Diffstat (limited to 'sys/dev/sr')
-rw-r--r--sys/dev/sr/if_sr.c11
-rw-r--r--sys/dev/sr/if_sr_isa.c11
2 files changed, 16 insertions, 6 deletions
diff --git a/sys/dev/sr/if_sr.c b/sys/dev/sr/if_sr.c
index 9af963b..89b2c99 100644
--- a/sys/dev/sr/if_sr.c
+++ b/sys/dev/sr/if_sr.c
@@ -941,6 +941,8 @@ srattach(struct sr_hardc *hc)
callout_handle_init(&sc->handle);
sc->xmitq.ifq_maxlen = IFQ_MAXLEN;
sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN;
+ mtx_init(&sc->xmitq.ifq_mtx, "sr_xmitq", MTX_DEF);
+ mtx_init(&sc->xmitq_hipri.ifq_mtx, "sr_xmitq_hipri", MTX_DEF);
sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit);
if (ng_name_node(sc->node, sc->nodename)) {
ng_rmnode(sc->node);
@@ -3264,13 +3266,16 @@ ngsr_rcvdata(hook_p hook, struct mbuf *m, meta_p meta,
xmitq_p = (&sc->xmitq);
}
s = splimp();
- if (IF_QFULL(xmitq_p)) {
- IF_DROP(xmitq_p);
+ IF_LOCK(xmitq_p);
+ if (_IF_QFULL(xmitq_p)) {
+ _IF_DROP(xmitq_p);
+ IF_UNLOCK(xmitq_p);
splx(s);
error = ENOBUFS;
goto bad;
}
- IF_ENQUEUE(xmitq_p, m);
+ _IF_ENQUEUE(xmitq_p, m);
+ IF_UNLOCK(xmitq_p);
srstart(sc);
splx(s);
return (0);
diff --git a/sys/dev/sr/if_sr_isa.c b/sys/dev/sr/if_sr_isa.c
index 9af963b..89b2c99 100644
--- a/sys/dev/sr/if_sr_isa.c
+++ b/sys/dev/sr/if_sr_isa.c
@@ -941,6 +941,8 @@ srattach(struct sr_hardc *hc)
callout_handle_init(&sc->handle);
sc->xmitq.ifq_maxlen = IFQ_MAXLEN;
sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN;
+ mtx_init(&sc->xmitq.ifq_mtx, "sr_xmitq", MTX_DEF);
+ mtx_init(&sc->xmitq_hipri.ifq_mtx, "sr_xmitq_hipri", MTX_DEF);
sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit);
if (ng_name_node(sc->node, sc->nodename)) {
ng_rmnode(sc->node);
@@ -3264,13 +3266,16 @@ ngsr_rcvdata(hook_p hook, struct mbuf *m, meta_p meta,
xmitq_p = (&sc->xmitq);
}
s = splimp();
- if (IF_QFULL(xmitq_p)) {
- IF_DROP(xmitq_p);
+ IF_LOCK(xmitq_p);
+ if (_IF_QFULL(xmitq_p)) {
+ _IF_DROP(xmitq_p);
+ IF_UNLOCK(xmitq_p);
splx(s);
error = ENOBUFS;
goto bad;
}
- IF_ENQUEUE(xmitq_p, m);
+ _IF_ENQUEUE(xmitq_p, m);
+ IF_UNLOCK(xmitq_p);
srstart(sc);
splx(s);
return (0);
OpenPOWER on IntegriCloud