Skip to content

Commit

Permalink
Make MBUF_EXT_PGS_ASSERT_SANITY() a macro, so that it prints file:line.
Browse files Browse the repository at this point in the history
While here, stop using struct mbuf_ext_pgs.

Reviewed by:	gallatin
Differential Revision:	https://reviews.freebsd.org/D24598
  • Loading branch information
glebius committed May 3, 2020
1 parent 6fbcdeb commit b363a43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
34 changes: 0 additions & 34 deletions sys/kern/kern_mbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,40 +1145,6 @@ mb_alloc_ext_pgs(int how, m_ext_free_t ext_free)
return (m);
}

#ifdef INVARIANT_SUPPORT
void
mb_ext_pgs_check(struct mbuf *m)
{
struct mbuf_ext_pgs *ext_pgs = &m->m_ext_pgs;

/*
* NB: This expects a non-empty buffer (npgs > 0 and
* last_pg_len > 0).
*/
KASSERT(ext_pgs->npgs > 0,
("ext_pgs with no valid pages: %p", ext_pgs));
KASSERT(ext_pgs->npgs <= nitems(m->m_epg_pa),
("ext_pgs with too many pages: %p", ext_pgs));
KASSERT(ext_pgs->nrdy <= ext_pgs->npgs,
("ext_pgs with too many ready pages: %p", ext_pgs));
KASSERT(ext_pgs->first_pg_off < PAGE_SIZE,
("ext_pgs with too large page offset: %p", ext_pgs));
KASSERT(ext_pgs->last_pg_len > 0,
("ext_pgs with zero last page length: %p", ext_pgs));
KASSERT(ext_pgs->last_pg_len <= PAGE_SIZE,
("ext_pgs with too large last page length: %p", ext_pgs));
if (ext_pgs->npgs == 1) {
KASSERT(ext_pgs->first_pg_off + ext_pgs->last_pg_len <=
PAGE_SIZE, ("ext_pgs with single page too large: %p",
ext_pgs));
}
KASSERT(ext_pgs->hdr_len <= sizeof(m->m_epg_hdr),
("ext_pgs with too large header length: %p", ext_pgs));
KASSERT(ext_pgs->trail_len <= sizeof(m->m_epg_trail),
("ext_pgs with too large header length: %p", ext_pgs));
}
#endif

/*
* Clean up after mbufs with M_EXT storage attached to them if the
* reference count hits 1.
Expand Down
33 changes: 28 additions & 5 deletions sys/sys/mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,36 @@ m_epg_pagelen(const struct mbuf *m, int pidx, int pgoff)
}
}

#ifdef INVARIANT_SUPPORT
void mb_ext_pgs_check(struct mbuf *m);
#endif
#ifdef INVARIANTS
#define MBUF_EXT_PGS_ASSERT_SANITY(m) mb_ext_pgs_check((m))
#define MCHECK(ex, msg) KASSERT((ex), \
("Multi page mbuf %p with " #msg " at %s:%d", \
m, __FILE__, __LINE__))
/*
* NB: This expects a non-empty buffer (npgs > 0 and
* last_pg_len > 0).
*/
#define MBUF_EXT_PGS_ASSERT_SANITY(m) do { \
MCHECK(m->m_ext_pgs.npgs > 0, "no valid pages"); \
MCHECK(m->m_ext_pgs.npgs <= nitems(m->m_epg_pa), \
"too many pages"); \
MCHECK(m->m_ext_pgs.nrdy <= m->m_ext_pgs.npgs, \
"too many ready pages"); \
MCHECK(m->m_ext_pgs.first_pg_off < PAGE_SIZE, \
"too large page offset"); \
MCHECK(m->m_ext_pgs.last_pg_len > 0, "zero last page length"); \
MCHECK(m->m_ext_pgs.last_pg_len <= PAGE_SIZE, \
"too large last page length"); \
if (m->m_ext_pgs.npgs == 1) \
MCHECK(m->m_ext_pgs.first_pg_off + \
m->m_ext_pgs.last_pg_len <= PAGE_SIZE, \
"single page too large"); \
MCHECK(m->m_ext_pgs.hdr_len <= sizeof(m->m_epg_hdr), \
"too large header length"); \
MCHECK(m->m_ext_pgs.trail_len <= sizeof(m->m_epg_trail), \
"too large header length"); \
} while (0)
#else
#define MBUF_EXT_PGS_ASSERT_SANITY(m)
#define MBUF_EXT_PGS_ASSERT_SANITY(m) do {} while (0);
#endif
#endif

Expand Down

0 comments on commit b363a43

Please sign in to comment.