Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move m_align() back into the kernel, and switch M_ALIGN ...



details:   https://anonhg.NetBSD.org/src/rev/9ab842d518da
branches:  trunk
changeset: 446846:9ab842d518da
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Dec 22 13:55:56 2018 +0000

description:
Move m_align() back into the kernel, and switch M_ALIGN and MH_ALIGN to it.
Forcing a distinction between M_ALIGN and MH_ALIGN is too bug-friendly and
serves no particular purpose.

diffstat:

 sys/kern/uipc_mbuf.c            |  32 ++++++++++++++++++++++++++++----
 sys/net80211/ieee80211_netbsd.c |  25 ++-----------------------
 sys/net80211/ieee80211_netbsd.h |   3 +--
 sys/sys/mbuf.h                  |  27 ++++-----------------------
 4 files changed, 35 insertions(+), 52 deletions(-)

diffs (170 lines):

diff -r 4316c9f04afe -r 9ab842d518da sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c      Sat Dec 22 13:11:37 2018 +0000
+++ b/sys/kern/uipc_mbuf.c      Sat Dec 22 13:55:56 2018 +0000
@@ -1,12 +1,12 @@
-/*     $NetBSD: uipc_mbuf.c,v 1.226 2018/12/22 13:11:37 maxv Exp $     */
+/*     $NetBSD: uipc_mbuf.c,v 1.227 2018/12/22 13:55:56 maxv Exp $     */
 
 /*
- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
+ * NASA Ames Research Center, and Maxime Villard.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.226 2018/12/22 13:11:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.227 2018/12/22 13:55:56 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
@@ -1754,6 +1754,30 @@
 }
 
 /*
+ * Set the m_data pointer of a newly-allocated mbuf to place an object of the
+ * specified size at the end of the mbuf, longword aligned.
+ */
+void
+m_align(struct mbuf *m, int len)
+{
+       int buflen, adjust;
+
+       KASSERT(len != M_COPYALL);
+       KASSERT(M_LEADINGSPACE(m) == 0);
+
+       if (m->m_flags & M_EXT)
+               buflen = m->m_ext.ext_size;
+       else if (m->m_flags & M_PKTHDR)
+               buflen = MHLEN;
+       else
+               buflen = MLEN;
+
+       KASSERT(len <= buflen);
+       adjust = buflen - len;
+       m->m_data += adjust &~ (sizeof(long)-1);
+}
+
+/*
  * Apply function f to the data in an mbuf chain starting "off" bytes from the
  * beginning, continuing for "len" bytes.
  */
diff -r 4316c9f04afe -r 9ab842d518da sys/net80211/ieee80211_netbsd.c
--- a/sys/net80211/ieee80211_netbsd.c   Sat Dec 22 13:11:37 2018 +0000
+++ b/sys/net80211/ieee80211_netbsd.c   Sat Dec 22 13:55:56 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.32 2018/09/03 16:29:36 riastradh Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.33 2018/12/22 13:55:56 maxv Exp $ */
 
 /*
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
@@ -31,7 +31,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_freebsd.c,v 1.8 2005/08/08 18:46:35 sam Exp $");
 #else
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.32 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.33 2018/12/22 13:55:56 maxv Exp $");
 #endif
 
 /*
@@ -724,27 +724,6 @@
 /* -------------------------------------------------------------------------- */
 
 /*
- * Set the m_data pointer of a newly-allocated mbuf
- * to place an object of the specified size at the
- * end of the mbuf, longword aligned.
- */
-void
-m_align(struct mbuf *m, int len)
-{
-       int adjust;
-
-       KASSERT(len != M_COPYALL);
-
-       if (m->m_flags & M_EXT)
-               adjust = m->m_ext.ext_size - len;
-       else if (m->m_flags & M_PKTHDR)
-               adjust = MHLEN - len;
-       else
-               adjust = MLEN - len;
-       m->m_data += adjust &~ (sizeof(long)-1);
-}
-
-/*
  * Append the specified data to the indicated mbuf chain,
  * Extend the mbuf chain if the new data does not fit in
  * existing space.
diff -r 4316c9f04afe -r 9ab842d518da sys/net80211/ieee80211_netbsd.h
--- a/sys/net80211/ieee80211_netbsd.h   Sat Dec 22 13:11:37 2018 +0000
+++ b/sys/net80211/ieee80211_netbsd.h   Sat Dec 22 13:55:56 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.h,v 1.21 2018/05/03 17:14:37 maxv Exp $ */
+/* $NetBSD: ieee80211_netbsd.h,v 1.22 2018/12/22 13:55:56 maxv Exp $ */
 /*-
  * Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
  * All rights reserved.
@@ -248,7 +248,6 @@
        static void name(void)
 #endif
 
-void   m_align(struct mbuf *, int);
 int    m_append(struct mbuf *, int, const void *);
 
 #endif /* !_NET80211_IEEE80211_NETBSD_H_ */
diff -r 4316c9f04afe -r 9ab842d518da sys/sys/mbuf.h
--- a/sys/sys/mbuf.h    Sat Dec 22 13:11:37 2018 +0000
+++ b/sys/sys/mbuf.h    Sat Dec 22 13:55:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbuf.h,v 1.215 2018/11/15 11:18:33 maxv Exp $  */
+/*     $NetBSD: mbuf.h,v 1.216 2018/12/22 13:55:56 maxv Exp $  */
 
 /*
  * Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -517,28 +517,8 @@
 #define        M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from)
 #define        M_MOVE_PKTHDR(to, from) m_move_pkthdr(to, from)
 
-/*
- * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
- * an object of the specified size at the end of the mbuf, longword aligned.
- */
-#define        M_ALIGN(m, len)                                                 \
-do {                                                                   \
-       KASSERT(((m)->m_flags & (M_PKTHDR|M_EXT)) == 0);                \
-       KASSERT(M_LEADINGSPACE(m) == 0);                                \
-       (m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1);            \
-} while (/* CONSTCOND */ 0)
-
-/*
- * As above, for mbufs allocated with m_gethdr/MGETHDR
- * or initialized by M_COPY_PKTHDR.
- */
-#define        MH_ALIGN(m, len)                                                \
-do {                                                                   \
-       KASSERT(((m)->m_flags & M_PKTHDR) != 0);                        \
-       KASSERT(((m)->m_flags & M_EXT) == 0);                           \
-       KASSERT(M_LEADINGSPACE(m) == 0);                                \
-       (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1);           \
-} while (/* CONSTCOND */ 0)
+#define M_ALIGN(m, len)                m_align(m, len)
+#define MH_ALIGN(m, len)       m_align(m, len)
 
 /*
  * Determine if an mbuf's data area is read-only.  This is true
@@ -801,6 +781,7 @@
 void   m_remove_pkthdr(struct mbuf *);
 void   m_copy_pkthdr(struct mbuf *, struct mbuf *);
 void   m_move_pkthdr(struct mbuf *, struct mbuf *);
+void   m_align(struct mbuf *, int);
 
 bool   m_ensure_contig(struct mbuf **, int);
 struct mbuf *m_add(struct mbuf *, struct mbuf *);



Home | Main Index | Thread Index | Old Index