Add a routine for attaching an mbuf to a buffer with an external

refcount.  This one is willing to work with buffers that may already be
referenced.  MEXTADD/m_extadd are suitable only for the first attachment
to a cluster -- they initialize the refcount to 1.
This commit is contained in:
Navdeep Parhar 2013-08-29 23:46:38 +00:00
parent 9f40021f28
commit ba3a81c904

View File

@ -545,6 +545,28 @@ m_gettype(int size)
return (type);
}
/*
* Associated an external reference counted buffer with an mbuf.
*/
static __inline void
m_extaddref(struct mbuf *m, caddr_t buf, u_int size, u_int *ref_cnt,
int (*freef)(struct mbuf *, void *, void *), void *arg1, void *arg2)
{
KASSERT(ref_cnt != NULL, ("%s: ref_cnt not provided", __func__));
atomic_add_int(ref_cnt, 1);
m->m_flags |= M_EXT;
m->m_ext.ext_buf = buf;
m->m_ext.ref_cnt = ref_cnt;
m->m_data = m->m_ext.ext_buf;
m->m_ext.ext_size = size;
m->m_ext.ext_free = freef;
m->m_ext.ext_arg1 = arg1;
m->m_ext.ext_arg2 = arg2;
m->m_ext.ext_type = EXT_EXTREF;
}
static __inline uma_zone_t
m_getzone(int size)
{