ofpbuf: Add OFPBUF_DPDK type.
authorPravin <pshelar@nicira.com>
Thu, 20 Mar 2014 18:00:14 +0000 (11:00 -0700)
committerPravin B Shelar <pshelar@nicira.com>
Fri, 21 Mar 2014 18:48:28 +0000 (11:48 -0700)
This will be used by DPDK for zero copy IO.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
lib/ofpbuf.c
lib/ofpbuf.h

index 0eed428..962857c 100644 (file)
@@ -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 {
index 7407d8b..7662989 100644 (file)
@@ -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