From cdc97ad749b541ea2e2f1c0b5b9bc35c37762877 Mon Sep 17 00:00:00 2001 From: Amir Shehata Date: Fri, 24 Jul 2015 14:14:38 -0700 Subject: [PATCH] LU-6851 lnet: Ignore hops if not explicitly set Since the # of hops is not a mandatory parameter the LU-6060 patch will cause problems to already existing systems since it changes the behavior by which a route is determined down. To fix this case the # of hops now defaults to LNET_UNDEFINED_HOPS if no hop count is specified. LNET_UNDEFINED_HOPS is defined to ((__u32)-1). When it's printed as %d, it displays as -1. __u32 is used through out the call stack for hop count to explicitly define the size of the hop count and to avoid any sizing issues when passing data to and from the kernel. To keep existing behavior both lnet_compare_routes() and LNetDist() will treat undefined hop count as hop count 1. When executing the logic in lnet_parse_rc_info() there is no longer an assumption that the default hop count is 1. If the hop count is 1 then it must've been explicitly set by the user. Signed-off-by: Amir Shehata Change-Id: I1a28a35a4edc2437cf95cb9d455e59c8102736fa Reviewed-on: http://review.whamcloud.com/15719 Tested-by: Jenkins Reviewed-by: Olaf Weber Tested-by: Maloo Reviewed-by: Doug Oucharek Reviewed-by: Oleg Drokin --- lnet/include/lnet/lib-dlc.h | 1 + lnet/include/lnet/lib-lnet.h | 2 +- lnet/include/lnet/lib-types.h | 2 +- lnet/lnet/config.c | 6 ++++-- lnet/lnet/lib-move.c | 27 ++++++++++++++++++--------- lnet/lnet/router.c | 6 +++--- lnet/lnet/router_proc.c | 2 +- lnet/utils/lnetconfig/liblnetconfig.c | 6 +++--- lnet/utils/portals.c | 7 ++++--- 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lnet/include/lnet/lib-dlc.h b/lnet/include/lnet/lib-dlc.h index 77b15b8..2ec20b4 100644 --- a/lnet/include/lnet/lib-dlc.h +++ b/lnet/include/lnet/lib-dlc.h @@ -33,6 +33,7 @@ #define MAX_NUM_SHOW_ENTRIES 32 #define LNET_MAX_STR_LEN 128 #define LNET_MAX_SHOW_NUM_CPT 128 +#define LNET_UNDEFINED_HOPS ((__u32) -1) struct lnet_ioctl_net_config { char ni_interfaces[LNET_MAX_INTERFACES][LNET_MAX_STR_LEN]; diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index fa1fd33..7a82b11 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -464,7 +464,7 @@ extern int portal_rotor; int lnet_notify(lnet_ni_t *ni, lnet_nid_t peer, int alive, cfs_time_t when); void lnet_notify_locked(lnet_peer_t *lp, int notifylnd, int alive, cfs_time_t when); -int lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway_nid, +int lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway_nid, unsigned int priority); int lnet_check_routes(void); int lnet_del_route(__u32 net, lnet_nid_t gw_nid); diff --git a/lnet/include/lnet/lib-types.h b/lnet/include/lnet/lib-types.h index 95e42ed..678851f 100644 --- a/lnet/include/lnet/lib-types.h +++ b/lnet/include/lnet/lib-types.h @@ -402,7 +402,7 @@ typedef struct { __u32 lr_net; /* remote network number */ int lr_seq; /* sequence for round-robin */ unsigned int lr_downis; /* number of down NIs */ - unsigned int lr_hops; /* how far I am */ + __u32 lr_hops; /* how far I am */ unsigned int lr_priority; /* route priority */ } lnet_route_t; diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 815ac6d..37340d9 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -676,7 +676,7 @@ lnet_parse_route (char *str, int *im_a_router) char *token = str; int ntokens = 0; int myrc = -1; - unsigned int hops; + __u32 hops; int got_hops = 0; unsigned int priority = 0; @@ -759,8 +759,10 @@ lnet_parse_route (char *str, int *im_a_router) } } + /* if there are no hops set then we want to flag this value as + * unset since hops is an optional parameter */ if (!got_hops) - hops = 1; + hops = LNET_UNDEFINED_HOPS; LASSERT(!list_empty(&nets)); LASSERT(!list_empty(&gateways)); diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index 7f5c0e8..ee2ab6f 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -1142,6 +1142,8 @@ lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2) { lnet_peer_t *p1 = r1->lr_gateway; lnet_peer_t *p2 = r2->lr_gateway; + int r1_hops = (r1->lr_hops == LNET_UNDEFINED_HOPS) ? 1 : r1->lr_hops; + int r2_hops = (r2->lr_hops == LNET_UNDEFINED_HOPS) ? 1 : r2->lr_hops; if (r1->lr_priority < r2->lr_priority) return 1; @@ -1149,10 +1151,10 @@ lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2) if (r1->lr_priority > r2->lr_priority) return -1; - if (r1->lr_hops < r2->lr_hops) + if (r1_hops < r2_hops) return 1; - if (r1->lr_hops > r2->lr_hops) + if (r1_hops > r2_hops) return -1; if (p1->lp_txqnob < p2->lp_txqnob) @@ -2511,22 +2513,29 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp) if (rnet->lrn_net == dstnet) { lnet_route_t *route; lnet_route_t *shortest = NULL; + __u32 shortest_hops = LNET_UNDEFINED_HOPS; + __u32 route_hops; LASSERT(!list_empty(&rnet->lrn_routes)); list_for_each_entry(route, &rnet->lrn_routes, lr_list) { + route_hops = route->lr_hops; + if (route_hops == LNET_UNDEFINED_HOPS) + route_hops = 1; if (shortest == NULL || - route->lr_hops < shortest->lr_hops) + route_hops < shortest_hops) { shortest = route; + shortest_hops = route_hops; + } } - LASSERT (shortest != NULL); - hops = shortest->lr_hops; - if (srcnidp != NULL) - *srcnidp = shortest->lr_gateway->lp_ni->ni_nid; - if (orderp != NULL) - *orderp = order; + LASSERT(shortest != NULL); + hops = shortest_hops; + if (srcnidp != NULL) + *srcnidp = shortest->lr_gateway->lp_ni->ni_nid; + if (orderp != NULL) + *orderp = order; lnet_net_unlock(cpt); return hops + 1; } diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 072adcc..4b47269 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -293,7 +293,7 @@ lnet_add_route_to_rnet(lnet_remotenet_t *rnet, lnet_route_t *route) } int -lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway, +lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, unsigned int priority) { struct list_head *e; @@ -304,7 +304,7 @@ lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway, int add_route; int rc; - CDEBUG(D_NET, "Add route: net %s hops %u priority %u gw %s\n", + CDEBUG(D_NET, "Add route: net %s hops %d priority %u gw %s\n", libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway)); if (gateway == LNET_NID_ANY || @@ -312,7 +312,7 @@ lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway, net == LNET_NIDNET(LNET_NID_ANY) || LNET_NETTYP(net) == LOLND || LNET_NIDNET(gateway) == net || - hops < 1 || hops > 255) + (hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255))) return -EINVAL; if (lnet_islocalnet(net)) /* it's a local network */ diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index 0fe5a3f..f58fc27 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -222,7 +222,7 @@ proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer, if (route != NULL) { __u32 net = rnet->lrn_net; - unsigned int hops = route->lr_hops; + __u32 hops = route->lr_hops; unsigned int priority = route->lr_priority; lnet_nid_t nid = route->lr_gateway->lp_nid; int alive = lnet_is_route_alive(route); diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 6cae18b..625e5fa 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -143,12 +143,12 @@ int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio, } if (hops == -1) { - /* -1 indicates to use the default hop value */ - hops = 1; + /* hops is undefined */ + hops = LNET_UNDEFINED_HOPS; } else if (hops < 1 || hops > 255) { snprintf(err_str, sizeof(err_str), - "\"invalid hop count %d, must be between 0 and 256\"", + "\"invalid hop count %d, must be between 1 and 255\"", hops); rc = LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM; goto out; diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 8778f81..facea69 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -1063,7 +1063,7 @@ jt_ptl_add_route (int argc, char **argv) { struct lnet_ioctl_config_data data; lnet_nid_t gateway_nid; - unsigned int hops = 1; + __u32 hops = LNET_UNDEFINED_HOPS; unsigned int priority = 0; char *end; int rc; @@ -1084,8 +1084,9 @@ jt_ptl_add_route (int argc, char **argv) } if (argc > 2) { - hops = strtoul(argv[2], &end, 0); - if (hops == 0 || hops >= 256 || (end != NULL && *end != 0)) { + hops = strtol(argv[2], &end, 0); + if (hops == 0 || hops >= 256 || + (end != NULL && *end != 0)) { fprintf(stderr, "Can't parse hopcount \"%s\"\n", argv[2]); return -1; -- 1.8.3.1