- Move large functions m_getjcl() and m_get2() to kern/uipc_mbuf.c

- style(9) fixes to mbuf.h

Reviewed by:	bde
This commit is contained in:
glebius 2013-01-24 09:29:41 +00:00
parent 9a5e009c74
commit fd20cedd21
2 changed files with 83 additions and 101 deletions

View File

@ -84,6 +84,79 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, m_defragrandomfailures, CTLFLAG_RW,
&m_defragrandomfailures, 0, "");
#endif
/*
* m_get2() allocates minimum mbuf that would fit "size" argument.
*/
struct mbuf *
m_get2(int how, short type, int flags, int size)
{
struct mb_args args;
struct mbuf *m, *n;
uma_zone_t zone;
args.flags = flags;
args.type = type;
if (size <= MHLEN || (size <= MLEN && (flags & M_PKTHDR) == 0))
return (uma_zalloc_arg(zone_mbuf, &args, how));
if (size <= MCLBYTES)
return (uma_zalloc_arg(zone_pack, &args, how));
if (size > MJUM16BYTES)
return (NULL);
m = uma_zalloc_arg(zone_mbuf, &args, how);
if (m == NULL)
return (NULL);
#if MJUMPAGESIZE != MCLBYTES
if (size <= MJUMPAGESIZE)
zone = zone_jumbop;
else
#endif
if (size <= MJUM9BYTES)
zone = zone_jumbo9;
else
zone = zone_jumbo16;
n = uma_zalloc_arg(zone, m, how);
if (n == NULL) {
uma_zfree(zone_mbuf, m);
return (NULL);
}
return (m);
}
/*
* m_getjcl() returns an mbuf with a cluster of the specified size attached.
* For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES.
*/
struct mbuf *
m_getjcl(int how, short type, int flags, int size)
{
struct mb_args args;
struct mbuf *m, *n;
uma_zone_t zone;
if (size == MCLBYTES)
return m_getcl(how, type, flags);
args.flags = flags;
args.type = type;
m = uma_zalloc_arg(zone_mbuf, &args, how);
if (m == NULL)
return (NULL);
zone = m_getzone(size);
n = uma_zalloc_arg(zone, m, how);
if (n == NULL) {
uma_zfree(zone_mbuf, m);
return (NULL);
}
return (m);
}
/*
* Allocate a given length worth of mbufs and/or clusters (whatever fits
* best) and return a pointer to the top of the allocated chain. If an

View File

@ -392,23 +392,8 @@ extern uma_zone_t zone_jumbo9;
extern uma_zone_t zone_jumbo16;
extern uma_zone_t zone_ext_refcnt;
static __inline struct mbuf *m_getcl(int how, short type, int flags);
static __inline struct mbuf *m_get(int how, short type);
static __inline struct mbuf *m_get2(int how, short type, int flags,
u_int size);
static __inline struct mbuf *m_gethdr(int how, short type);
static __inline struct mbuf *m_getjcl(int how, short type, int flags,
int size);
static __inline struct mbuf *m_getclr(int how, short type); /* XXX */
static __inline int m_init(struct mbuf *m, uma_zone_t zone,
int size, int how, short type, int flags);
static __inline struct mbuf *m_free(struct mbuf *m);
static __inline void m_clget(struct mbuf *m, int how);
static __inline void *m_cljget(struct mbuf *m, int how, int size);
static __inline void m_chtype(struct mbuf *m, short new_type);
void mb_free_ext(struct mbuf *);
static __inline struct mbuf *m_last(struct mbuf *m);
int m_pkthdr_init(struct mbuf *m, int how);
void mb_free_ext(struct mbuf *);
int m_pkthdr_init(struct mbuf *, int);
static __inline int
m_gettype(int size)
@ -501,7 +486,7 @@ m_get(int how, short type)
args.flags = 0;
args.type = type;
return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
return (uma_zalloc_arg(zone_mbuf, &args, how));
}
/*
@ -528,7 +513,7 @@ m_gethdr(int how, short type)
args.flags = M_PKTHDR;
args.type = type;
return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
return (uma_zalloc_arg(zone_mbuf, &args, how));
}
static __inline struct mbuf *
@ -538,85 +523,7 @@ m_getcl(int how, short type, int flags)
args.flags = flags;
args.type = type;
return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how)));
}
/*
* m_get2() allocates minimum mbuf that would fit "size" argument.
*
* XXX: This is rather large, should be real function maybe.
*/
static __inline struct mbuf *
m_get2(int how, short type, int flags, u_int size)
{
struct mb_args args;
struct mbuf *m, *n;
uma_zone_t zone;
args.flags = flags;
args.type = type;
if (size <= MHLEN || (size <= MLEN && (flags & M_PKTHDR) == 0))
return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
if (size <= MCLBYTES)
return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how)));
if (size > MJUM16BYTES)
return (NULL);
m = uma_zalloc_arg(zone_mbuf, &args, how);
if (m == NULL)
return (NULL);
#if MJUMPAGESIZE != MCLBYTES
if (size <= MJUMPAGESIZE)
zone = zone_jumbop;
else
#endif
if (size <= MJUM9BYTES)
zone = zone_jumbo9;
else
zone = zone_jumbo16;
n = uma_zalloc_arg(zone, m, how);
if (n == NULL) {
uma_zfree(zone_mbuf, m);
return (NULL);
}
return (m);
}
/*
* m_getjcl() returns an mbuf with a cluster of the specified size attached.
* For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES.
*
* XXX: This is rather large, should be real function maybe.
*/
static __inline struct mbuf *
m_getjcl(int how, short type, int flags, int size)
{
struct mb_args args;
struct mbuf *m, *n;
uma_zone_t zone;
if (size == MCLBYTES)
return m_getcl(how, type, flags);
args.flags = flags;
args.type = type;
m = uma_zalloc_arg(zone_mbuf, &args, how);
if (m == NULL)
return (NULL);
zone = m_getzone(size);
n = uma_zalloc_arg(zone, m, how);
if (n == NULL) {
uma_zfree(zone_mbuf, m);
return (NULL);
}
return (m);
return (uma_zalloc_arg(zone_pack, &args, how));
}
static __inline void
@ -880,7 +787,7 @@ struct mbuf *m_copymdata(struct mbuf *, struct mbuf *,
int, int, int, int);
struct mbuf *m_copypacket(struct mbuf *, int);
void m_copy_pkthdr(struct mbuf *, struct mbuf *);
struct mbuf *m_copyup(struct mbuf *n, int len, int dstoff);
struct mbuf *m_copyup(struct mbuf *, int, int);
struct mbuf *m_defrag(struct mbuf *, int);
void m_demote(struct mbuf *, int);
struct mbuf *m_devget(char *, int, int, struct ifnet *,
@ -890,6 +797,8 @@ int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
u_int m_fixhdr(struct mbuf *);
struct mbuf *m_fragment(struct mbuf *, int, int);
void m_freem(struct mbuf *);
struct mbuf *m_get2(int, short, int, int);
struct mbuf *m_getjcl(int, short, int, int);
struct mbuf *m_getm2(struct mbuf *, int, int, short, int);
struct mbuf *m_getptr(struct mbuf *, int, int *);
u_int m_length(struct mbuf *, struct mbuf **);
@ -899,10 +808,10 @@ struct mbuf *m_prepend(struct mbuf *, int, int);
void m_print(const struct mbuf *, int);
struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
struct mbuf *m_pullup(struct mbuf *, int);
int m_sanity(struct mbuf *, int);
int m_sanity(struct mbuf *, int);
struct mbuf *m_split(struct mbuf *, int, int);
struct mbuf *m_uiotombuf(struct uio *, int, int, int, int);
struct mbuf *m_unshare(struct mbuf *, int how);
struct mbuf *m_unshare(struct mbuf *, int);
/*-
* Network packets may have annotations attached by affixing a list of