From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A5B2BA046B for ; Wed, 24 Jul 2019 18:29:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 75EBB1C222; Wed, 24 Jul 2019 18:29:16 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id E79081C218 for ; Wed, 24 Jul 2019 18:29:14 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id s1so15180450pgr.2 for ; Wed, 24 Jul 2019 09:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4o4+XoIn8520vUuSq7qE4meynJspd1AnVZuzgfZicWQ=; b=zGHsAyGRLZoeuq8/FxkyhAfQJhfUNsT66XZYotW0TbtrCGQXYgNn77fuXToioyvw6h ueI32uLqBf9qwNHmzPhMkXCXGHUepP8ky8bx+VOjurwr0J4LaXK6kjLmhx8JmsRirc8m Vfsjh5Bi12A/4d1d3akeuTbZ4GZElefTVjbIAT3mtIvfUJDoRMgxzuwFqfiewq6SDAw9 RScrW+MoARyDWn6osn5lSi4lSWh0x7HpB/HDtd8LW1g1eLZO11gN+0gZVXd2xquKeJLR 1ATLyVawOMzIGhYiCzP47GA3rB5OD6JyybOk+NDOc/qeUHl6RPJOzeeV5U92I3T1vmm+ f9tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4o4+XoIn8520vUuSq7qE4meynJspd1AnVZuzgfZicWQ=; b=p2UhKCsVxTMgZ2rYID1bSiSGhGhFjm3Uw4aCp2Wd24uc6LWGGZSVjYfnH8gT6AK1Sn meTHqOUsg+2Y8cJkCBke4LpKck7jfUXtY/Nus+1JXLT9VhWMfNw+Kf7MFhaJRy51YtTA g2zXbUCmU6bVrOhZgIM2671SEtjifLd5TEpEZQYBWKVJYzH4jHPA62QYidzBFyRKEJJN UXdIqf0+QEUfBWQCVRktYpF0hrgjYAlI67Gh6tekIyQd6tpEWju7tRAzTR3Y0RnDa1Zl B7a06gMHmVk6X6lNI2CDjBLLj2Kv1ascjG3DEPQkxVdU1IAoTABaW0BCLJPY75wgFX9g pphg== X-Gm-Message-State: APjAAAV8GmEjtnTlHEtelK/t86n3bA1hvEAS5gLa0CKCDhE+mWb5pqQ3 XHEvsoJh7bwd9r8HI8nFdM8= X-Google-Smtp-Source: APXvYqzIWnB/IaFkM/63B7Awqyl616axvlh3Zi7dVfJ2+wFTE6C5IvwtyfvSh4kZ35krR3DPJMx2ew== X-Received: by 2002:a62:6083:: with SMTP id u125mr11951198pfb.208.1563985754182; Wed, 24 Jul 2019 09:29:14 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id g6sm41316325pgh.64.2019.07.24.09.29.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 09:29:14 -0700 (PDT) Date: Wed, 24 Jul 2019 09:29:12 -0700 From: Stephen Hemminger To: Anatoly Burakov Cc: dev@dpdk.org, john.mcnamara@intel.com, thomas@monjalon.net Message-ID: <20190724092912.303e8844@hermes.lan> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 1/2] usertools/devbind: add error on forgetting to specify driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 24 Jul 2019 16:34:43 +0100 Anatoly Burakov 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 > --- > 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.