From 20ebd771520db301d24c57c22fde989692adf913 Mon Sep 17 00:00:00 2001 From: Pravin Date: Thu, 20 Mar 2014 11:00:14 -0700 Subject: [PATCH] ofpbuf: Add OFPBUF_DPDK type. This will be used by DPDK for zero copy IO. Signed-off-by: Pravin B Shelar --- lib/ofpbuf.c | 7 +++++++ lib/ofpbuf.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 0eed4284d..962857c8d 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -265,6 +265,9 @@ ofpbuf_resize__(struct ofpbuf *b, size_t new_headroom, size_t new_tailroom) new_allocated = new_headroom + b->size + new_tailroom; switch (b->source) { + case OFPBUF_DPDK: + OVS_NOT_REACHED(); + case OFPBUF_MALLOC: if (new_headroom == ofpbuf_headroom(b)) { new_base = xrealloc(b->base, new_allocated); @@ -343,6 +346,8 @@ ofpbuf_prealloc_headroom(struct ofpbuf *b, size_t size) void ofpbuf_trim(struct ofpbuf *b) { + ovs_assert(b->source != OFPBUF_DPDK); + if (b->source == OFPBUF_MALLOC && (ofpbuf_headroom(b) || ofpbuf_tailroom(b))) { ofpbuf_resize__(b, 0, 0); @@ -562,6 +567,8 @@ void * ofpbuf_steal_data(struct ofpbuf *b) { void *p; + ovs_assert(b->source != OFPBUF_DPDK); + if (b->source == OFPBUF_MALLOC && b->data == b->base) { p = b->data; } else { diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h index 7407d8bd3..766298925 100644 --- a/lib/ofpbuf.h +++ b/lib/ofpbuf.h @@ -29,7 +29,8 @@ extern "C" { enum ofpbuf_source { OFPBUF_MALLOC, /* Obtained via malloc(). */ OFPBUF_STACK, /* Un-movable stack space or static buffer. */ - OFPBUF_STUB /* Starts on stack, may expand into heap. */ + OFPBUF_STUB, /* Starts on stack, may expand into heap. */ + OFPBUF_DPDK, /* buffer data is from DPDK allocated memory. */ }; /* Buffer for holding arbitrary data. An ofpbuf is automatically reallocated -- 2.47.0