Module Name: src
Committed By: pgoyette
Date: Sun Mar 11 00:44:32 UTC 2018
Modified Files:
src/share/man/man9 [pgoyette-compat]: module.9
src/sys/kern [pgoyette-compat]: kern_module.c sys_module.c
src/sys/sys [pgoyette-compat]: module.h
Log Message:
Store the aliases list in the mod_info struct, since it is totally
static data. This saves us having to make a special xxx_modcmd()
call to retrieve the data. Update module(9) man page accordingly.
To generate a diff of this commit:
cvs rdiff -u -r1.42.2.2 -r1.42.2.3 src/share/man/man9/module.9
cvs rdiff -u -r1.130 -r1.130.2.1 src/sys/kern/kern_module.c
cvs rdiff -u -r1.23 -r1.23.2.1 src/sys/kern/sys_module.c
cvs rdiff -u -r1.41.14.2 -r1.41.14.3 src/sys/sys/module.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/man/man9/module.9
diff -u src/share/man/man9/module.9:1.42.2.2 src/share/man/man9/module.9:1.42.2.3
--- src/share/man/man9/module.9:1.42.2.2 Sat Mar 10 11:34:19 2018
+++ src/share/man/man9/module.9 Sun Mar 11 00:44:32 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: module.9,v 1.42.2.2 2018/03/10 11:34:19 pgoyette Exp $
+.\" $NetBSD: module.9,v 1.42.2.3 2018/03/11 00:44:32 pgoyette Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -170,9 +170,6 @@ Perform module-specific clean-up before
Notify the module that it is about to be unloaded.
.It Dv MODULE_CMD_STAT
Request the module to provide status information (not currently implemented).
-.It Dv MODULE_CMD_GETALIASES
-Request the module to provide a list of its alias names (typically used
-for included modules).
.El
.Pp
All modules'
@@ -198,14 +195,6 @@ For the
command, the
.Fa data
argument points to a buffer where the status information should be placed.
-For the
-.Dv MODULE_CMD_GETALIASES
-command, the
-.Fa data
-argument points to an array of type
-.Vt const char *[] ;
-the module's command routine should store the addresses of each alias
-name for the module.
.Pp
The __link_set mechanism is used to enable the
.Nm
Index: src/sys/kern/kern_module.c
diff -u src/sys/kern/kern_module.c:1.130 src/sys/kern/kern_module.c:1.130.2.1
--- src/sys/kern/kern_module.c:1.130 Thu Dec 14 22:28:59 2017
+++ src/sys/kern/kern_module.c Sun Mar 11 00:44:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_module.c,v 1.130 2017/12/14 22:28:59 pgoyette Exp $ */
+/* $NetBSD: kern_module.c,v 1.130.2.1 2018/03/11 00:44:32 pgoyette Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130 2017/12/14 22:28:59 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130.2.1 2018/03/11 00:44:32 pgoyette Exp $");
#define _MODULE_INTERNAL
@@ -99,6 +99,7 @@ static int module_fetch_info(module_t *)
static void module_thread(void *);
static module_t *module_lookup(const char *);
+int module_alias_lookup(const char *, module_t *);
static void module_enqueue(module_t *);
static bool module_merge_dicts(prop_dictionary_t, const prop_dictionary_t);
@@ -658,6 +659,25 @@ module_unload(const char *name)
}
/*
+ * module_alias_lookup
+ *
+ * locate a name within a module's alias list
+ */
+int
+module_alias_lookup(const char *name, module_t *mod)
+{
+ const char * const *aliasp;
+
+ aliasp = mod->mod_info->mi_aliases;
+ if (aliasp == NULL)
+ return 0;
+ while (*aliasp)
+ if (strcmp(*aliasp++, name) == 0)
+ return 1;
+ return 0;
+}
+
+/*
* module_lookup:
*
* Look up a module by name.
@@ -672,6 +692,8 @@ module_lookup(const char *name)
TAILQ_FOREACH(mod, &module_list, mod_chain) {
if (strcmp(mod->mod_info->mi_name, name) == 0) {
break;
+ if (module_alias_lookup(name, mod))
+ break;
}
}
@@ -762,6 +784,7 @@ module_do_builtin(const module_t *pmod,
prop_dictionary_t props)
{
const char *p, *s;
+ const char * const *aliasp;
char buf[MAXMODNAME];
modinfo_t *mi = NULL;
module_t *mod, *mod2, *mod_loaded, *prev_active;
@@ -832,6 +855,15 @@ module_do_builtin(const module_t *pmod,
}
/*
+ * Retrieve that none of the module's aliases already exist
+ */
+
+ if ((aliasp = mod->mod_info->mi_aliases) != NULL) {
+ while (*aliasp)
+ if (module_lookup(*aliasp++) != NULL)
+ return EEXIST;
+ }
+ /*
* Try to initialize the module.
*/
prev_active = module_active;
@@ -878,6 +910,7 @@ module_do_load(const char *name, bool is
prop_dictionary_t filedict;
char buf[MAXMODNAME];
const char *s, *p;
+ const char * const *aliasp;
int error;
size_t len;
@@ -1135,6 +1168,17 @@ module_do_load(const char *name, bool is
goto fail;
}
}
+ /*
+ * One last check for duplicate module name/alias
+ */
+ if ((aliasp = mod->mod_info->mi_aliases) != NULL)
+ while (*aliasp != NULL)
+ if (module_lookup(*aliasp) != NULL) {
+ module_error("Module `%s' alias `%s' already "
+ "exists", mod->mod_info->mi_name, *aliasp);
+ goto fail;
+ }
+
prev_active = module_active;
module_active = mod;
error = (*mi->mi_modcmd)(MODULE_CMD_INIT, filedict ? filedict : props);
Index: src/sys/kern/sys_module.c
diff -u src/sys/kern/sys_module.c:1.23 src/sys/kern/sys_module.c:1.23.2.1
--- src/sys/kern/sys_module.c:1.23 Thu Jan 18 13:31:20 2018
+++ src/sys/kern/sys_module.c Sun Mar 11 00:44:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_module.c,v 1.23 2018/01/18 13:31:20 maxv Exp $ */
+/* $NetBSD: sys_module.c,v 1.23.2.1 2018/03/11 00:44:32 pgoyette Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.23 2018/01/18 13:31:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_module.c,v 1.23.2.1 2018/03/11 00:44:32 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_modular.h"
@@ -120,7 +120,9 @@ handle_modctl_stat(struct iovec *iov, vo
size_t size;
size_t mslen;
int error;
+ int mscnt;
bool stataddr;
+ const char * const *aliasp;
/* If not privileged, don't expose kernel addresses. */
error = kauth_authorize_system(kauth_cred_get(), KAUTH_SYSTEM_MODULE,
@@ -128,7 +130,16 @@ handle_modctl_stat(struct iovec *iov, vo
stataddr = (error == 0);
kernconfig_lock();
- mslen = (module_count+module_builtinlist+1) * sizeof(modstat_t);
+ mscnt = 0;
+ TAILQ_FOREACH(mod, &module_list, mod_chain) {
+ mscnt++;
+ mi = mod->mod_info;
+ if ((aliasp = mi->mi_aliases) != NULL) {
+ while (*aliasp++ != NULL)
+ mslen++;
+ }
+ }
+ mslen = (mscnt+module_builtinlist+1) * sizeof(modstat_t);
mso = kmem_zalloc(mslen, KM_SLEEP);
ms = mso;
TAILQ_FOREACH(mod, &module_list, mod_chain) {
@@ -148,6 +159,19 @@ handle_modctl_stat(struct iovec *iov, vo
ms->ms_source = mod->mod_source;
ms->ms_flags = mod->mod_flags;
ms++;
+ aliasp = mi->mi_aliases;
+ if (aliasp == NULL)
+ continue;
+ while (*aliasp) {
+ strlcpy(ms->ms_name, *aliasp, sizeof(ms->ms_name));
+ strlcpy(ms->ms_required, mi->mi_name,
+ sizeof(ms->ms_required));
+ ms->ms_class = mi->mi_class;
+ ms->ms_source = mod->mod_source;
+ ms->ms_flags = mod->mod_flags | MODFLG_IS_ALIAS;
+ aliasp++;
+ ms++;
+ }
}
TAILQ_FOREACH(mod, &module_builtins, mod_chain) {
mi = mod->mod_info;
Index: src/sys/sys/module.h
diff -u src/sys/sys/module.h:1.41.14.2 src/sys/sys/module.h:1.41.14.3
--- src/sys/sys/module.h:1.41.14.2 Sat Mar 10 11:35:44 2018
+++ src/sys/sys/module.h Sun Mar 11 00:44:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: module.h,v 1.41.14.2 2018/03/10 11:35:44 pgoyette Exp $ */
+/* $NetBSD: module.h,v 1.41.14.3 2018/03/11 00:44:32 pgoyette Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,6 @@ typedef enum modcmd {
MODULE_CMD_FINI, /* mandatory */
MODULE_CMD_STAT, /* optional */
MODULE_CMD_AUTOUNLOAD, /* optional */
- MODULE_CMD_GETALIASES, /* optional */
} modcmd_t;
#ifdef _KERNEL
@@ -74,12 +73,12 @@ typedef enum modcmd {
/* Module header structure. */
typedef struct modinfo {
- u_int mi_version;
- modclass_t mi_class;
- int (*mi_modcmd)(modcmd_t, void *);
- const char *mi_name;
- const char *mi_required;
- const char *mi_alias[];
+ u_int mi_version;
+ modclass_t mi_class;
+ int (*mi_modcmd)(modcmd_t, void *);
+ const char *mi_name;
+ const char *mi_required;
+ const char * const *mi_aliases;
} const modinfo_t;
/* Per module information, maintained by kern_module.c */
@@ -154,12 +153,16 @@ static void __CONCAT(moddtor_,name)(void
#endif /* RUMP_USE_CTOR */
#define MODULE(class, name, required) \
+ MODULE_ALIAS(class, name, required, NULL)
+
+#define MODULE_ALIAS(class, name, required, aliases) \
static int __CONCAT(name,_modcmd)(modcmd_t, void *); \
static const modinfo_t __CONCAT(name,_modinfo) = { \
.mi_version = __NetBSD_Version__, \
.mi_class = (class), \
.mi_modcmd = __CONCAT(name,_modcmd), \
.mi_name = __STRING(name), \
+ .mi_aliases = (required), \
.mi_required = (required) \
}; \
_MODULE_REGISTER(name)