DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Yongxin Liu <yongxin.liu@windriver.com>,
	dev@dpdk.org, thomas@monjalon.net
Subject: Re: [dpdk-dev] [PATCH v3] usertools/devbind: fix binding for built-in kernel drivers
Date: Thu, 19 Nov 2020 12:18:30 +0000	[thread overview]
Message-ID: <f47ad3ed-9801-ad4f-64c5-b533ee7d5007@intel.com> (raw)
In-Reply-To: <20201119071646.10052-1-yongxin.liu@windriver.com>

On 19-Nov-20 7:16 AM, Yongxin Liu wrote:
> A driver can be loaded as a dynamic module or a built-in module.
> In commit 681a67288655 ("usertools: check if module is loaded
> before binding"), script only checks modules in /sys/module/.
> 
> However, for built-in kernel driver, it only shows up in /sys/module/,
> if it has a version or at least one parameter. So add check for
> modules in /lib/modules/$(uname -r)/modules.builtin.
> 
> Thanks for Anatoly Burakov's advice.
> 
> Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com>
> ---
> 
> v3:
>   - Add built-in module list in loaded_modules for checking
>     instead of removing error check.
> 
> v2:
>   - fix git commit description style in commit log
>   - fix typo spelling
> 
> ---
>   usertools/dpdk-devbind.py | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
> index 99112b7ab..5b34ccd2a 100755
> --- a/usertools/dpdk-devbind.py
> +++ b/usertools/dpdk-devbind.py
> @@ -181,7 +181,13 @@ def module_is_loaded(module):
>   
>       loaded_modules = sysfs_mods
>   
> -    return module in sysfs_mods
> +    # add built-in modules as loaded
> +    builtin_mods = subprocess.check_output(["cat /lib/modules/$(uname -r)/modules.builtin"], shell=True).splitlines()

I'd rather not call shell directly, it's bad practice and is potentially 
unsafe. The $(uname -r) can be replaced with:

	import platform
	release = platform.uname().release  # equivalent to $(uname -r)

The rest can follow:

	filename = os.path.join("/lib/modules/", release, "modules.builtin")
	# read the file contents, split lines, etc.

Also, please check if file exists to ensure we don't crash the script.

> +    for mod in builtin_mods:
> +        mod_name = os.path.basename(mod.decode("utf8")).split(".ko", 1)

os.path.splitext(os.path.basename(...))?

> +        loaded_modules.append(mod_name[0])
> +
> +    return module in loaded_modules
>   
>   
>   def check_modules():
> 


-- 
Thanks,
Anatoly

  reply	other threads:[~2020-11-19 12:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18  2:58 [dpdk-dev] [PATCH v2] usertools/devbind: fix binding for built-in 1kernel drivers Yongxin Liu
2020-11-18 16:27 ` Burakov, Anatoly
2020-11-19  7:24   ` Liu, Yongxin
2020-11-19  7:16 ` [dpdk-dev] [PATCH v3] usertools/devbind: fix binding for built-in kernel drivers Yongxin Liu
2020-11-19 12:18   ` Burakov, Anatoly [this message]
2020-11-20  2:30     ` Liu, Yongxin
2020-11-20  2:22 ` [dpdk-dev] [PATCH v4] " Yongxin Liu
2020-11-20 10:49   ` Burakov, Anatoly
2020-11-20 11:38   ` Burakov, Anatoly
2020-11-23  3:05 ` [dpdk-dev] [PATCH v5] " Yongxin Liu
2020-12-03  8:25   ` Liu, Yongxin
2021-02-11 10:43     ` Burakov, Anatoly
2021-02-11 22:19       ` 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=f47ad3ed-9801-ad4f-64c5-b533ee7d5007@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yongxin.liu@windriver.com \
    /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 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).