From 0031ab371ddd0ffda157629fb64c101203a3b1e2 Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Tue, 5 Dec 2023 01:38:12 -0600 Subject: [PATCH] LU-9680 lnet: Empty route/peer table is not an error lnetctl peer/route show command, without any other arguments, should not return an error if the peer/route tables are empty. If the user specifies a particular peer/route to show, and that peer/route does not exist then this is an error. Modify the dumpit routines to check the netlink message length to determine whether the user supplied any arguments to the show commands, and use this information to return the proper status. Some dead code was also removed from lnet_route_show_dump(). We also fix an issue with older kernels where non-zero return status from old dumpit commands was not being returned correctly. Test-Parameters: trivial Signed-off-by: Chris Horn Change-Id: I9a188c573b0f373052208dbea52ea56181719769 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53366 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Serguei Smirnov Reviewed-by: James Simmons --- lnet/lnet/api-ni.c | 47 ++++++++++++++++++++++++----------------------- lnet/selftest/conctl.c | 5 ++++- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 0afcf81..60a2f93 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -5016,7 +5016,10 @@ static int lnet_old_cpt_of_nid_show_dump(struct sk_buff *msg, int rc = lnet_cpt_of_nid_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lnet_cpt_of_nid_show_dump(msg, cb); @@ -5778,7 +5781,10 @@ static int lnet_old_net_show_dump(struct sk_buff *msg, int rc = lnet_net_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lnet_net_show_dump(msg, cb); @@ -6800,6 +6806,7 @@ static int lnet_route_show_dump(struct sk_buff *msg, int portid = NETLINK_CB(cb->skb).portid; int seq = cb->nlh->nlmsg_seq; int idx = rlist->lgrl_index; + int msg_len = genlmsg_len(gnlh); int rc = 0; #ifdef HAVE_NL_DUMP_WITH_EXT_ACK @@ -6807,7 +6814,7 @@ static int lnet_route_show_dump(struct sk_buff *msg, #endif if (!rlist->lgrl_count) { NL_SET_ERR_MSG(extack, "No routes found"); - GOTO(send_error, rc = -ENOENT); + GOTO(send_error, rc = msg_len ? -ENOENT : 0); } if (!idx) { @@ -6825,22 +6832,6 @@ static int lnet_route_show_dump(struct sk_buff *msg, } } - /* If not routes found send an empty message and not an error */ - if (!rlist->lgrl_count) { - void *hdr; - - hdr = genlmsg_put(msg, portid, seq, &lnet_family, - NLM_F_MULTI, LNET_CMD_ROUTES); - if (!hdr) { - NL_SET_ERR_MSG(extack, "failed to send values"); - genlmsg_cancel(msg, hdr); - GOTO(send_error, rc = -EMSGSIZE); - } - genlmsg_end(msg, hdr); - - goto send_error; - } - while (idx < rlist->lgrl_count) { struct lnet_route_properties *prop; void *hdr; @@ -6890,7 +6881,10 @@ static int lnet_old_route_show_dump(struct sk_buff *msg, int rc = lnet_route_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lnet_route_show_dump(msg, cb); @@ -7227,6 +7221,7 @@ static int lnet_peer_ni_show_dump(struct sk_buff *msg, int portid = NETLINK_CB(cb->skb).portid; int seq = cb->nlh->nlmsg_seq; int idx = plist->lgpl_index; + int msg_len = genlmsg_len(gnlh); int rc = 0; #ifdef HAVE_NL_DUMP_WITH_EXT_ACK @@ -7234,7 +7229,7 @@ static int lnet_peer_ni_show_dump(struct sk_buff *msg, #endif if (!plist->lgpl_count) { NL_SET_ERR_MSG(extack, "No peers found"); - GOTO(send_error, rc = -ENOENT); + GOTO(send_error, rc = msg_len ? -ENOENT : 0); } if (!idx) { @@ -7506,7 +7501,10 @@ static int lnet_old_peer_ni_show_dump(struct sk_buff *msg, int rc = lnet_peer_ni_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lnet_peer_ni_show_dump(msg, cb); @@ -8155,7 +8153,10 @@ static int lnet_old_ping_show_dump(struct sk_buff *msg, int rc = lnet_ping_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lnet_ping_show_dump(msg, cb); diff --git a/lnet/selftest/conctl.c b/lnet/selftest/conctl.c index 0bd81d4..b9faaff 100644 --- a/lnet/selftest/conctl.c +++ b/lnet/selftest/conctl.c @@ -1355,7 +1355,10 @@ static int lst_old_groups_show_dump(struct sk_buff *msg, int rc = lst_groups_show_start(cb); if (rc < 0) - return rc; + return lnet_nl_send_error(cb->skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + rc); } return lst_groups_show_dump(msg, cb); -- 1.8.3.1