diff options
author | rwatson <rwatson@FreeBSD.org> | 2015-01-06 12:59:37 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2015-01-06 12:59:37 +0000 |
commit | 60909669f00c3675bab15d82d9d63aaff61dfafa (patch) | |
tree | 8da641e0473d723ab1cc2e5a5772cb1eed6e4d6f /sys/dev | |
parent | ff9d81bf5b98e98550d75c454cbd7b6d5002e628 (diff) | |
download | FreeBSD-src-60909669f00c3675bab15d82d9d63aaff61dfafa.zip FreeBSD-src-60909669f00c3675bab15d82d9d63aaff61dfafa.tar.gz |
In order to reduce use of M_EXT outside of the mbuf allocator and
socket-buffer implementations, introduce a return value for MCLGET()
(and m_cljget() that underlies it) to allow the caller to avoid testing
M_EXT itself. Update all callers to use the return value.
With this change, very few network device drivers remain aware of
M_EXT; the primary exceptions lie in mbuf-chain pretty printers for
debugging, and in a few cases, custom mbuf and cluster allocation
implementations.
NB: This is a difficult-to-test change as it touches many drivers for
which I don't have physical devices. Instead we've gone for intensive
review, but further post-commit review would definitely be appreciated
to spot errors where changes could not easily be made mechanically,
but were largely mechanical in nature.
Differential Revision: https://reviews.freebsd.org/D1440
Reviewed by: adrian, bz, gnn
Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'sys/dev')
32 files changed, 37 insertions, 81 deletions
diff --git a/sys/dev/an/if_an.c b/sys/dev/an/if_an.c index bee2a0c..3433cd5 100644 --- a/sys/dev/an/if_an.c +++ b/sys/dev/an/if_an.c @@ -943,8 +943,7 @@ an_rxeof(struct an_softc *sc) if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); return; } - MCLGET(m, M_NOWAIT); - if (!(m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); return; @@ -1034,8 +1033,7 @@ an_rxeof(struct an_softc *sc) if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); return; } - MCLGET(m, M_NOWAIT); - if (!(m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); return; diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c index 58f529d..af4fddb 100644 --- a/sys/dev/bge/if_bge.c +++ b/sys/dev/bge/if_bge.c @@ -1383,8 +1383,7 @@ bge_newbuf_jumbo(struct bge_softc *sc, int i) if (m == NULL) return (ENOBUFS); - m_cljget(m, M_NOWAIT, MJUM9BYTES); - if (!(m->m_flags & M_EXT)) { + if (m_cljget(m, M_NOWAIT, MJUM9BYTES) == NULL) { m_freem(m); return (ENOBUFS); } diff --git a/sys/dev/ce/if_ce.c b/sys/dev/ce/if_ce.c index d0dd0c7..7d81720 100644 --- a/sys/dev/ce/if_ce.c +++ b/sys/dev/ce/if_ce.c @@ -307,8 +307,7 @@ static struct mbuf *makembuf (void *buf, unsigned len) MGETHDR (m, M_NOWAIT, MT_DATA); if (! m) return 0; - MCLGET (m, M_NOWAIT); - if (! (m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem (m); return 0; } diff --git a/sys/dev/cm/smc90cx6.c b/sys/dev/cm/smc90cx6.c index a1932ad..5607298 100644 --- a/sys/dev/cm/smc90cx6.c +++ b/sys/dev/cm/smc90cx6.c @@ -540,10 +540,7 @@ cm_srint_locked(vsc) */ if ((len + 2 + 2) > MHLEN) { /* attach an mbuf cluster */ - MCLGET(m, M_NOWAIT); - - /* Insist on getting a cluster */ - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); goto cleanup; } diff --git a/sys/dev/cp/if_cp.c b/sys/dev/cp/if_cp.c index 4e70838..3d07ef2 100644 --- a/sys/dev/cp/if_cp.c +++ b/sys/dev/cp/if_cp.c @@ -191,8 +191,7 @@ static struct mbuf *makembuf (void *buf, unsigned len) MGETHDR (m, M_NOWAIT, MT_DATA); if (! m) return 0; - MCLGET (m, M_NOWAIT); - if (! (m->m_flags & M_EXT)) { + if (!(MCLGET (m, M_NOWAIT))) { m_freem (m); return 0; } diff --git a/sys/dev/cs/if_cs.c b/sys/dev/cs/if_cs.c index 8ad50eb..a9b0d08 100644 --- a/sys/dev/cs/if_cs.c +++ b/sys/dev/cs/if_cs.c @@ -716,8 +716,7 @@ cs_get_packet(struct cs_softc *sc) return (-1); if (length > MHLEN) { - MCLGET(m, M_NOWAIT); - if (!(m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); return (-1); } diff --git a/sys/dev/ctau/if_ct.c b/sys/dev/ctau/if_ct.c index d0b68bc..2e9d2e2 100644 --- a/sys/dev/ctau/if_ct.c +++ b/sys/dev/ctau/if_ct.c @@ -194,8 +194,7 @@ static struct mbuf *makembuf (void *buf, u_int len) MGETHDR (m, M_NOWAIT, MT_DATA); if (! m) return 0; - MCLGET (m, M_NOWAIT); - if (! (m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem (m); return 0; } diff --git a/sys/dev/ed/if_ed.c b/sys/dev/ed/if_ed.c index 46524dd..be9d274 100644 --- a/sys/dev/ed/if_ed.c +++ b/sys/dev/ed/if_ed.c @@ -1323,10 +1323,7 @@ ed_get_packet(struct ed_softc *sc, bus_size_t buf, u_short len) */ if ((len + 2) > MHLEN) { /* Attach an mbuf cluster */ - MCLGET(m, M_NOWAIT); - - /* Insist on getting a cluster */ - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); return; } diff --git a/sys/dev/ex/if_ex.c b/sys/dev/ex/if_ex.c index 4072351..5832168 100644 --- a/sys/dev/ex/if_ex.c +++ b/sys/dev/ex/if_ex.c @@ -745,8 +745,7 @@ ex_rx_intr(struct ex_softc *sc) while (pkt_len > 0) { if (pkt_len >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if (m->m_flags & M_EXT) { + if (MCLGET(m, M_NOWAIT)) { m->m_len = MCLBYTES; } else { m_freem(ipkt); diff --git a/sys/dev/fe/if_fe.c b/sys/dev/fe/if_fe.c index 2123dfc..4598b59 100644 --- a/sys/dev/fe/if_fe.c +++ b/sys/dev/fe/if_fe.c @@ -1880,8 +1880,7 @@ fe_get_packet (struct fe_softc * sc, u_short len) /* Attach a cluster if this packet doesn't fit in a normal mbuf. */ if (len > MHLEN - NFS_MAGIC_OFFSET) { - MCLGET(m, M_NOWAIT); - if (!(m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); return -1; } diff --git a/sys/dev/hifn/hifn7751.c b/sys/dev/hifn/hifn7751.c index e9d47a1..8330d30 100644 --- a/sys/dev/hifn/hifn7751.c +++ b/sys/dev/hifn/hifn7751.c @@ -1890,8 +1890,7 @@ hifn_crypto( goto err_srcmap; } if (totlen >= MINCLSIZE) { - MCLGET(m0, M_NOWAIT); - if ((m0->m_flags & M_EXT) == 0) { + if (!(MCLGET(m0, M_NOWAIT))) { hifnstats.hst_nomem_mcl++; err = sc->sc_cmdu ? ERESTART : ENOMEM; m_freem(m0); @@ -1913,8 +1912,7 @@ hifn_crypto( } len = MLEN; if (totlen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { hifnstats.hst_nomem_mcl++; err = sc->sc_cmdu ? ERESTART : ENOMEM; mlast->m_next = m; diff --git a/sys/dev/ie/if_ie.c b/sys/dev/ie/if_ie.c index 72e2559..dc7a868 100644 --- a/sys/dev/ie/if_ie.c +++ b/sys/dev/ie/if_ie.c @@ -728,8 +728,7 @@ ieget(struct ie_softc *sc, struct mbuf **mp) m->m_len = MLEN; } if (resid >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if (m->m_flags & M_EXT) + if (MCLGET(m, M_NOWAIT)) m->m_len = min(resid, MCLBYTES); } else { if (resid < m->m_len) { diff --git a/sys/dev/le/lance.c b/sys/dev/le/lance.c index 38be317..2b4202b 100644 --- a/sys/dev/le/lance.c +++ b/sys/dev/le/lance.c @@ -398,8 +398,7 @@ lance_get(struct lance_softc *sc, int boff, int totlen) while (totlen > 0) { if (totlen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) + if (!(MCLGET(m, M_NOWAIT))) goto bad; len = MCLBYTES; } diff --git a/sys/dev/lmc/if_lmc.c b/sys/dev/lmc/if_lmc.c index 9e1463b..3ca3d3e 100644 --- a/sys/dev/lmc/if_lmc.c +++ b/sys/dev/lmc/if_lmc.c @@ -2689,8 +2689,7 @@ rxintr_setup(softc_t *sc) printf("%s: rxintr_setup: MGETHDR() failed\n", NAME_UNIT); return 0; } - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); sc->status.cntrs.rxdma++; diff --git a/sys/dev/mn/if_mn.c b/sys/dev/mn/if_mn.c index 63ae5f6..2f1ea5f 100644 --- a/sys/dev/mn/if_mn.c +++ b/sys/dev/mn/if_mn.c @@ -1165,8 +1165,7 @@ mn_rx_intr(struct mn_softc *sc, u_int32_t vector) mn_free_desc(dp); return; /* ENOBUFS */ } - MCLGET(m, M_NOWAIT); - if((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { mn_free_desc(dp); m_freem(m); return; /* ENOBUFS */ diff --git a/sys/dev/my/if_my.c b/sys/dev/my/if_my.c index e94e9ab..e2430c1 100644 --- a/sys/dev/my/if_my.c +++ b/sys/dev/my/if_my.c @@ -1085,8 +1085,7 @@ my_newbuf(struct my_softc * sc, struct my_chain_onefrag * c) "no memory for rx list -- packet dropped!\n"); return (ENOBUFS); } - MCLGET(m_new, M_NOWAIT); - if (!(m_new->m_flags & M_EXT)) { + if (!(MCLGET(m_new, M_NOWAIT))) { device_printf(sc->my_dev, "no memory for rx list -- packet dropped!\n"); m_freem(m_new); @@ -1352,8 +1351,7 @@ my_encap(struct my_softc * sc, struct my_chain * c, struct mbuf * m_head) return (1); } if (m_head->m_pkthdr.len > MHLEN) { - MCLGET(m_new, M_NOWAIT); - if (!(m_new->m_flags & M_EXT)) { + if (!(MCLGET(m_new, M_NOWAIT))) { m_freem(m_new); device_printf(sc->my_dev, "no memory for tx list"); return (1); diff --git a/sys/dev/pcn/if_pcn.c b/sys/dev/pcn/if_pcn.c index d3121a1..d63d4aa 100644 --- a/sys/dev/pcn/if_pcn.c +++ b/sys/dev/pcn/if_pcn.c @@ -803,8 +803,7 @@ pcn_newbuf(sc, idx, m) if (m_new == NULL) return(ENOBUFS); - MCLGET(m_new, M_NOWAIT); - if (!(m_new->m_flags & M_EXT)) { + if (!(MCLGET(m_new, M_NOWAIT))) { m_freem(m_new); return(ENOBUFS); } diff --git a/sys/dev/pdq/pdq_freebsd.h b/sys/dev/pdq/pdq_freebsd.h index 78eeef9..a556b36 100644 --- a/sys/dev/pdq/pdq_freebsd.h +++ b/sys/dev/pdq/pdq_freebsd.h @@ -190,8 +190,7 @@ typedef struct _pdq_os_ctx_t { PDQ_OS_DATABUF_T *x_m0; \ MGETHDR(x_m0, M_NOWAIT, MT_DATA); \ if (x_m0 != NULL) { \ - MCLGET(x_m0, M_NOWAIT); \ - if ((x_m0->m_flags & M_EXT) == 0) { \ + if (!(MCLGET(x_m0, M_NOWAIT))) { \ m_free(x_m0); \ (b) = NULL; \ } else { \ diff --git a/sys/dev/pdq/pdq_ifsubr.c b/sys/dev/pdq/pdq_ifsubr.c index 50619cb..f8df3a7 100644 --- a/sys/dev/pdq/pdq_ifsubr.c +++ b/sys/dev/pdq/pdq_ifsubr.c @@ -748,8 +748,7 @@ pdq_os_databuf_alloc( printf("%s: can't alloc small buf\n", sc->sc_dev.dv_xname); return NULL; } - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { printf("%s: can't alloc cluster\n", sc->sc_dev.dv_xname); m_free(m); return NULL; diff --git a/sys/dev/pdq/pdqvar.h b/sys/dev/pdq/pdqvar.h index 7eb6324..db53273 100644 --- a/sys/dev/pdq/pdqvar.h +++ b/sys/dev/pdq/pdqvar.h @@ -216,8 +216,7 @@ typedef struct mbuf PDQ_OS_DATABUF_T; PDQ_OS_DATABUF_T *x_m0; \ MGETHDR(x_m0, M_NOWAIT, MT_DATA); \ if (x_m0 != NULL) { \ - MCLGET(x_m0, M_NOWAIT); \ - if ((x_m0->m_flags & M_EXT) == 0) { \ + if (!(MCLGET(x_m0, M_NOWAIT))) { \ m_free(x_m0); \ (b) = NULL; \ } else { \ diff --git a/sys/dev/safe/safe.c b/sys/dev/safe/safe.c index cfd00b6..9b91ed0 100644 --- a/sys/dev/safe/safe.c +++ b/sys/dev/safe/safe.c @@ -1328,8 +1328,7 @@ safe_process(device_t dev, struct cryptop *crp, int hint) goto errout; } if (totlen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { m_free(m); safestats.st_nomcl++; err = sc->sc_nqchip ? @@ -1355,8 +1354,7 @@ safe_process(device_t dev, struct cryptop *crp, int hint) len = MLEN; } if (top && totlen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { *mp = m; m_freem(top); safestats.st_nomcl++; diff --git a/sys/dev/sbni/if_sbni.c b/sys/dev/sbni/if_sbni.c index c459ded..03200ef 100644 --- a/sys/dev/sbni/if_sbni.c +++ b/sys/dev/sbni/if_sbni.c @@ -878,8 +878,7 @@ get_rx_buf(struct sbni_softc *sc) */ if (ETHER_MAX_LEN + 2 > MHLEN) { /* Attach an mbuf cluster */ - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); return (0); } diff --git a/sys/dev/smc/if_smc.c b/sys/dev/smc/if_smc.c index 8ba7210..af8a5bd 100644 --- a/sys/dev/smc/if_smc.c +++ b/sys/dev/smc/if_smc.c @@ -693,8 +693,7 @@ smc_task_rx(void *context, int pending) if (m == NULL) { break; } - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); break; } diff --git a/sys/dev/sn/if_sn.c b/sys/dev/sn/if_sn.c index 7350537..26e60bc 100644 --- a/sys/dev/sn/if_sn.c +++ b/sys/dev/sn/if_sn.c @@ -1065,14 +1065,9 @@ read_another: m->m_pkthdr.len = m->m_len = packet_length; /* - * Attach an mbuf cluster + * Attach an mbuf cluster. */ - MCLGET(m, M_NOWAIT); - - /* - * Insist on getting a cluster - */ - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); printf("sn: snread() kernel memory allocation problem\n"); diff --git a/sys/dev/snc/dp83932.c b/sys/dev/snc/dp83932.c index d4e062a..a496b67 100644 --- a/sys/dev/snc/dp83932.c +++ b/sys/dev/snc/dp83932.c @@ -1129,8 +1129,7 @@ sonic_get(struct snc_softc *sc, u_int32_t pkt, int datalen) len = MLEN; } if (datalen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(MCLGET(m, M_NOWAIT))) { if (top) m_freem(top); return (0); } diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c index 7d0fc9d..0405020 100644 --- a/sys/dev/ti/if_ti.c +++ b/sys/dev/ti/if_ti.c @@ -1596,8 +1596,7 @@ ti_newbuf_jumbo(struct ti_softc *sc, int idx, struct mbuf *m_old) "failed -- packet dropped!\n"); goto nobufs; } - MCLGET(m[NPAYLOAD], M_NOWAIT); - if ((m[NPAYLOAD]->m_flags & M_EXT) == 0) { + if (!(MCLGET(m[NPAYLOAD], M_NOWAIT))) { device_printf(sc->ti_dev, "mbuf allocation failed " "-- packet dropped!\n"); goto nobufs; diff --git a/sys/dev/tl/if_tl.c b/sys/dev/tl/if_tl.c index 8535b04..455dd38 100644 --- a/sys/dev/tl/if_tl.c +++ b/sys/dev/tl/if_tl.c @@ -1813,8 +1813,7 @@ tl_encap(sc, c, m_head) return(1); } if (m_head->m_pkthdr.len > MHLEN) { - MCLGET(m_new, M_NOWAIT); - if (!(m_new->m_flags & M_EXT)) { + if (!(MCLGET(m_new, M_NOWAIT))) { m_freem(m_new); if_printf(ifp, "no memory for tx list\n"); return(1); diff --git a/sys/dev/usb/misc/udbp.c b/sys/dev/usb/misc/udbp.c index fc0d850..8140170 100644 --- a/sys/dev/usb/misc/udbp.c +++ b/sys/dev/usb/misc/udbp.c @@ -417,9 +417,8 @@ udbp_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) if (m == NULL) { goto tr_setup; } - MCLGET(m, M_NOWAIT); - if (!(m->m_flags & M_EXT)) { + if (!(MCLGET(m, M_NOWAIT))) { m_freem(m); goto tr_setup; } diff --git a/sys/dev/vx/if_vx.c b/sys/dev/vx/if_vx.c index 7d852e9..47a6cd9 100644 --- a/sys/dev/vx/if_vx.c +++ b/sys/dev/vx/if_vx.c @@ -865,8 +865,7 @@ vx_get(struct vx_softc *sc, u_int totlen) len = MLEN; } if (totlen >= MINCLSIZE) { - MCLGET(m, M_NOWAIT); - if (m->m_flags & M_EXT) + if (MCLGET(m, M_NOWAIT)) len = MCLBYTES; } len = min(totlen, len); diff --git a/sys/dev/wb/if_wb.c b/sys/dev/wb/if_wb.c index 01090aa..4215d9e 100644 --- a/sys/dev/wb/if_wb.c +++ b/sys/dev/wb/if_wb.c @@ -1194,8 +1194,7 @@ wb_encap(sc, c, m_head) if (m_new == NULL) return(1); if (m_head->m_pkthdr.len > MHLEN) { - MCLGET(m_new, M_NOWAIT); - if (!(m_new->m_flags & M_EXT)) { + if (!(MCLGET(m_new, M_NOWAIT))) { m_freem(m_new); return(1); } diff --git a/sys/dev/xe/if_xe.c b/sys/dev/xe/if_xe.c index bcde27f..4a7aa6e 100644 --- a/sys/dev/xe/if_xe.c +++ b/sys/dev/xe/if_xe.c @@ -765,8 +765,7 @@ xe_rxintr(struct xe_softc *scp, uint8_t rst0) } if (len + 3 > MHLEN) { - MCLGET(mbp, M_NOWAIT); - if ((mbp->m_flags & M_EXT) == 0) { + if (!(MCLGET(mbp, M_NOWAIT))) { m_freem(mbp); if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); continue; diff --git a/sys/dev/xen/netfront/netfront.c b/sys/dev/xen/netfront/netfront.c index c3c8d92..440c189 100644 --- a/sys/dev/xen/netfront/netfront.c +++ b/sys/dev/xen/netfront/netfront.c @@ -822,8 +822,7 @@ network_alloc_rx_buffers(struct netfront_info *sc) goto no_mbuf; } - m_cljget(m_new, M_NOWAIT, MJUMPAGESIZE); - if ((m_new->m_flags & M_EXT) == 0) { + if (m_cljget(m_new, M_NOWAIT, MJUMPAGESIZE) == NULL) { printf("%s: m_cljget failed\n", __func__); m_freem(m_new); |