All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Anatoly Burakov <anatoly.burakov@intel.com>
Cc: dev@dpdk.org, john.mcnamara@intel.com, thomas@monjalon.net
Subject: Re: [dpdk-dev] [PATCH 1/2] usertools/devbind: add error on forgetting to specify driver
Date: Wed, 24 Jul 2019 09:29:12 -0700	[thread overview]
Message-ID: <20190724092912.303e8844@hermes.lan> (raw)
In-Reply-To: <af7e62fabfaf49ab854550e80d6b780dc5719807.1563982007.git.anatoly.burakov@intel.com>

On Wed, 24 Jul 2019 16:34:43 +0100
Anatoly Burakov <anatoly.burakov@intel.com> wrote:

> A common user error is to forget driver to which the PCI devices should
> be bound to. Currently, the error message in this case looks unhelpful
> misleading and indecipherable to anyone but people who know how devbind
> works.
> 
> Fix this by checking if the driver string is actually a valid device
> string. If it is, we assume that the user has just forgot to specify the
> driver, and display appropriate error. We also assume that no one will
> name their driver in a format that looks like a PCI address, but that
> seems like a reasonable assumption to make.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  usertools/dpdk-devbind.py | 33 ++++++++++++++++++++++++++++-----
>  1 file changed, 28 insertions(+), 5 deletions(-)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 542ecffcc..f7c4c6434 100755
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> @@ -342,9 +342,8 @@ def dev_id_from_dev_name(dev_name):
>              if dev_name in devices[d]["Interface"].split(","):
>                  return devices[d]["Slot"]
>      # if nothing else matches - error
> -    print("Unknown device: %s. "
> -          "Please specify device in \"bus:slot.func\" format" % dev_name)
> -    sys.exit(1)
> +    raise ValueError("Unknown device: %s. "
> +	    "Please specify device in \"bus:slot.func\" format" % dev_name)
>  
>  
>  def unbind_one(dev_id, force):
> @@ -493,7 +492,12 @@ def unbind_all(dev_list, force=False):
>                      unbind_one(devices[d]["Slot"], force)
>          return
>  
> -    dev_list = map(dev_id_from_dev_name, dev_list)
> +    try:
> +        dev_list = map(dev_id_from_dev_name, dev_list)
> +    except ValueError as ex:
> +        print(ex)
> +        sys.exit(1)
> +
>      for d in dev_list:
>          unbind_one(d, force)
>  
> @@ -502,7 +506,26 @@ def bind_all(dev_list, driver, force=False):
>      """Bind method, takes a list of device locations"""
>      global devices
>  
> -    dev_list = map(dev_id_from_dev_name, dev_list)
> +    # a common user error is to forget to specify the driver the devices need to
> +    # be bound to. check if the driver is a valid device, and if it is, show
> +    # a meaningful error.
> +    try:
> +        dev_id_from_dev_name(driver)
> +        # if we've made it this far, this means that the "driver" was a valid
> +        # device string, so it's probably not a valid driver name.
> +        print("ERROR: Driver '%s' does not look like a valid driver. "
> +              "Did you forget to specify the driver to bind devices to?" %
> +              driver)
> +        sys.exit(1)
> +    except ValueError:
> +        # driver generated error - it's not a valid device ID, so all is well
> +        pass
> +
> +    try:
> +        dev_list = map(dev_id_from_dev_name, dev_list)
> +    except ValueError as ex:
> +        print(ex)
> +        sys.exit(1)
>  
>      for d in dev_list:
>          bind_one(d, driver, force)

It would be better print error messages to stderr.
If you call sys.exit() with a string it will do that.

  reply	other threads:[~2019-07-24 16:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 15:34 [dpdk-dev] [PATCH 0/2] Small usability improvements for devbind Anatoly Burakov
2019-07-24 15:34 ` [dpdk-dev] [PATCH 1/2] usertools/devbind: add error on forgetting to specify driver Anatoly Burakov
2019-07-24 16:29   ` Stephen Hemminger [this message]
2019-07-24 16:47     ` Burakov, Anatoly
2019-07-24 15:34 ` [dpdk-dev] [PATCH 2/2] usertools/devbind: check if module is loaded before binding Anatoly Burakov
2019-07-24 16:28   ` Stephen Hemminger
2019-07-24 16:47     ` Burakov, Anatoly
2019-07-25 13:48 ` [dpdk-dev] [PATCH v2 0/3] Small usability improvements for devbind Anatoly Burakov
2019-07-25 13:48   ` [dpdk-dev] [PATCH v2 1/3] usertools/devbind: add error on forgetting to specify driver Anatoly Burakov
2019-07-25 13:48   ` [dpdk-dev] [PATCH v2 2/3] usertools/devbind: check if module is loaded before binding Anatoly Burakov
2019-07-25 13:48   ` [dpdk-dev] [PATCH v2 3/3] usertools/devbind: print all errors to stderr Anatoly Burakov
2019-07-25 13:55   ` [dpdk-dev] [PATCH v3 0/3] Small usability improvements for devbind Anatoly Burakov
2019-07-25 13:55     ` [dpdk-dev] [PATCH v3 1/3] usertools/devbind: add error on forgetting to specify driver Anatoly Burakov
2019-07-25 13:55     ` [dpdk-dev] [PATCH v3 2/3] usertools/devbind: check if module is loaded before binding Anatoly Burakov
2019-07-25 13:55     ` [dpdk-dev] [PATCH v3 3/3] usertools/devbind: print all errors to stderr Anatoly Burakov
2019-07-25 14:21     ` [dpdk-dev] [PATCH v4 0/3] Small usability improvements for devbind Anatoly Burakov
2019-07-25 14:21       ` [dpdk-dev] [PATCH v4 1/3] usertools/devbind: add error on forgetting to specify driver Anatoly Burakov
2019-07-25 14:21       ` [dpdk-dev] [PATCH v4 2/3] usertools/devbind: check if module is loaded before binding Anatoly Burakov
2019-07-25 14:21       ` [dpdk-dev] [PATCH v4 3/3] usertools/devbind: print all errors to stderr Anatoly Burakov
2019-07-30 21:52       ` [dpdk-dev] [PATCH v4 0/3] Small usability improvements for devbind Thomas Monjalon

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=20190724092912.303e8844@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=thomas@monjalon.net \
    /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.