From e175dc83c5772438466bafb23a17ceb2e052e1c2 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 5 Mar 2016 13:38:19 -0800 Subject: [PATCH] netdev: Improve comments on netdev_rxq_recv(). The comment was incomplete in some ways and simply wrong in others. Also ensure that *cnt is set to 0 if an error is encountered. It's nice when callers can rely on this. Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- lib/netdev-provider.h | 32 +++++++++++++++++++------------- lib/netdev.c | 32 ++++++++++++++++---------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index 2aa1b5ddd..1952a0249 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -713,23 +713,29 @@ struct netdev_class { void (*rxq_destruct)(struct netdev_rxq *); void (*rxq_dealloc)(struct netdev_rxq *); - /* Attempts to receive batch of packets from 'rx' and place array of - * pointers into '*pkts'. netdev is responsible for allocating buffers. - * '*cnt' points to packet count for given batch. Once packets are returned - * to caller, netdev should give up ownership of ofpbuf data. - * - * Implementations should allocate buffer with DP_NETDEV_HEADROOM headroom - * and add a VLAN header which is obtained out-of-band to the packet. - * - * Caller is expected to pass array of size MAX_RX_BATCH. - * This function may be set to null if it would always return EOPNOTSUPP - * anyhow. */ + /* Attempts to receive a batch of packets from 'rx'. The caller supplies + * 'pkts' as the pointer to the beginning of an array of MAX_RX_BATCH + * pointers to dp_packet. If successful, the implementation stores + * pointers to up to MAX_RX_BATCH dp_packets into the array, transferring + * ownership of the packets to the caller, stores the number of received + * packets into '*cnt', and returns 0. + * + * The implementation does not necessarily initialize any non-data members + * of 'pkts'. That is, the caller must initialize layer pointers and + * metadata itself, if desired, e.g. with pkt_metadata_init() and + * miniflow_extract(). + * + * Implementations should allocate buffers with DP_NETDEV_HEADROOM bytes of + * headroom. + * + * Returns EAGAIN immediately if no packet is ready to be received or + * another positive errno value if an error was encountered. */ int (*rxq_recv)(struct netdev_rxq *rx, struct dp_packet **pkts, int *cnt); /* Registers with the poll loop to wake up from the next call to - * poll_block() when a packet is ready to be received with netdev_rxq_recv() - * on 'rx'. */ + * poll_block() when a packet is ready to be received with + * netdev_rxq_recv() on 'rx'. */ void (*rxq_wait)(struct netdev_rxq *rx); /* Discards all packets waiting to be received from 'rx'. */ diff --git a/lib/netdev.c b/lib/netdev.c index ee92e0115..150f8d851 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -639,28 +639,28 @@ netdev_rxq_close(struct netdev_rxq *rx) } } -/* Attempts to receive batch of packets from 'rx'. - * - * Returns EAGAIN immediately if no packet is ready to be received. - * - * Returns EMSGSIZE, and discards the packet, if the received packet is longer - * than 'dp_packet_tailroom(buffer)'. - * - * It is advised that the tailroom of 'buffer' should be - * VLAN_HEADER_LEN bytes longer than the MTU to allow space for an - * out-of-band VLAN header to be added to the packet. At the very least, - * 'buffer' must have at least ETH_TOTAL_MIN bytes of tailroom. - * - * This function may be set to null if it would always return EOPNOTSUPP - * anyhow. */ +/* Attempts to receive a batch of packets from 'rx'. 'pkts' should point to + * the beginning of an array of MAX_RX_BATCH pointers to dp_packet. If + * successful, this function stores pointers to up to MAX_RX_BATCH dp_packets + * into the array, transferring ownership of the packets to the caller, stores + * the number of received packets into '*cnt', and returns 0. + * + * The implementation does not necessarily initialize any non-data members of + * 'pkts'. That is, the caller must initialize layer pointers and metadata + * itself, if desired, e.g. with pkt_metadata_init() and miniflow_extract(). + * + * Returns EAGAIN immediately if no packet is ready to be received or another + * positive errno value if an error was encountered. */ int -netdev_rxq_recv(struct netdev_rxq *rx, struct dp_packet **buffers, int *cnt) +netdev_rxq_recv(struct netdev_rxq *rx, struct dp_packet **pkts, int *cnt) { int retval; - retval = rx->netdev->netdev_class->rxq_recv(rx, buffers, cnt); + retval = rx->netdev->netdev_class->rxq_recv(rx, pkts, cnt); if (!retval) { COVERAGE_INC(netdev_received); + } else { + *cnt = 0; } return retval; } -- 2.20.1