* [PATCH ethtool 0/2] ethtool-netlink compatibility fixes @ 2020-08-14 13:17 Maxim Mikityanskiy 2020-08-14 13:17 ` [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes Maxim Mikityanskiy 2020-08-14 13:17 ` [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed Maxim Mikityanskiy 0 siblings, 2 replies; 5+ messages in thread From: Maxim Mikityanskiy @ 2020-08-14 13:17 UTC (permalink / raw) To: David S. Miller, Michal Kubecek, Andrew Lunn Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy This series contains fixes for ethtool-netlink to make the behavior similar to the legacy ethtool and avoid regressions caused by differences in behavior between the old and the new tool. Please also see the sibling series for the kernel. Maxim Mikityanskiy (2): netlink: Fix the condition for displaying actual changes netlink: Print and return an error when features weren't changed netlink/features.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) -- 2.21.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes 2020-08-14 13:17 [PATCH ethtool 0/2] ethtool-netlink compatibility fixes Maxim Mikityanskiy @ 2020-08-14 13:17 ` Maxim Mikityanskiy 2020-08-23 15:55 ` Michal Kubecek 2020-08-14 13:17 ` [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed Maxim Mikityanskiy 1 sibling, 1 reply; 5+ messages in thread From: Maxim Mikityanskiy @ 2020-08-14 13:17 UTC (permalink / raw) To: David S. Miller, Michal Kubecek, Andrew Lunn Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy This comment in the code: /* result is not exactly as requested, show differences */ implies that the "Actual changes" output should be displayed only if the result is not as requested, which matches the legacy ethtool behavior. However, in fact, ethtool-netlink displays "actual changes" even when the changes are expected (e.g., one bit was requested, and it was changed as requested). This commit fixes the condition above to make the behavior match the description in the comment and the behavior of the legacy ethtool. The new condition excludes the req_mask bits from active_mask to avoid reacting on bit changes that we asked for. The new condition now matches the ifs in the loop above that print "[requested on/off]" and "[not requested]". Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> --- netlink/features.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlink/features.c b/netlink/features.c index 8b5b858..133529d 100644 --- a/netlink/features.c +++ b/netlink/features.c @@ -413,7 +413,7 @@ static void show_feature_changes(struct nl_context *nlctx, diff = false; for (i = 0; i < words; i++) - if (wanted_mask[i] || active_mask[i]) + if (wanted_mask[i] || (active_mask[i] & ~sfctx->req_mask[i])) diff = true; if (!diff) return; -- 2.21.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes 2020-08-14 13:17 ` [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes Maxim Mikityanskiy @ 2020-08-23 15:55 ` Michal Kubecek 0 siblings, 0 replies; 5+ messages in thread From: Michal Kubecek @ 2020-08-23 15:55 UTC (permalink / raw) To: Maxim Mikityanskiy; +Cc: David S. Miller, Andrew Lunn, Jakub Kicinski, netdev [-- Attachment #1: Type: text/plain, Size: 1530 bytes --] On Fri, Aug 14, 2020 at 04:17:44PM +0300, Maxim Mikityanskiy wrote: > This comment in the code: > > /* result is not exactly as requested, show differences */ > > implies that the "Actual changes" output should be displayed only if the > result is not as requested, which matches the legacy ethtool behavior. > However, in fact, ethtool-netlink displays "actual changes" even when > the changes are expected (e.g., one bit was requested, and it was > changed as requested). > > This commit fixes the condition above to make the behavior match the > description in the comment and the behavior of the legacy ethtool. The > new condition excludes the req_mask bits from active_mask to avoid > reacting on bit changes that we asked for. The new condition now > matches the ifs in the loop above that print "[requested on/off]" and > "[not requested]". > > Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> Applied, thank you. Michal > --- > netlink/features.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/netlink/features.c b/netlink/features.c > index 8b5b858..133529d 100644 > --- a/netlink/features.c > +++ b/netlink/features.c > @@ -413,7 +413,7 @@ static void show_feature_changes(struct nl_context *nlctx, > > diff = false; > for (i = 0; i < words; i++) > - if (wanted_mask[i] || active_mask[i]) > + if (wanted_mask[i] || (active_mask[i] & ~sfctx->req_mask[i])) > diff = true; > if (!diff) > return; > -- > 2.21.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed 2020-08-14 13:17 [PATCH ethtool 0/2] ethtool-netlink compatibility fixes Maxim Mikityanskiy 2020-08-14 13:17 ` [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes Maxim Mikityanskiy @ 2020-08-14 13:17 ` Maxim Mikityanskiy 2020-08-23 16:03 ` Michal Kubecek 1 sibling, 1 reply; 5+ messages in thread From: Maxim Mikityanskiy @ 2020-08-14 13:17 UTC (permalink / raw) To: David S. Miller, Michal Kubecek, Andrew Lunn Cc: Jakub Kicinski, netdev, Maxim Mikityanskiy The legacy ethtool prints an error message and returns 1 if no features were changed as requested. Port this behavior to ethtool-netlink. req_mask is compared to wanted_mask to detect if any feature was changed. If these masks are equal, it means that the kernel hasn't changed anything, and all bits got to wanted. Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> --- netlink/features.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/netlink/features.c b/netlink/features.c index 133529d..4f63fa2 100644 --- a/netlink/features.c +++ b/netlink/features.c @@ -378,7 +378,7 @@ err: return ret; } -static void show_feature_changes(struct nl_context *nlctx, +static bool show_feature_changes(struct nl_context *nlctx, const struct nlattr *const *tb) { struct sfeatures_context *sfctx = nlctx->cmd_private; @@ -388,8 +388,8 @@ static void show_feature_changes(struct nl_context *nlctx, const uint32_t *wanted_val; const uint32_t *active_val; unsigned int count, words; + bool any_changed, diff; unsigned int i; - bool diff; int ret; feature_names = global_stringset(ETH_SS_FEATURES, nlctx->ethnl_socket); @@ -411,12 +411,20 @@ static void show_feature_changes(struct nl_context *nlctx, if (!wanted_val || !wanted_mask || !active_val || !active_mask) goto err; + any_changed = false; diff = false; - for (i = 0; i < words; i++) + for (i = 0; i < words; i++) { + if (wanted_mask[i] != sfctx->req_mask[i]) + any_changed = true; if (wanted_mask[i] || (active_mask[i] & ~sfctx->req_mask[i])) diff = true; + } + if (!any_changed) { + fprintf(stderr, "Could not change any device features\n"); + nlctx->exit_code = 1; + } if (!diff) - return; + return any_changed; /* result is not exactly as requested, show differences */ printf("Actual changes:\n"); @@ -442,9 +450,10 @@ static void show_feature_changes(struct nl_context *nlctx, fputc('\n', stdout); } - return; + return any_changed; err: fprintf(stderr, "malformed diff info from kernel\n"); + return false; } int sfeatures_reply_cb(const struct nlmsghdr *nlhdr, void *data) @@ -471,8 +480,10 @@ int sfeatures_reply_cb(const struct nlmsghdr *nlhdr, void *data) return MNL_CB_OK; } - show_feature_changes(nlctx, tb); - return MNL_CB_OK; + if (show_feature_changes(nlctx, tb)) + return MNL_CB_OK; + else + return MNL_CB_ERROR; } int nl_sfeatures(struct cmd_context *ctx) -- 2.21.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed 2020-08-14 13:17 ` [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed Maxim Mikityanskiy @ 2020-08-23 16:03 ` Michal Kubecek 0 siblings, 0 replies; 5+ messages in thread From: Michal Kubecek @ 2020-08-23 16:03 UTC (permalink / raw) To: Maxim Mikityanskiy; +Cc: David S. Miller, Andrew Lunn, Jakub Kicinski, netdev [-- Attachment #1: Type: text/plain, Size: 1634 bytes --] On Fri, Aug 14, 2020 at 04:17:45PM +0300, Maxim Mikityanskiy wrote: > The legacy ethtool prints an error message and returns 1 if no features > were changed as requested. Port this behavior to ethtool-netlink. > req_mask is compared to wanted_mask to detect if any feature was > changed. If these masks are equal, it means that the kernel hasn't > changed anything, and all bits got to wanted. > > Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com> > --- > netlink/features.c | 25 ++++++++++++++++++------- > 1 file changed, 18 insertions(+), 7 deletions(-) > > diff --git a/netlink/features.c b/netlink/features.c > index 133529d..4f63fa2 100644 > --- a/netlink/features.c > +++ b/netlink/features.c [...] > @@ -471,8 +480,10 @@ int sfeatures_reply_cb(const struct nlmsghdr *nlhdr, void *data) > return MNL_CB_OK; > } > > - show_feature_changes(nlctx, tb); > - return MNL_CB_OK; > + if (show_feature_changes(nlctx, tb)) > + return MNL_CB_OK; > + else > + return MNL_CB_ERROR; I agree with the general change and the code aboved detecting the condition but this kind of error is IMHO not so critical that it would justify bailing out and completely ignoring the final NLMSG_ERROR with kernel return code and possible extack (error/warning message). I would rather suggest to set a flag (e.g. in sfctx) when "no requested change performed" result is detected and leave displaying the error message and setting the exit code after the whole message queue is processed. What do you think? Michal > } > > int nl_sfeatures(struct cmd_context *ctx) > -- > 2.21.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-23 16:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-08-14 13:17 [PATCH ethtool 0/2] ethtool-netlink compatibility fixes Maxim Mikityanskiy 2020-08-14 13:17 ` [PATCH ethtool 1/2] netlink: Fix the condition for displaying actual changes Maxim Mikityanskiy 2020-08-23 15:55 ` Michal Kubecek 2020-08-14 13:17 ` [PATCH ethtool 2/2] netlink: Print and return an error when features weren't changed Maxim Mikityanskiy 2020-08-23 16:03 ` Michal Kubecek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).