diff mbox

[2/6] netdev-odp: refactor error handling in netdev_odp_rxq_recv

Message ID 1426792426-12507-3-git-send-email-zoltan.kiss@linaro.org
State New
Headers show

Commit Message

Zoltan Kiss March 19, 2015, 7:13 p.m. UTC
Refactor how odp_pktio_recv errors handled, including:

- use OVS_(UN)LIKELY
- set *c in error cases
- some code style fix at the definitions
- remove stale printf from the end

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---
 lib/netdev-odp.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/lib/netdev-odp.c b/lib/netdev-odp.c
index a7968dc..385401f 100644
--- a/lib/netdev-odp.c
+++ b/lib/netdev-odp.c
@@ -581,27 +581,28 @@  netdev_odp_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets,
     struct netdev_odp *netdev = netdev_odp_cast(rx->up.netdev);
     int pkts, pkts_ok, ret = 0;
     size_t rx_bytes = 0;
-	unsigned long err_cnt = 0;
-	int i;
-	odp_packet_t pkt_tbl[NETDEV_MAX_RX_BATCH];
+    unsigned long err_cnt = 0;
+    int i;
+    odp_packet_t pkt_tbl[NETDEV_MAX_RX_BATCH];
 
     pkts = odp_pktio_recv(netdev->pktio, pkt_tbl, NETDEV_MAX_RX_BATCH);
-    if (pkts < 0) {
-        return EINVAL;
-    }
-    if (!pkts) {
-        return EAGAIN;
-    }
-
-    if (pkts > 0) {
+    if (OVS_LIKELY(pkts > 0)) {
         pkts_ok = drop_err_pkts(pkt_tbl, pkts);
-        if (odp_unlikely(pkts_ok != pkts))
-            VLOG_ERR("Dropped frames:%u - err_cnt:%lu\n",
+        if (OVS_UNLIKELY(pkts_ok != pkts))
+          VLOG_ERR_RL(&rl, "Dropped frames:%u - err_cnt:%lu\n",
                     pkts-pkts_ok, ++err_cnt);
-        if (!pkts_ok) {
+        if (OVS_UNLIKELY(!pkts_ok)) {
+            VLOG_ERR_RL(&rl, "ODP: All %d packets dropped!\n", pkts);
+            *c = 0;
             ret = EAGAIN;
             goto out_stats;
         }
+    } else {
+        *c = 0;
+        if (!pkts)
+            return EAGAIN;
+        VLOG_ERR_RL(&rl, "ODP: Packet receive error (%d)\n", pkts);
+        return EINVAL;
     }
 
     /* Allocate an ofpbuf for each valid packet */
@@ -620,8 +621,6 @@  netdev_odp_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets,
 
     *c = pkts_ok;
 
-    printf("ODP: received %d packets\n", pkts_ok);
-
 out_stats:
     ovs_mutex_lock(&netdev->mutex);
     netdev->stats.rx_packets += pkts_ok;