Skip to content

Commit 754baf8

Browse files
Alexander Duyckdavem330
authored andcommitted
fib_trie: replace tnode_get_child functions with get_child macros
I am replacing the tnode_get_child call with get_child since we are techically pulling the child out of a key_vector now and not a tnode. Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 35c6eda commit 754baf8

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

net/ipv4/fib_trie.c

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ static struct kmem_cache *trie_leaf_kmem __read_mostly;
159159

160160
/* caller must hold RTNL */
161161
#define node_parent(n) rtnl_dereference((n)->parent)
162+
#define get_child(tn, i) rtnl_dereference((tn)->tnode[i])
162163

163164
/* caller must hold RCU read lock or RTNL */
164165
#define node_parent_rcu(n) rcu_dereference_rtnl((n)->parent)
166+
#define get_child_rcu(tn, i) rcu_dereference_rtnl((tn)->tnode[i])
165167

166168
/* wrapper for rcu_assign_pointer */
167169
static inline void node_set_parent(struct key_vector *n, struct key_vector *tp)
@@ -180,20 +182,6 @@ static inline unsigned long tnode_child_length(const struct key_vector *tn)
180182
return (1ul << tn->bits) & ~(1ul);
181183
}
182184

183-
/* caller must hold RTNL */
184-
static inline struct key_vector *tnode_get_child(struct key_vector *tn,
185-
unsigned long i)
186-
{
187-
return rtnl_dereference(tn->tnode[i]);
188-
}
189-
190-
/* caller must hold RCU read lock or RTNL */
191-
static inline struct key_vector *tnode_get_child_rcu(struct key_vector *tn,
192-
unsigned long i)
193-
{
194-
return rcu_dereference_rtnl(tn->tnode[i]);
195-
}
196-
197185
static inline struct fib_table *trie_get_table(struct trie *t)
198186
{
199187
unsigned long *tb_data = (unsigned long *)t;
@@ -383,7 +371,7 @@ static inline int tnode_full(struct key_vector *tn, struct key_vector *n)
383371
static void put_child(struct key_vector *tn, unsigned long i,
384372
struct key_vector *n)
385373
{
386-
struct key_vector *chi = tnode_get_child(tn, i);
374+
struct key_vector *chi = get_child(tn, i);
387375
int isfull, wasfull;
388376

389377
BUG_ON(i >= tnode_child_length(tn));
@@ -415,7 +403,7 @@ static void update_children(struct key_vector *tn)
415403

416404
/* update all of the child parent pointers */
417405
for (i = tnode_child_length(tn); i;) {
418-
struct key_vector *inode = tnode_get_child(tn, --i);
406+
struct key_vector *inode = get_child(tn, --i);
419407

420408
if (!inode)
421409
continue;
@@ -493,7 +481,7 @@ static struct key_vector __rcu **replace(struct trie *t,
493481

494482
/* resize children now that oldtnode is freed */
495483
for (i = tnode_child_length(tn); i;) {
496-
struct key_vector *inode = tnode_get_child(tn, --i);
484+
struct key_vector *inode = get_child(tn, --i);
497485

498486
/* resize child node */
499487
if (tnode_full(tn, inode))
@@ -525,7 +513,7 @@ static struct key_vector __rcu **inflate(struct trie *t,
525513
* nodes.
526514
*/
527515
for (i = tnode_child_length(oldtnode), m = 1u << tn->pos; i;) {
528-
struct key_vector *inode = tnode_get_child(oldtnode, --i);
516+
struct key_vector *inode = get_child(oldtnode, --i);
529517
struct key_vector *node0, *node1;
530518
unsigned long j, k;
531519

@@ -544,8 +532,8 @@ static struct key_vector __rcu **inflate(struct trie *t,
544532

545533
/* An internal node with two children */
546534
if (inode->bits == 1) {
547-
put_child(tn, 2 * i + 1, tnode_get_child(inode, 1));
548-
put_child(tn, 2 * i, tnode_get_child(inode, 0));
535+
put_child(tn, 2 * i + 1, get_child(inode, 1));
536+
put_child(tn, 2 * i, get_child(inode, 0));
549537
continue;
550538
}
551539

@@ -575,10 +563,10 @@ static struct key_vector __rcu **inflate(struct trie *t,
575563

576564
/* populate child pointers in new nodes */
577565
for (k = tnode_child_length(inode), j = k / 2; j;) {
578-
put_child(node1, --j, tnode_get_child(inode, --k));
579-
put_child(node0, j, tnode_get_child(inode, j));
580-
put_child(node1, --j, tnode_get_child(inode, --k));
581-
put_child(node0, j, tnode_get_child(inode, j));
566+
put_child(node1, --j, get_child(inode, --k));
567+
put_child(node0, j, get_child(inode, j));
568+
put_child(node1, --j, get_child(inode, --k));
569+
put_child(node0, j, get_child(inode, j));
582570
}
583571

584572
/* link new nodes to parent */
@@ -620,8 +608,8 @@ static struct key_vector __rcu **halve(struct trie *t,
620608
* nodes.
621609
*/
622610
for (i = tnode_child_length(oldtnode); i;) {
623-
struct key_vector *node1 = tnode_get_child(oldtnode, --i);
624-
struct key_vector *node0 = tnode_get_child(oldtnode, --i);
611+
struct key_vector *node1 = get_child(oldtnode, --i);
612+
struct key_vector *node0 = get_child(oldtnode, --i);
625613
struct key_vector *inode;
626614

627615
/* At least one of the children is empty */
@@ -661,7 +649,7 @@ static void collapse(struct trie *t, struct key_vector *oldtnode)
661649

662650
/* scan the tnode looking for that one child that might still exist */
663651
for (n = NULL, i = tnode_child_length(oldtnode); !n && i;)
664-
n = tnode_get_child(oldtnode, --i);
652+
n = get_child(oldtnode, --i);
665653

666654
/* compress one level */
667655
tp = node_parent(oldtnode);
@@ -683,7 +671,7 @@ static unsigned char update_suffix(struct key_vector *tn)
683671
* represent the nodes with suffix length equal to tn->pos
684672
*/
685673
for (i = 0, stride = 0x2ul ; i < tnode_child_length(tn); i += stride) {
686-
struct key_vector *n = tnode_get_child(tn, i);
674+
struct key_vector *n = get_child(tn, i);
687675

688676
if (!n || (n->slen <= slen))
689677
continue;
@@ -942,7 +930,7 @@ static struct key_vector *fib_find_node(struct trie *t,
942930
break;
943931

944932
pn = n;
945-
n = tnode_get_child_rcu(n, index);
933+
n = get_child_rcu(n, index);
946934
}
947935

948936
*tp = pn;
@@ -1000,7 +988,7 @@ static int fib_insert_node(struct trie *t, struct key_vector *tp,
1000988

1001989
/* retrieve child from parent node */
1002990
if (tp)
1003-
n = tnode_get_child(tp, get_index(key, tp));
991+
n = get_child(tp, get_index(key, tp));
1004992
else
1005993
n = rcu_dereference_rtnl(t->tnode[0]);
1006994

@@ -1309,7 +1297,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
13091297
cindex = index;
13101298
}
13111299

1312-
n = tnode_get_child_rcu(n, index);
1300+
n = get_child_rcu(n, index);
13131301
if (unlikely(!n))
13141302
goto backtrace;
13151303
}
@@ -1551,7 +1539,7 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key)
15511539
cindex = idx;
15521540

15531541
/* descend into the next child */
1554-
n = tnode_get_child_rcu(pn, cindex++);
1542+
n = get_child_rcu(pn, cindex++);
15551543
}
15561544

15571545
/* this loop will search for the next leaf with a greater key */
@@ -1569,7 +1557,7 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key)
15691557
}
15701558

15711559
/* grab the next available node */
1572-
n = tnode_get_child_rcu(pn, cindex++);
1560+
n = get_child_rcu(pn, cindex++);
15731561
if (!n)
15741562
continue;
15751563

@@ -1624,7 +1612,7 @@ void fib_table_flush_external(struct fib_table *tb)
16241612
}
16251613

16261614
/* grab the next available node */
1627-
n = tnode_get_child(pn, cindex);
1615+
n = get_child(pn, cindex);
16281616
} while (!n);
16291617
}
16301618

@@ -1690,7 +1678,7 @@ int fib_table_flush(struct fib_table *tb)
16901678
}
16911679

16921680
/* grab the next available node */
1693-
n = tnode_get_child(pn, cindex);
1681+
n = get_child(pn, cindex);
16941682
} while (!n);
16951683
}
16961684

@@ -1887,7 +1875,7 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter)
18871875
iter->tnode, iter->index, iter->depth);
18881876
rescan:
18891877
while (cindex < tnode_child_length(tn)) {
1890-
struct key_vector *n = tnode_get_child_rcu(tn, cindex);
1878+
struct key_vector *n = get_child_rcu(tn, cindex);
18911879

18921880
if (n) {
18931881
if (IS_LEAF(n)) {

0 commit comments

Comments
 (0)