return -1;
}
+static void
+my_free_cb(void *addr, void *opaque __rte_unused)
+{
+ rte_free(addr);
+}
+
+static int
+test_shinfo_in_mbuf(struct rte_mempool *pktmbuf_pool)
+{
+ struct rte_mbuf_ext_shared_info *shinfo = NULL;
+ struct rte_mbuf *m2 = NULL;
+ struct rte_mbuf *m = NULL;
+ size_t buf_len = 256;
+ rte_iova_t iova;
+ char *buf = NULL;
+
+ m = rte_pktmbuf_alloc(pktmbuf_pool);
+ printf("%s() m=%p\n", __func__, m);
+ if (m == NULL)
+ GOTO_FAIL("cannot allocate mbuf m");
+ rte_pktmbuf_dump(stdout, m, 0);
+
+ if (rte_pktmbuf_tailroom(m) < sizeof(*shinfo))
+ GOTO_FAIL("tailroom too small");
+
+ buf = rte_malloc(NULL, buf_len, RTE_CACHE_LINE_SIZE);
+ if (buf == NULL)
+ GOTO_FAIL("cannot allocate buffer");
+
+ shinfo = rte_pktmbuf_mtod(m, struct rte_mbuf_ext_shared_info *);
+ shinfo->free_cb = my_free_cb;
+ shinfo->fcb_opaque = NULL;
+ rte_mbuf_ext_refcnt_set(shinfo, 1);
+ iova = rte_malloc_virt2iova(buf);
+ rte_pktmbuf_attach_extbuf(m, buf, iova, buf_len, shinfo);
+ printf("%s() m is attached to the ext buf\n", __func__);
+ rte_pktmbuf_dump(stdout, m, 0);
+
+ m2 = rte_pktmbuf_alloc(pktmbuf_pool);
+ printf("%s() m2=%p\n", __func__, m2);
+ if (m2 == NULL)
+ GOTO_FAIL("cannot allocate mbuf m2");
+ rte_pktmbuf_dump(stdout, m2, 0);
+
+ rte_pktmbuf_attach(m2, m);
+ rte_pktmbuf_dump(stdout, m2, 0);
+ rte_pktmbuf_dump(stdout, m, 0);
+ rte_pktmbuf_free(m);
+ m = NULL;
+
+ m = rte_pktmbuf_alloc(pktmbuf_pool);
+ printf("%s() m=%p\n", __func__, m);
+ if (m == NULL)
+ GOTO_FAIL("cannot allocate mbuf m");
+
+ /* clobber data in the mbuf we just allocated */
+ shinfo = rte_pktmbuf_mtod(m, struct rte_mbuf_ext_shared_info *);
+ shinfo->free_cb = NULL;
+
+ rte_pktmbuf_free(m);
+ m = NULL;
+
+ rte_pktmbuf_free(m2);
+ m2 = NULL;
+
+ printf("done\n");
+ return 0;
+
+
+fail:
+ rte_pktmbuf_free(m2);
+ rte_pktmbuf_free(m);
+ rte_free(buf);
+ return -1;
+}
+
static int
test_mbuf(void)
{
goto err;
}
+ if (test_shinfo_in_mbuf(pktmbuf_pool) < 0) {
+ printf("mbuf shinfo in mbuf failed\n");
+ goto err;
+ }
+
+ if (1) {
+ ret = 0;
+ goto err;
+ }
+
/* test registration of dynamic fields and flags */
if (test_mbuf_dyn(pktmbuf_pool) < 0) {
printf("mbuf dynflag test failed\n");