Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/pgoyette-compat]: src Store the aliases list in the mod_info struct, sin...
details: https://anonhg.NetBSD.org/src/rev/7472f61e0073
branches: pgoyette-compat
changeset: 321004:7472f61e0073
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Sun Mar 11 00:44:32 2018 +0000
description:
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.
diffstat:
share/man/man9/module.9 | 13 +------------
sys/kern/kern_module.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
sys/kern/sys_module.c | 30 +++++++++++++++++++++++++++---
sys/sys/module.h | 19 +++++++++++--------
4 files changed, 85 insertions(+), 25 deletions(-)
diffs (264 lines):
diff -r a872faa65d2a -r 7472f61e0073 share/man/man9/module.9
--- a/share/man/man9/module.9 Sat Mar 10 11:35:44 2018 +0000
+++ b/share/man/man9/module.9 Sun Mar 11 00:44:32 2018 +0000
@@ -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 @@
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 @@
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
diff -r a872faa65d2a -r 7472f61e0073 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c Sat Mar 10 11:35:44 2018 +0000
+++ b/sys/kern/kern_module.c Sun Mar 11 00:44:32 2018 +0000
@@ -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 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_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 @@
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 @@
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 @@
}
/*
+ * 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 @@
prop_dictionary_t filedict;
char buf[MAXMODNAME];
const char *s, *p;
+ const char * const *aliasp;
int error;
size_t len;
@@ -1135,6 +1168,17 @@
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);
diff -r a872faa65d2a -r 7472f61e0073 sys/kern/sys_module.c
--- a/sys/kern/sys_module.c Sat Mar 10 11:35:44 2018 +0000
+++ b/sys/kern/sys_module.c Sun Mar 11 00:44:32 2018 +0000
@@ -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 @@
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 @@
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 @@
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;
diff -r a872faa65d2a -r 7472f61e0073 sys/sys/module.h
--- a/sys/sys/module.h Sat Mar 10 11:35:44 2018 +0000
+++ b/sys/sys/module.h Sun Mar 11 00:44:32 2018 +0000
@@ -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 @@
MODULE_CMD_FINI, /* mandatory */
MODULE_CMD_STAT, /* optional */
MODULE_CMD_AUTOUNLOAD, /* optional */
- MODULE_CMD_GETALIASES, /* optional */
} modcmd_t;
#ifdef _KERNEL
@@ -74,12 +73,12 @@
/* 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 @@
#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)
Home |
Main Index |
Thread Index |
Old Index