Whamcloud - gitweb
LU-9680 lnet: Empty route/peer table is not an error 66/53366/4
authorChris Horn <chris.horn@hpe.com>
Tue, 5 Dec 2023 07:38:12 +0000 (01:38 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 3 Jan 2024 03:01:51 +0000 (03:01 +0000)
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 <chris.horn@hpe.com>
Change-Id: I9a188c573b0f373052208dbea52ea56181719769
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53366
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
lnet/lnet/api-ni.c
lnet/selftest/conctl.c

index 0afcf81..60a2f93 100644 (file)
@@ -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);
index 0bd81d4..b9faaff 100644 (file)
@@ -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);