mbuf: clarify usage of packet pool initializers

Clarify that the mempool private initializer and object initializer used
for packet pools require that the mempool private size is large enough.

Also add an assert (only enabled when -DRTE_ENABLE_ASSERT is passed) to
check this constraint.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Aaron Conole <aconole@redhat.com>
This commit is contained in:
Olivier Matz 2021-04-27 15:56:46 +02:00 committed by Thomas Monjalon
parent e1064f80b6
commit bd6113858f
2 changed files with 12 additions and 1 deletions

View File

@ -43,6 +43,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
struct rte_pktmbuf_pool_private default_mbp_priv;
uint16_t roomsz;
RTE_ASSERT(mp->private_data_size >=
sizeof(struct rte_pktmbuf_pool_private));
RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
/* if no structure is provided, assume no mbuf private area */
@ -83,6 +85,9 @@ rte_pktmbuf_init(struct rte_mempool *mp,
struct rte_mbuf *m = _m;
uint32_t mbuf_size, buf_len, priv_size;
RTE_ASSERT(mp->private_data_size >=
sizeof(struct rte_pktmbuf_pool_private));
priv_size = rte_pktmbuf_priv_size(mp);
mbuf_size = sizeof(struct rte_mbuf) + priv_size;
buf_len = rte_pktmbuf_data_room_size(mp);

View File

@ -624,6 +624,9 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
* address, and so on). This function is given as a callback function to
* rte_mempool_obj_iter() or rte_mempool_create() at pool creation time.
*
* This function expects that the mempool private area was previously
* initialized with rte_pktmbuf_pool_init().
*
* @param mp
* The mempool from which mbufs originate.
* @param opaque_arg
@ -639,7 +642,7 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
void *m, unsigned i);
/**
* A packet mbuf pool constructor.
* A packet mbuf pool constructor.
*
* This function initializes the mempool private data in the case of a
* pktmbuf pool. This private data is needed by the driver. The
@ -648,6 +651,9 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
* pool creation. It can be extended by the user, for example, to
* provide another packet size.
*
* The mempool private area size must be at least equal to
* sizeof(struct rte_pktmbuf_pool_private).
*
* @param mp
* The mempool from which mbufs originate.
* @param opaque_arg