All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Kubiak <michal.kubiak@intel.com>
To: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	David Ahern <dsahern@kernel.org>, <netdev@vger.kernel.org>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Lukasz Czapnik <lukasz.czapnik@intel.com>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Subject: Re: [PATCH iproute2-next 2/3] devlink: print missing params even if an unknown one is present
Date: Thu, 4 Jul 2024 15:33:48 +0200	[thread overview]
Message-ID: <ZoakvNeIz2WK33fj@localhost.localdomain> (raw)
In-Reply-To: <20240703131521.60284-3-przemyslaw.kitszel@intel.com>

On Wed, Jul 03, 2024 at 03:15:20PM +0200, Przemek Kitszel wrote:
> Print all of the missing parameters, also in the presence of unknown ones.
> 
> Take for example a correct command:
>     $ devlink resource set pci/0000:01:00.0 path /kvd/linear size 98304
> And remove the "size" keyword:
>     $ devlink resource set pci/0000:01:00.0 path /kvd/linear 98304
> That yields output:
>     Resource size expected.
>     Unknown option "98304"
> 
> Prior to the patch only the last line of output was present. And if user
> would forgot also the "path" keyword, there will be additional line:
>     Resource path expected.
> in the stderr.
> 
> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> ---
>  devlink/devlink.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index 57bcc9658bdb..9907712e3ad0 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
> @@ -1680,26 +1680,28 @@ static const struct dl_args_metadata dl_args_required[] = {
>  static int dl_args_finding_required_validate(uint64_t o_required,
>  					     uint64_t o_found)
>  {
> -	uint64_t o_flag;
> -	int i;
> +	uint64_t o_flag, o_missing = 0;
> +	int i, err = 0;
>  
>  	for (i = 0; i < ARRAY_SIZE(dl_args_required); i++) {
>  		o_flag = dl_args_required[i].o_flag;
>  		if ((o_required & o_flag) && !(o_found & o_flag)) {
> +			o_missing |= o_flag;
>  			pr_err("%s\n", dl_args_required[i].err_msg);
> -			return -ENOENT;
> +			err = -ENOENT;
>  		}
>  	}
> -	if (o_required & ~o_found) {
> +	if (o_required & ~(o_found | o_missing)) {
>  		pr_err("BUG: unknown argument required but not found\n");
>  		return -EINVAL;
>  	}
> -	return 0;
> +	return err;
>  }
>  
>  static int dl_argv_parse(struct dl *dl, uint64_t o_required,
>  			 uint64_t o_optional)
>  {
> +	const char *unknown_option = NULL;
>  	struct dl_opts *opts = &dl->opts;
>  	uint64_t o_all = o_required | o_optional;
>  	char *str = dl_argv_next(dl);
> @@ -2313,8 +2315,9 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
>  			o_found |= DL_OPT_PORT_FN_MAX_IO_EQS;
>  
>  		} else {
> -			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
> -			return -EINVAL;
> +			if (!unknown_option)
> +				unknown_option = dl_argv(dl);
> +			dl_arg_inc(dl);
>  		}
>  	}
>  
> @@ -2325,7 +2328,15 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
>  
>  	opts->present = o_found;
>  
> -	return dl_args_finding_required_validate(o_required, o_found);
> +	err = dl_args_finding_required_validate(o_required, o_found);
> +
> +	if (unknown_option) {
> +		pr_err("Unknown option \"%s\"\n", unknown_option);
> +		if (!err)
> +			return -EINVAL;
> +	}
> +
> +	return err;
>  }
>  
>  static int dl_argv_dry_parse(struct dl *dl, uint64_t o_required,
> -- 
> 2.39.3
> 
> 

Thanks,
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>

  reply	other threads:[~2024-07-04 13:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-03 13:15 [PATCH iproute2-next 0/3] minor improvements to makefile, devlink Przemek Kitszel
2024-07-03 13:15 ` [PATCH iproute2-next 1/3] man: devlink-resource: add missing words in the example Przemek Kitszel
2024-07-04 13:31   ` Michal Kubiak
2024-07-03 13:15 ` [PATCH iproute2-next 2/3] devlink: print missing params even if an unknown one is present Przemek Kitszel
2024-07-04 13:33   ` Michal Kubiak [this message]
2024-07-03 13:15 ` [PATCH iproute2-next 3/3] Makefile: support building from subdirectories Przemek Kitszel
2024-07-03 15:16   ` Stephen Hemminger
2024-07-03 15:28     ` Przemek Kitszel
2024-07-07 16:48   ` David Ahern
2024-07-07 16:50 ` [PATCH iproute2-next 0/3] minor improvements to makefile, devlink patchwork-bot+netdevbpf
2024-07-08 22:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZoakvNeIz2WK33fj@localhost.localdomain \
    --to=michal.kubiak@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=dsahern@kernel.org \
    --cc=lukasz.czapnik@intel.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.