Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Merge uipc_mbuf2.c into uipc_mbuf.c. Reorder the latter a li...
details: https://anonhg.NetBSD.org/src/rev/f4c8b5f79c76
branches: trunk
changeset: 445862:f4c8b5f79c76
user: maxv <maxv%NetBSD.org@localhost>
date: Thu Nov 15 09:38:57 2018 +0000
description:
Merge uipc_mbuf2.c into uipc_mbuf.c. Reorder the latter a little to gather
similar functions. No functional change.
diffstat:
share/man/man9/m_tag.9 | 6 +-
sys/kern/files.kern | 3 +-
sys/kern/uipc_mbuf.c | 500 ++++++++++++++++++++++++-----
sys/kern/uipc_mbuf2.c | 426 -------------------------
sys/rump/librump/rumpnet/Makefile.rumpnet | 4 +-
5 files changed, 416 insertions(+), 523 deletions(-)
diffs (truncated from 1051 to 300 lines):
diff -r e13d3518eeae -r f4c8b5f79c76 share/man/man9/m_tag.9
--- a/share/man/man9/m_tag.9 Thu Nov 15 09:23:50 2018 +0000
+++ b/share/man/man9/m_tag.9 Thu Nov 15 09:38:57 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: m_tag.9,v 1.5 2010/12/02 12:54:13 wiz Exp $
+.\" $NetBSD: m_tag.9,v 1.6 2018/11/15 09:38:57 maxv Exp $
.\"
.\" Copyright (c)2004 YAMAMOTO Takashi,
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\" SUCH DAMAGE.
.\"
.\" ------------------------------------------------------------
-.Dd September 7, 2004
+.Dd November 15, 2018
.Dt M_TAG 9
.Os
.Sh NAME
@@ -206,7 +206,7 @@
.\" ------------------------------------------------------------
.Sh CODE REFERENCES
The mbuf tagging interfaces are implemented within the file
-.Pa sys/kern/uipc_mbuf2.c .
+.Pa sys/kern/uipc_mbuf.c .
.Pp
The
.Dv PACKET_TAG_
diff -r e13d3518eeae -r f4c8b5f79c76 sys/kern/files.kern
--- a/sys/kern/files.kern Thu Nov 15 09:23:50 2018 +0000
+++ b/sys/kern/files.kern Thu Nov 15 09:38:57 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.kern,v 1.24 2018/10/31 06:26:26 maxv Exp $
+# $NetBSD: files.kern,v 1.25 2018/11/15 09:38:57 maxv Exp $
#
# kernel sources
@@ -174,7 +174,6 @@
file kern/uipc_accf.c kern
file kern/uipc_domain.c kern
file kern/uipc_mbuf.c kern
-file kern/uipc_mbuf2.c kern
file kern/uipc_mbufdebug.c kern & ether
file net/link_proto.c kern # XXX
file kern/uipc_proto.c kern
diff -r e13d3518eeae -r f4c8b5f79c76 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Thu Nov 15 09:23:50 2018 +0000
+++ b/sys/kern/uipc_mbuf.c Thu Nov 15 09:38:57 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.220 2018/10/05 05:06:48 msaitoh Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.221 2018/11/15 09:38:57 maxv Exp $ */
/*
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.220 2018/10/05 05:06:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.221 2018/11/15 09:38:57 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@@ -596,6 +596,27 @@
mowner_ref(m, M_EXT|M_EXT_CLUSTER);
}
+struct mbuf *
+m_getcl(int how, int type, int flags)
+{
+ struct mbuf *mp;
+
+ if ((flags & M_PKTHDR) != 0)
+ mp = m_gethdr(how, type);
+ else
+ mp = m_get(how, type);
+
+ if (mp == NULL)
+ return NULL;
+
+ MCLGET(mp, how);
+ if ((mp->m_flags & M_EXT) != 0)
+ return mp;
+
+ m_free(mp);
+ return NULL;
+}
+
/*
* Utility function for M_PREPEND. Do *NOT* use it directly.
*/
@@ -1016,6 +1037,167 @@
}
/*
+ * ensure that [off, off + len) is contiguous on the mbuf chain "m".
+ * packet chain before "off" is kept untouched.
+ * if offp == NULL, the target will start at <retval, 0> on resulting chain.
+ * if offp != NULL, the target will start at <retval, *offp> on resulting chain.
+ *
+ * on error return (NULL return value), original "m" will be freed.
+ *
+ * XXX M_TRAILINGSPACE/M_LEADINGSPACE on shared cluster (sharedcluster)
+ */
+struct mbuf *
+m_pulldown(struct mbuf *m, int off, int len, int *offp)
+{
+ struct mbuf *n, *o;
+ int hlen, tlen, olen;
+ int sharedcluster;
+
+ /* Check invalid arguments. */
+ if (m == NULL)
+ panic("%s: m == NULL", __func__);
+ if (len > MCLBYTES) {
+ m_freem(m);
+ return NULL;
+ }
+
+ n = m;
+ while (n != NULL && off > 0) {
+ if (n->m_len > off)
+ break;
+ off -= n->m_len;
+ n = n->m_next;
+ }
+ /* Be sure to point non-empty mbuf. */
+ while (n != NULL && n->m_len == 0)
+ n = n->m_next;
+ if (!n) {
+ m_freem(m);
+ return NULL; /* mbuf chain too short */
+ }
+
+ sharedcluster = M_READONLY(n);
+
+ /*
+ * The target data is on <n, off>. If we got enough data on the mbuf
+ * "n", we're done.
+ */
+#ifdef __NO_STRICT_ALIGNMENT
+ if ((off == 0 || offp) && len <= n->m_len - off && !sharedcluster)
+#else
+ if ((off == 0 || offp) && len <= n->m_len - off && !sharedcluster &&
+ ALIGNED_POINTER((mtod(n, char *) + off), uint32_t))
+#endif
+ goto ok;
+
+ /*
+ * When (len <= n->m_len - off) and (off != 0), it is a special case.
+ * Len bytes from <n, off> sit in single mbuf, but the caller does
+ * not like the starting position (off).
+ *
+ * Chop the current mbuf into two pieces, set off to 0.
+ */
+ if (len <= n->m_len - off) {
+ struct mbuf *mlast;
+
+ o = m_dup(n, off, n->m_len - off, M_DONTWAIT);
+ if (o == NULL) {
+ m_freem(m);
+ return NULL; /* ENOBUFS */
+ }
+ KASSERT(o->m_len >= len);
+ for (mlast = o; mlast->m_next != NULL; mlast = mlast->m_next)
+ ;
+ n->m_len = off;
+ mlast->m_next = n->m_next;
+ n->m_next = o;
+ n = o;
+ off = 0;
+ goto ok;
+ }
+
+ /*
+ * We need to take hlen from <n, off> and tlen from <n->m_next, 0>,
+ * and construct contiguous mbuf with m_len == len.
+ *
+ * Note that hlen + tlen == len, and tlen > 0.
+ */
+ hlen = n->m_len - off;
+ tlen = len - hlen;
+
+ /*
+ * Ensure that we have enough trailing data on mbuf chain. If not,
+ * we can do nothing about the chain.
+ */
+ olen = 0;
+ for (o = n->m_next; o != NULL; o = o->m_next)
+ olen += o->m_len;
+ if (hlen + olen < len) {
+ m_freem(m);
+ return NULL; /* mbuf chain too short */
+ }
+
+ /*
+ * Easy cases first. We need to use m_copydata() to get data from
+ * <n->m_next, 0>.
+ */
+ if ((off == 0 || offp) && M_TRAILINGSPACE(n) >= tlen &&
+ !sharedcluster) {
+ m_copydata(n->m_next, 0, tlen, mtod(n, char *) + n->m_len);
+ n->m_len += tlen;
+ m_adj(n->m_next, tlen);
+ goto ok;
+ }
+ if ((off == 0 || offp) && M_LEADINGSPACE(n->m_next) >= hlen &&
+#ifndef __NO_STRICT_ALIGNMENT
+ ALIGNED_POINTER((n->m_next->m_data - hlen), uint32_t) &&
+#endif
+ !sharedcluster && n->m_next->m_len >= tlen) {
+ n->m_next->m_data -= hlen;
+ n->m_next->m_len += hlen;
+ memcpy(mtod(n->m_next, void *), mtod(n, char *) + off, hlen);
+ n->m_len -= hlen;
+ n = n->m_next;
+ off = 0;
+ goto ok;
+ }
+
+ /*
+ * Now, we need to do the hard way. Don't copy as there's no room
+ * on both ends.
+ */
+ o = m_get(M_DONTWAIT, m->m_type);
+ if (o && len > MLEN) {
+ MCLGET(o, M_DONTWAIT);
+ if ((o->m_flags & M_EXT) == 0) {
+ m_free(o);
+ o = NULL;
+ }
+ }
+ if (!o) {
+ m_freem(m);
+ return NULL; /* ENOBUFS */
+ }
+ /* get hlen from <n, off> into <o, 0> */
+ o->m_len = hlen;
+ memcpy(mtod(o, void *), mtod(n, char *) + off, hlen);
+ n->m_len -= hlen;
+ /* get tlen from <n->m_next, 0> into <o, hlen> */
+ m_copydata(n->m_next, 0, tlen, mtod(o, char *) + o->m_len);
+ o->m_len += tlen;
+ m_adj(n->m_next, tlen);
+ o->m_next = n->m_next;
+ n->m_next = o;
+ n = o;
+ off = 0;
+
+ok:
+ if (offp)
+ *offp = off;
+ return n;
+}
+
+/*
* Like m_pullup(), except a new mbuf is always allocated, and we allow
* the amount of empty space before the data in the new mbuf to be specified
* (in the event that the caller expects to prepend later).
@@ -1642,6 +1824,115 @@
return NULL;
}
+/*
+ * Release a reference to the mbuf external storage.
+ *
+ * => free the mbuf m itself as well.
+ */
+static void
+m_ext_free(struct mbuf *m)
+{
+ const bool embedded = MEXT_ISEMBEDDED(m);
+ bool dofree = true;
+ u_int refcnt;
+
+ KASSERT((m->m_flags & M_EXT) != 0);
+ KASSERT(MEXT_ISEMBEDDED(m->m_ext_ref));
+ KASSERT((m->m_ext_ref->m_flags & M_EXT) != 0);
+ KASSERT((m->m_flags & M_EXT_CLUSTER) ==
+ (m->m_ext_ref->m_flags & M_EXT_CLUSTER));
+
+ if (__predict_false(m->m_type == MT_FREE)) {
+ panic("mbuf %p already freed", m);
+ }
+
+ if (__predict_true(m->m_ext.ext_refcnt == 1)) {
+ refcnt = m->m_ext.ext_refcnt = 0;
+ } else {
+ refcnt = atomic_dec_uint_nv(&m->m_ext.ext_refcnt);
+ }
+
+ if (refcnt > 0) {
+ if (embedded) {
+ /*
+ * other mbuf's m_ext_ref still points to us.
+ */
+ dofree = false;
+ } else {
+ m->m_ext_ref = m;
+ }
+ } else {
Home |
Main Index |
Thread Index |
Old Index