DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards
@ 2020-08-20 12:23 Bruce Richardson
  2020-08-20 14:44 ` Ferruh Yigit
  2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
  0 siblings, 2 replies; 13+ messages in thread
From: Bruce Richardson @ 2020-08-20 12:23 UTC (permalink / raw)
  To: dev; +Cc: anatoly.burakov, Bruce Richardson

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 <bruce.richardson@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-09-08 21:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 12:23 [dpdk-dev] [PATCH] usertools/dpdk-devbind: add support for PCI wildcards Bruce Richardson
2020-08-20 14:44 ` Ferruh Yigit
2020-08-20 15:43   ` [dpdk-dev] [PATCH v2] " Bruce Richardson
2020-08-21  9:14     ` Burakov, Anatoly
2020-08-24 17:05       ` Bruce Richardson
2020-08-21  9:17     ` Burakov, Anatoly
2020-08-24 16:19       ` Bruce Richardson
2020-08-20 15:43   ` [dpdk-dev] [PATCH] " Bruce Richardson
2020-08-20 15:52   ` [dpdk-dev] [PATCH v3] " Bruce Richardson
2020-08-24 17:04 ` [dpdk-dev] [PATCH v4] " Bruce Richardson
2020-08-28 15:48   ` Ferruh Yigit
2020-09-08 21:44     ` Thomas Monjalon
2020-08-28 16:02   ` Burakov, Anatoly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).