Whamcloud - gitweb
LU-18083 utils: handle more than one peer NI per peer 44/55944/4
authorJames Simmons <jsimmons@infradead.org>
Wed, 7 Aug 2024 13:43:01 +0000 (07:43 -0600)
committerOleg Drokin <green@whamcloud.com>
Fri, 16 Aug 2024 23:50:51 +0000 (23:50 +0000)
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55944
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/lnetctl.c
lustre/tests/sanity-lnet.sh

index 72bdc5c..0120a47 100644 (file)
@@ -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:
index 66ce227..5a203db 100755 (executable)
@@ -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 $?