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 15D8FA04AF; Thu, 20 Aug 2020 14:24:03 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 437711BEC3; Thu, 20 Aug 2020 14:24:02 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 392F61BEBA for ; Thu, 20 Aug 2020 14:24:00 +0200 (CEST) IronPort-SDR: F8bjkv1d1Xy9pEwvbjKkH0fNGFMLzuQ7PtqTV57nMxawzzFfFIy53iWx9l4P9glRfRIMjZPl8w R5Sd8pLQ2xjA== X-IronPort-AV: E=McAfee;i="6000,8403,9718"; a="142919896" X-IronPort-AV: E=Sophos;i="5.76,332,1592895600"; d="scan'208";a="142919896" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2020 05:23:59 -0700 IronPort-SDR: 64seOw/ji1+F0boWXZQoyounu5QqsmunwgpVEqBHxkxmQxckX9nFNDjU/8bWIrui3/BxZqSzR1 G/Z+U/iaM7+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,332,1592895600"; d="scan'208";a="472634078" Received: from silpixa00399126.ir.intel.com ([10.237.222.56]) by orsmga005.jf.intel.com with ESMTP; 20 Aug 2020 05:23:58 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: anatoly.burakov@intel.com, Bruce Richardson Date: Thu, 20 Aug 2020 13:23:55 +0100 Message-Id: <20200820122355.3357-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards 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" When binding or unbinding a range of devices, it can be useful to use wildcards to specify the devices rather than repeating the same prefix multiple times. We can use the python "glob" module to give us this functionality - at least for PCI devices - by checking /sys for matching files. Examples of use from my system: ./dpdk-devbind.py -b vfio-pci 80:04.* ./dpdk-devbind.py -u 80:04.[2-7] The first example binds eight devices, 80:04.0..80:04.7, to vfio-pci. The second then unbinds six of those devices, 80:04.2..80:04.7, from any driver. Signed-off-by: Bruce Richardson --- usertools/dpdk-devbind.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py index 86b6b53c40..70ed7bce9d 100755 --- a/usertools/dpdk-devbind.py +++ b/usertools/dpdk-devbind.py @@ -8,6 +8,7 @@ import os import getopt import subprocess +from glob import glob from os.path import exists, abspath, dirname, basename if sys.version_info.major < 3: @@ -689,6 +690,16 @@ def parse_args(): else: b_flag = arg + # resolve any PCI globs in the args + new_args = [] + sysfs_path = "/sys/bus/pci/devices/" + for arg in args: + globbed_arg = glob(sysfs_path + arg) + glob(sysfs_path + "0000:" + arg) + if globbed_arg: + new_args.extend([a[len(sysfs_path):] for a in globbed_arg]) + else: + new_args.append(arg) + args = new_args def do_arg_actions(): '''do the actual action requested by the user''' -- 2.25.1