1 From: Alexander Duyck <alexander.h.duyck@redhat.com>
2 Date: Thu, 22 Jan 2015 15:51:45 -0800
3 Subject: [PATCH] fib_trie: Various clean-ups for handling slen
5 While doing further work on the fib_trie I noted a few items.
7 First I was using calls that were far more complicated than they needed to
8 be for determining when to push/pull the suffix length. I have updated the
9 code to reflect the simplier logic.
11 The second issue is that I realised we weren't necessarily handling the
12 case of a leaf_info struct surviving a flush. I have updated the logic so
13 that now we will call pull_suffix in the event of having a leaf info value
14 left in the leaf after flushing it.
16 Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
20 --- a/net/ipv4/fib_trie.c
21 +++ b/net/ipv4/fib_trie.c
22 @@ -917,27 +917,20 @@ static void leaf_push_suffix(struct tnod
24 static void remove_leaf_info(struct tnode *l, struct leaf_info *old)
26 - struct hlist_node *prev;
28 - /* record the location of the pointer to this object */
29 - prev = rtnl_dereference(hlist_pprev_rcu(&old->hlist));
30 + /* record the location of the previous list_info entry */
31 + struct hlist_node **pprev = old->hlist.pprev;
32 + struct leaf_info *li = hlist_entry(pprev, typeof(*li), hlist.next);
34 /* remove the leaf info from the list */
35 hlist_del_rcu(&old->hlist);
37 - /* if we emptied the list this leaf will be freed and we can sort
38 - * out parent suffix lengths as a part of trie_rebalance
40 - if (hlist_empty(&l->list))
41 + /* only access li if it is pointing at the last valid hlist_node */
42 + if (hlist_empty(&l->list) || (*pprev))
45 - /* if we removed the tail then we need to update slen */
46 - if (!rcu_access_pointer(hlist_next_rcu(prev))) {
47 - struct leaf_info *li = hlist_entry(prev, typeof(*li), hlist);
49 - l->slen = KEYLENGTH - li->plen;
50 - leaf_pull_suffix(l);
52 + /* update the trie with the latest suffix length */
53 + l->slen = KEYLENGTH - li->plen;
54 + leaf_pull_suffix(l);
57 static void insert_leaf_info(struct tnode *l, struct leaf_info *new)
58 @@ -961,7 +954,7 @@ static void insert_leaf_info(struct tnod
61 /* if we added to the tail node then we need to update slen */
62 - if (!rcu_access_pointer(hlist_next_rcu(&new->hlist))) {
63 + if (l->slen < (KEYLENGTH - new->plen)) {
64 l->slen = KEYLENGTH - new->plen;
67 @@ -1613,6 +1606,7 @@ static int trie_flush_leaf(struct tnode
68 struct hlist_head *lih = &l->list;
69 struct hlist_node *tmp;
70 struct leaf_info *li = NULL;
71 + unsigned char plen = KEYLENGTH;
73 hlist_for_each_entry_safe(li, tmp, lih, hlist) {
74 found += trie_flush_list(&li->falh);
75 @@ -1620,8 +1614,14 @@ static int trie_flush_leaf(struct tnode
76 if (list_empty(&li->falh)) {
77 hlist_del_rcu(&li->hlist);
85 + l->slen = KEYLENGTH - plen;
90 @@ -1700,13 +1700,22 @@ int fib_table_flush(struct fib_table *tb
91 for (l = trie_firstleaf(t); l; l = trie_nextleaf(l)) {
92 found += trie_flush_leaf(l);
94 - if (ll && hlist_empty(&ll->list))
95 - trie_leaf_remove(t, ll);
97 + if (hlist_empty(&ll->list))
98 + trie_leaf_remove(t, ll);
100 + leaf_pull_suffix(ll);
106 - if (ll && hlist_empty(&ll->list))
107 - trie_leaf_remove(t, ll);
109 + if (hlist_empty(&ll->list))
110 + trie_leaf_remove(t, ll);
112 + leaf_pull_suffix(ll);
115 pr_debug("trie_flush found=%d\n", found);