Message ID | 20220216075533.185693-9-lucas.demarchi@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Random fixes + modinfo --modname | expand |
On Tue, Feb 15, 2022 at 11:55:33PM -0800, Lucas De Marchi wrote: > With the new -m|--modname option it's possible to query the information about this (builtin): Query what information? > $ modinfo --modname crc32 > module explicitly: explicitly seems a bit odd, its not clear if the information below is because its a module or what. Maybe module details? > name: crc32 > filename: (builtin) You know a --is-built-in option might be nice while you're at it. Unless we already have something like this on another tool. Other than that: Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Luis
On Wed, Feb 16, 2022 at 10:47:36AM -0800, Luis Chamberlain wrote: >On Tue, Feb 15, 2022 at 11:55:33PM -0800, Lucas De Marchi wrote: >> With the new -m|--modname option it's possible to query the information about this (builtin): > >Query what information? any of the fields exposed by the module or builtin. The phrase got truncated by wrong copy and paste. See below > >> $ modinfo --modname crc32 >> module explicitly: > >explicitly seems a bit odd, its not clear if the information below >is because its a module or what. Maybe module details? ugh... this was a wrong copy/paste in the commit message. That "module explicitely" is not in the output at all, and was rather part of the previous paragraph. It should had been something like: With the new -m|--modname option it's possible to query the information about this (builtin) module explicitly: $ ./build.new/tools/modinfo --modname crc32 name: crc32 filename: (builtin) license: GPL file: lib/crc32 description: Various CRC32 calculations author: Matt Domsch <Matt_Domsch@dell.com> >> name: crc32 >> filename: (builtin) > >You know a --is-built-in option might be nice while you're at it. >Unless we already have something like this on another tool. to just check if a module is built-in or not? Not sure if it would be in modinfo or modprobe (since modprobe historically got the -R to resolve an alias). > > >Other than that: > >Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> thanks Lucas De Marchi
On Wed, Feb 16, 2022 at 11:57:30AM -0800, Lucas De Marchi wrote: > On Wed, Feb 16, 2022 at 10:47:36AM -0800, Luis Chamberlain wrote: > > > > You know a --is-built-in option might be nice while you're at it. > > Unless we already have something like this on another tool. > > to just check if a module is built-in or not? Yup. > Not sure if it would be in modinfo or modprobe (since modprobe > historically got the -R to resolve an alias). You would know better. But having that would be wonderful. Luis
diff --git a/tools/modinfo.c b/tools/modinfo.c index f51b7e4..d0aab20 100644 --- a/tools/modinfo.c +++ b/tools/modinfo.c @@ -293,6 +293,24 @@ static int modinfo_path_do(struct kmod_ctx *ctx, const char *path) return err; } +static int modinfo_name_do(struct kmod_ctx *ctx, const char *name) +{ + struct kmod_module *mod = NULL; + int err; + + err = kmod_module_new_from_name_lookup(ctx, name, &mod); + if (err < 0 || mod == NULL) { + ERR("Module name %s not found.\n", name); + return err < 0 ? err : -ENOENT; + } + + err = modinfo_do(mod); + kmod_module_unref(mod); + + return err; +} + + static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias) { struct kmod_list *l, *list = NULL; @@ -318,7 +336,7 @@ static int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias) return err; } -static const char cmdopts_s[] = "adlpn0F:k:b:Vh"; +static const char cmdopts_s[] = "adlpn0mF:k:b:Vh"; static const struct option cmdopts[] = { {"author", no_argument, 0, 'a'}, {"description", no_argument, 0, 'd'}, @@ -326,6 +344,7 @@ static const struct option cmdopts[] = { {"parameters", no_argument, 0, 'p'}, {"filename", no_argument, 0, 'n'}, {"null", no_argument, 0, '0'}, + {"modname", no_argument, 0, 'm'}, {"field", required_argument, 0, 'F'}, {"set-version", required_argument, 0, 'k'}, {"basedir", required_argument, 0, 'b'}, @@ -345,6 +364,7 @@ static void help(void) "\t-p, --parameters Print only 'parm'\n" "\t-n, --filename Print only 'filename'\n" "\t-0, --null Use \\0 instead of \\n\n" + "\t-m, --modname Handle argument as module name instead of alias or filename\n" "\t-F, --field=FIELD Print only provided FIELD\n" "\t-k, --set-version=VERSION Use VERSION instead of `uname -r`\n" "\t-b, --basedir=DIR Use DIR as filesystem root for /lib/modules\n" @@ -372,6 +392,7 @@ static int do_modinfo(int argc, char *argv[]) const char *kversion = NULL; const char *root = NULL; const char *null_config = NULL; + bool arg_is_modname = false; int i, err; for (;;) { @@ -398,6 +419,9 @@ static int do_modinfo(int argc, char *argv[]) case '0': separator = '\0'; break; + case 'm': + arg_is_modname = true; + break; case 'F': field = optarg; break; @@ -454,7 +478,9 @@ static int do_modinfo(int argc, char *argv[]) const char *name = argv[i]; int r; - if (is_module_filename(name)) + if (arg_is_modname) + r = modinfo_name_do(ctx, name); + else if (is_module_filename(name)) r = modinfo_path_do(ctx, name); else r = modinfo_alias_do(ctx, name);