diff mbox series

[ethtool,v2] netlink: Print and return an error when features weren't changed

Message ID 20200825081138.10855-1-maximmi@mellanox.com
State Accepted
Delegated to: Michal Kubecek
Headers show
Series [ethtool,v2] netlink: Print and return an error when features weren't changed | expand

Commit Message

Maxim Mikityanskiy Aug. 25, 2020, 8:11 a.m. UTC
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 | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Michal Kubecek Aug. 27, 2020, 9 a.m. UTC | #1
On Tue, Aug 25, 2020 at 11:11:38AM +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>

Applied, thank you.

Michal

> ---
>  netlink/features.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/netlink/features.c b/netlink/features.c
> index 133529d..7622594 100644
> --- a/netlink/features.c
> +++ b/netlink/features.c
> @@ -243,6 +243,7 @@ int nl_gfeatures(struct cmd_context *ctx)
>  /* FEATURES_SET */
>  
>  struct sfeatures_context {
> +	bool			nothing_changed;
>  	uint32_t		req_mask[0];
>  };
>  
> @@ -411,10 +412,14 @@ static void show_feature_changes(struct nl_context *nlctx,
>  	if (!wanted_val || !wanted_mask || !active_val || !active_mask)
>  		goto err;
>  
> +	sfctx->nothing_changed = true;
>  	diff = false;
> -	for (i = 0; i < words; i++)
> +	for (i = 0; i < words; i++) {
> +		if (wanted_mask[i] != sfctx->req_mask[i])
> +			sfctx->nothing_changed = false;
>  		if (wanted_mask[i] || (active_mask[i] & ~sfctx->req_mask[i]))
>  			diff = true;
> +	}
>  	if (!diff)
>  		return;
>  
> @@ -520,6 +525,10 @@ int nl_sfeatures(struct cmd_context *ctx)
>  	if (ret < 0)
>  		return 92;
>  	ret = nlsock_process_reply(nlsk, sfeatures_reply_cb, nlctx);
> +	if (sfctx->nothing_changed) {
> +		fprintf(stderr, "Could not change any device features\n");
> +		return nlctx->exit_code ?: 1;
> +	}
>  	if (ret == 0)
>  		return 0;
>  	return nlctx->exit_code ?: 92;
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/netlink/features.c b/netlink/features.c
index 133529d..7622594 100644
--- a/netlink/features.c
+++ b/netlink/features.c
@@ -243,6 +243,7 @@  int nl_gfeatures(struct cmd_context *ctx)
 /* FEATURES_SET */
 
 struct sfeatures_context {
+	bool			nothing_changed;
 	uint32_t		req_mask[0];
 };
 
@@ -411,10 +412,14 @@  static void show_feature_changes(struct nl_context *nlctx,
 	if (!wanted_val || !wanted_mask || !active_val || !active_mask)
 		goto err;
 
+	sfctx->nothing_changed = true;
 	diff = false;
-	for (i = 0; i < words; i++)
+	for (i = 0; i < words; i++) {
+		if (wanted_mask[i] != sfctx->req_mask[i])
+			sfctx->nothing_changed = false;
 		if (wanted_mask[i] || (active_mask[i] & ~sfctx->req_mask[i]))
 			diff = true;
+	}
 	if (!diff)
 		return;
 
@@ -520,6 +525,10 @@  int nl_sfeatures(struct cmd_context *ctx)
 	if (ret < 0)
 		return 92;
 	ret = nlsock_process_reply(nlsk, sfeatures_reply_cb, nlctx);
+	if (sfctx->nothing_changed) {
+		fprintf(stderr, "Could not change any device features\n");
+		return nlctx->exit_code ?: 1;
+	}
 	if (ret == 0)
 		return 0;
 	return nlctx->exit_code ?: 92;