The function tipc_bindtbl_translate() function is ugly. This can be improved somewhat by introducing a stack variable for holding the binding list to be used and re-ordering the if-clauses for selection of algorithm.
Signed-off-by: Jon Maloy <[email protected]> --- net/tipc/binding_table.c | 63 ++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/net/tipc/binding_table.c b/net/tipc/binding_table.c index 521a581..0203297 100644 --- a/net/tipc/binding_table.c +++ b/net/tipc/binding_table.c @@ -403,29 +403,32 @@ struct tipc_binding *tipc_bindtbl_remove_binding(struct net *net, u32 type, /** * tipc_bindtbl_translate - perform service instance to socket translation * - * On entry, 'destnode' is the search domain used during translation. + * On entry, 'dnode' is the search domain used during translation. * * On exit: - * - if name translation is deferred to another node/cluster/zone, - * leaves 'destnode' unchanged (will be non-zero) and returns 0 - * - if name translation is attempted and succeeds, sets 'destnode' - * to binding node and returns port reference (will be non-zero) - * - if name translation is attempted and fails, sets 'destnode' to 0 - * and returns 0 + * - if translation is deferred to another node, leave (non-zero) 'dnode' + * unchanged and return 0 + * - if translation is attempted and succeeds, set 'dnode' to the binding node + * and return the bound (non-zero) port number + * - if translation is attempted and fails, set 'dnode' to 0 and return 0 + * + * Note that for legacy users (node configured with Z.C.N address format) the + * 'closest-first' lookup algorithm must be maintained, i.e., if dnode is 0 + * we must look in the local binding list first */ -u32 tipc_bindtbl_translate(struct net *net, u32 type, u32 instance, - u32 *destnode) +u32 tipc_bindtbl_translate(struct net *net, u32 type, u32 instance, u32 *dnode) { struct tipc_net *tn = tipc_net(net); bool legacy = tn->legacy_addr_format; u32 self = tipc_own_addr(net); struct service_range *sr; - struct tipc_binding *b; struct tipc_service *sc; + struct tipc_binding *b; + struct list_head *list; u32 port = 0; u32 node = 0; - if (!tipc_in_scope(legacy, *destnode, self)) + if (!tipc_in_scope(legacy, *dnode, self)) return 0; rcu_read_lock(); @@ -438,43 +441,29 @@ u32 tipc_bindtbl_translate(struct net *net, u32 type, u32 instance, if (unlikely(!sr)) goto no_match; - /* Closest-First Algorithm */ - if (legacy && !*destnode) { - if (!list_empty(&sr->local_bindings)) { - b = list_first_entry(&sr->local_bindings, - struct tipc_binding, - local_bindings); - list_move_tail(&b->local_bindings, - &sr->local_bindings); - } else { - b = list_first_entry(&sr->all_bindings, - struct tipc_binding, - all_bindings); - list_move_tail(&b->all_bindings, - &sr->all_bindings); - } - } - - /* Round-Robin Algorithm */ - else if (*destnode == self) { - if (list_empty(&sr->local_bindings)) + /* Select lookup algorithm: local, closest-first or round-robin */ + if (*dnode == self) { + list = &sr->local_bindings; + if (list_empty(list)) goto no_match; - b = list_first_entry(&sr->local_bindings, struct tipc_binding, - local_bindings); + b = list_first_entry(list, struct tipc_binding, local_bindings); + list_move_tail(&b->local_bindings, &sr->local_bindings); + } else if (legacy && !*dnode && !list_empty(&sr->local_bindings)) { + list = &sr->local_bindings; + b = list_first_entry(list, struct tipc_binding, local_bindings); list_move_tail(&b->local_bindings, &sr->local_bindings); } else { - b = list_first_entry(&sr->all_bindings, struct tipc_binding, - all_bindings); + list = &sr->all_bindings; + b = list_first_entry(list, struct tipc_binding, all_bindings); list_move_tail(&b->all_bindings, &sr->all_bindings); } - port = b->port; node = b->node; no_match: spin_unlock_bh(&sc->lock); not_found: rcu_read_unlock(); - *destnode = node; + *dnode = node; return port; } -- 2.1.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ tipc-discussion mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tipc-discussion
