From 9d78f397986ebeeb6c2b6905e39a2ee4204c9bce Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 7 Aug 2024 07:43:01 -0600 Subject: [PATCH] LU-18083 utils: handle more than one peer NI per peer For lnetctl peer list command the loop to parse the returned data from the kernel ended its loop on the first mapping end event. This fails since we can have multiple peer ni nids and each one contains a mapping start and end event. Instead we need to skip everything until we get an sequence end event which has the effect of filtering everything but the primary nids which we want. Second smaller issue is that yaml_lnet_peer_display() can have either an emitter or parser error. If it was a emitter error the code would return back yaml_lnet_peer() would still treat it as an parse error as well which is incorrect. Make yaml_lnet_peere_display() return 0 if its a parser error or -EINVAL if its an emitter error. This way we can handle error reporting in each case separately. Test-Parameters: trivial testlist=sanity-lnet Change-Id: I71372a5b243c5907022a09fb080781d60180dd41 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55944 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: Frank Sehr Reviewed-by: Oleg Drokin --- lnet/utils/lnetctl.c | 14 ++++++-------- lustre/tests/sanity-lnet.sh | 13 +++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 72bdc5c..0120a47 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -3026,17 +3026,14 @@ static int yaml_lnet_peer_display(yaml_parser_t *reply, bool list_only) if (rc == 0) break; - /* skip reset */ - while (event.type != YAML_MAPPING_END_EVENT) { + /* skip ALL peer_ni info */ + while (event.type != YAML_SEQUENCE_END_EVENT) { rc = yaml_parser_parse(reply, &event); if (rc == 0) goto report_reply_error; } - /* we can have map end, seq end, map end or - * just map end event. If we see seq end event - * then skip to next mapping end event - */ + /* But keep sequence end event */ rc = yaml_parser_parse(reply, &event); if (rc == 0) goto report_reply_error; @@ -3065,8 +3062,10 @@ merge_event: yaml_document_delete(&errmsg); } out_err: - if (rc == 0) + if (rc == 0) { yaml_emitter_log_error(&debug, stderr); + rc = -EINVAL; /* Avoid reporting as reply error */ + } report_reply_error: yaml_emitter_delete(&debug); @@ -3449,7 +3448,6 @@ emitter_error: if (msg && strcmp(msg, "No peers found") == 0) rc = 1; } - } yaml_emitter_delete(&output); free_reply: diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index 66ce227..5a203db 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -1084,6 +1084,19 @@ test_27() { } run_test 27 "Import bad config should fail gracefully" +test_28() { + reinit_dlc || return $? + + do_lnetctl peer add --prim_nid 1.1.1.1@tcp --ni 7.7.7.7@tcp || + error "First peer add failed $?" + do_lnetctl peer add --prim_nid 1.1.1.2@tcp --nid 7.7.7.8@tcp || + error "Second peer add failed $?" + + count=$(do_lnetctl peer list | awk '/-\s+nid:/{print $NF}' | wc -l) + [[ $count -eq 2 ]] || error "wrong number of peers reported" +} +run_test 28 "Test peer_list" + test_99a() { reinit_dlc || return $? -- 1.8.3.1