From c56b9455f05f760aea6785c47061761bbc76f3b6 Mon Sep 17 00:00:00 2001 From: Cyril Bordage Date: Thu, 29 Sep 2022 17:19:19 +0200 Subject: [PATCH] LU-15944 lnet: remove crash with UDSP The following sequence of commands caused a crash: # lnetctl udsp add --dst tcp --prio 1 # lnetctl discover 192.168.122.60@tcp Pointer to lnet_peer_net in udsp_info is checked before used. Comments about syntax of "lnetctl udsp" command were updated. Test-Parameters: trivial testlist=lnet-selftest,sanity-lnet Signed-off-by: Cyril Bordage Change-Id: Ie3ae40b184e22627655e7f3813c5d16d38a6cfb8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48801 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: Serguei Smirnov Reviewed-by: Frank Sehr Reviewed-by: Oleg Drokin --- lnet/lnet/udsp.c | 21 ++++++++----- lnet/utils/lnetctl.c | 2 +- lustre/tests/sanity-lnet.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/lnet/lnet/udsp.c b/lnet/lnet/udsp.c index bd8efda..e073d12 100644 --- a/lnet/lnet/udsp.c +++ b/lnet/lnet/udsp.c @@ -73,13 +73,17 @@ * from the policy list. * * Generally, the syntax is as follows - * lnetctl policy - * --src: ip2nets syntax specifying the local NID to match - * --dst: ip2nets syntax specifying the remote NID to match - * --rte: ip2nets syntax specifying the router NID to match - * --priority: Priority to apply to rule matches - * --idx: Index of where to insert or delete the rule - * By default add appends to the end of the rule list + * lnetctl udsp add: add a udsp + * --src: ip2nets syntax specifying the local NID to match + * --dst: ip2nets syntax specifying the remote NID to match + * --rte: ip2nets syntax specifying the router NID to match + * --priority: priority value (0 - highest priority) + * --idx: index of where to insert the rule. + * By default, appends to the end of the rule list. + * lnetctl udsp del: delete a udsp + * --idx: index of the Policy. + * lnetctl udsp show: show udsps + * --idx: index of the policy to show. * * Author: Amir Shehata */ @@ -538,7 +542,8 @@ lnet_udsp_apply_rule_on_lpni(struct udsp_info *udi) /* check if looking for a net match */ if (!rc && - (lnet_get_list_len(&lp_match->ud_addr_range) || + (!udi->udi_lpn || + lnet_get_list_len(&lp_match->ud_addr_range) || !cfs_match_net(udi->udi_lpn->lpn_net_id, lp_match->ud_net_id.udn_net_type, &lp_match->ud_net_id.udn_net_num_range))) { diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index d33e386..f908cd8 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -3171,7 +3171,7 @@ static int jt_del_udsp(int argc, char **argv) idx = 0; break; case '?': - print_help(udsp_cmds, "udsp", "add"); + print_help(udsp_cmds, "udsp", "del"); default: return 0; } diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index 976e3e1..ca65bba 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -3353,6 +3353,62 @@ test_302() { } run_test 302 "Check that peer debug info can be dumped" +check_udsp_prio() { + local target_net="${1}" + local target_nid="${2}" + local expect_net="${3}" + local expect_nid="${4}" + local type="${5}" + + declare -a nids + declare -a net_prios + declare -a nid_prios + + nids=( $($LNETCTL ${type} show -v 5 | awk '/- nid:/{print $NF}' | + xargs echo) ) + + net_prios=( $($LNETCTL ${type} show -v 5 | + awk '/net priority:/{print $NF}' | xargs echo) ) + + nid_prios=( $($LNETCTL ${type} show -v 5 | + awk '/nid priority:/{print $NF}' | xargs echo) ) + + (( ${#nids[@]} != ${#net_prios[@]} )) && + error "Wrong # net prios ${#nids[@]} != ${#net_prios[@]}" + + (( ${#nids[@]} != ${#nid_prios[@]} )) && + error "Wrong # nid prios ${#nids[@]} != ${#nid_prios[@]}" + + local i + + for ((i = 0; i < ${#nids[@]}; i++)); do + [[ -n ${target_net} ]] && + [[ ${nids[i]##*@} != "${target_net}" ]] && + continue + [[ -n ${target_nid} ]] && + [[ ${nids[i]} != "${target_nid}" ]] && + continue + + echo "${nids[i]}: net_prio ${net_prios[i]} expect ${expect_net}" + (( net_prios[i] != expect_net )) && + error "Wrong net priority \"${net_prios[i]}\" expect ${expect_net}" + + echo "${nids[i]}: nid_prio ${nid_prios[i]} expect ${expect_nid}" + (( nid_prios[i] != expect_nid )) && + error "Wrong nid priority \"${nid_prios[i]}\" expect ${expect_nid}" + done + + return 0 +} + +check_peer_udsp_prio() { + check_udsp_prio "${1}" "${2}" "${3}" "${4}" "peer" +} + +check_net_udsp_prio() { + check_udsp_prio "${1}" "${2}" "${3}" "${4}" "net" +} + test_400() { reinit_dlc || return $? @@ -3364,6 +3420,24 @@ test_400() { } run_test 400 "Check for udsp add/delete net rule without net num" +test_401() { + reinit_dlc || return $? + + do_lnetctl net add --net ${NETTYPE} --if ${INTERFACES[0]} || + error "Failed to add net" + + do_lnetctl udsp add --dst ${NETTYPE} --prio 1 || + error "Failed to add peer net priority rule" + + do_lnetctl discover $($LCTL list_nids | head -n 1) || + error "Failed to discover peer" + + check_peer_udsp_prio "${NETTYPE}" "" "1" "-1" + + return 0 +} +run_test 401 "Discover peer after adding peer net UDSP rule" + complete $SECONDS cleanup_testsuite -- 1.8.3.1