diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/memif/memif.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c index c2df8d3b12e..c216a165d46 100644 --- a/src/plugins/memif/memif.c +++ b/src/plugins/memif/memif.c @@ -70,6 +70,7 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) { memif_main_t *mm = &memif_main; vnet_main_t *vnm = vnet_get_main (); + vlib_main_t *vm = vlib_get_main (); memif_region_t *mr; memif_queue_t *mq; int i; @@ -126,7 +127,19 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) memif_log_warn (mif, "Unable to unassign interface %d, queue %d: rc=%d", mif->hw_if_index, i, rv); - mq->ring = 0; + if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) + { + + u16 cur_slot,last_slot, start; + u16 ring_size = 1 << mq->log2_ring_size; + u16 mask = ring_size - 1; + cur_slot = mq->last_tail; + last_slot = mq->ring->head - 1 ; + start = (mq->last_tail & mask); + u16 n_slots = ((last_slot - cur_slot) & mask) + 1; + vlib_buffer_free_from_ring(vm,mq->buffers,start,ring_size,n_slots); + } + mq->ring = 0; } } @@ -136,7 +149,28 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err) vec_free (mif->rx_queues); vec_foreach (mq, mif->tx_queues) - memif_queue_intfd_close (mq); + { + if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) + { + memif_ring_t *ring = mq->ring; + u16 cur_slot,last_slot, start; + u16 ring_size = 1 << mq->log2_ring_size; + u16 mask = ring_size - 1; + u16 n_slots = ring->tail - mq->last_tail; + cur_slot = mq->last_tail; + last_slot = mq->ring->head; + start = (mq->last_tail & mask); + if(last_slot > cur_slot) + n_slots = n_slots + ((last_slot - cur_slot)) ; + else if (last_slot < cur_slot) + n_slots = n_slots + (cur_slot - last_slot); + vlib_buffer_free_from_ring_no_next (vm, mq->buffers, + start, + ring_size, n_slots); + } + memif_queue_intfd_close (mq); + } + vec_free (mif->tx_queues); /* free memory regions */ |