Fix buggy table-linear iterator function.
authorBen Pfaff <blp@nicira.com>
Mon, 19 May 2008 20:39:24 +0000 (13:39 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 28 May 2008 16:58:22 +0000 (09:58 -0700)
Apparently the linear table iteration had never really been tested,
since most flows go into table-hash.  It didn't work.  This fixes it.

datapath/table-linear.c

index 6634303..68c3aed 100644 (file)
@@ -72,6 +72,7 @@ static int table_linear_insert(struct sw_table *swt, struct sw_flow *flow)
        atomic_inc(&tl->n_flows);
 
        /* Insert the entry immediately in front of where we're pointing. */
+       flow->serial = tl->next_serial++;
        list_add_tail_rcu(&flow->node, &f->node);
        list_add_rcu(&flow->iter_node, &tl->iter_flows);
        spin_unlock_irqrestore(&tl->lock, flags);
@@ -147,12 +148,12 @@ static int table_linear_iterate(struct sw_table *swt,
        struct sw_flow *flow;
        unsigned long start;
 
-       start = ~position->private[0];
+       start = position->private[0];
        list_for_each_entry_rcu (flow, &tl->iter_flows, iter_node) {
-               if (flow->serial <= start && flow_matches(key, &flow->key)) {
+               if (flow->serial >= start && flow_matches(key, &flow->key)) {
                        int error = callback(flow, private);
                        if (error) {
-                               position->private[0] = ~flow->serial;
+                               position->private[0] = flow->serial;
                                return error;
                        }
                }