diff options
author | Alexander Motin <mav@FreeBSD.org> | 2022-03-08 17:04:42 +0000 |
---|---|---|
committer | Alexander Motin <mav@FreeBSD.org> | 2022-03-08 17:13:51 +0000 |
commit | 5678114cd8b310bd6f0a5699f036fc5b18addd65 (patch) | |
tree | 05574300e2e60d09b00aa2cc725d7a1b9e3d9221 | |
parent | 74c303e4ace2a1aa60b5b3df8af05d6b61d20006 (diff) | |
download | src-5678114cd8b310bd6f0a5699f036fc5b18addd65.tar.gz src-5678114cd8b310bd6f0a5699f036fc5b18addd65.zip |
geom: Allow "load" command for already loaded modules.
I see more user-friendly to do nothing if the module is already
loaded, rather than returning quite confusing error message.
As side effect it allows to avoid std_list_available() call, using
quite expensive on large systems geom_gettree().
MFC after: 1 month
-rw-r--r-- | sbin/geom/core/geom.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index 9d93e9b9989f..b29d73327df8 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -75,6 +75,8 @@ static struct g_command *class_commands = NULL; static struct g_command *find_command(const char *cmdstr, int flags); static void list_one_geom_by_provider(const char *provider_name); static int std_available(const char *name); +static int std_list_available(void); +static int std_load_available(void); static void std_help(struct gctl_req *req, unsigned flags); static void std_list(struct gctl_req *req, unsigned flags); @@ -657,7 +659,7 @@ get_class(int *argc, char ***argv) set_class_name(); /* If we can't load or list, it's not a class. */ - if (!std_available("load") && !std_available("list")) + if (!std_load_available() && !std_list_available()) errx(EXIT_FAILURE, "Invalid class name '%s'.", class_name); if (*argc < 1) @@ -1319,10 +1321,10 @@ std_load_available(void) snprintf(name, sizeof(name), "g_%s", class_name); /* - * If already in kernel, "load" command is not available. + * If already in kernel, "load" command is NOP. */ if (modfind(name) >= 0) - return (0); + return (1); bzero(paths, sizeof(paths)); len = sizeof(paths); if (sysctlbyname("kern.module_path", paths, &len, NULL, 0) < 0) |