git: 5678114cd8b3 - main - geom: Allow "load" command for already loaded modules.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Tue, 08 Mar 2022 17:13:55 UTC
The branch main has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=5678114cd8b310bd6f0a5699f036fc5b18addd65

commit 5678114cd8b310bd6f0a5699f036fc5b18addd65
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-03-08 17:04:42 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-03-08 17:13:51 +0000

    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
---
 sbin/geom/core/geom.c | 8 +++++---
 1 file 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)