Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys * make it possible to include kern_module in a kernel wi...
details: https://anonhg.NetBSD.org/src/rev/6c835856cf86
branches: trunk
changeset: 749123:6c835856cf86
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Nov 18 17:40:45 2009 +0000
description:
* make it possible to include kern_module in a kernel without vfs
support, i.e. move vfs functionality to a separate module
(kern_module_vfs.c)
* make module proplist size an MI constant (now 8k) instead of PAGE_SIZE
* change some error values to something else than the karmic EINVAL
diffstat:
sys/conf/files | 3 +-
sys/kern/kern_module.c | 190 ++++++++----------------------------------
sys/kern/kern_module_vfs.c | 201 +++++++++++++++++++++++++++++++++++++++++++++
sys/sys/module.h | 15 +++-
4 files changed, 253 insertions(+), 156 deletions(-)
diffs (truncated from 573 to 300 lines):
diff -r 385012b3e3a3 -r 6c835856cf86 sys/conf/files
--- a/sys/conf/files Wed Nov 18 17:06:23 2009 +0000
+++ b/sys/conf/files Wed Nov 18 17:40:45 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.963 2009/11/12 18:37:10 snj Exp $
+# $NetBSD: files,v 1.964 2009/11/18 17:40:45 pooka Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20090313
@@ -1438,6 +1438,7 @@
file kern/kern_malloc_stdtype.c
file kern/kern_malloc_debug.c malloc_debug
file kern/kern_module.c
+file kern/kern_module_vfs.c
file kern/kern_mutex.c
file kern/kern_mutex_obj.c
file kern/kern_fileassoc.c fileassoc
diff -r 385012b3e3a3 -r 6c835856cf86 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c Wed Nov 18 17:06:23 2009 +0000
+++ b/sys/kern/kern_module.c Wed Nov 18 17:40:45 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_module.c,v 1.53 2009/11/05 14:09:14 pooka Exp $ */
+/* $NetBSD: kern_module.c,v 1.54 2009/11/18 17:40:45 pooka Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.53 2009/11/05 14:09:14 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.54 2009/11/18 17:40:45 pooka Exp $");
+
+#define _MODULE_INTERNAL
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -44,7 +46,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/fcntl.h>
#include <sys/proc.h>
#include <sys/kauth.h>
#include <sys/kobj.h>
@@ -53,21 +54,18 @@
#include <sys/kauth.h>
#include <sys/kthread.h>
#include <sys/sysctl.h>
-#include <sys/namei.h>
#include <sys/lock.h>
-#include <sys/vnode.h>
-#include <sys/stat.h>
#include <uvm/uvm_extern.h>
#include <machine/stdarg.h>
struct vm_map *module_map;
+char module_base[MODULE_BASE_SIZE];
struct modlist module_list = TAILQ_HEAD_INITIALIZER(module_list);
struct modlist module_bootlist = TAILQ_HEAD_INITIALIZER(module_bootlist);
static module_t *module_active;
-static char module_base[64];
static int module_verbose_on;
static int module_autoload_on = 1;
u_int module_count;
@@ -87,23 +85,28 @@
static int module_do_load(const char *, bool, int, prop_dictionary_t,
module_t **, modclass_t class, bool);
static int module_do_unload(const char *);
-static void module_error(const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
-static void module_print(const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
static int module_do_builtin(const char *, module_t **);
static int module_fetch_info(module_t *);
static void module_thread(void *);
-static int module_load_plist_file(const char *, const bool, void **,
- size_t *);
+
static bool module_merge_dicts(prop_dictionary_t, const prop_dictionary_t);
+int module_eopnotsupp(void);
+
+int
+module_eopnotsupp(void)
+{
+
+ return EOPNOTSUPP;
+}
+__weak_alias(module_load_vfs,module_eopnotsupp);
+
/*
* module_error:
*
* Utility function: log an error.
*/
-static void
+void
module_error(const char *fmt, ...)
{
va_list ap;
@@ -120,7 +123,7 @@
*
* Utility function: log verbose output.
*/
-static void
+void
module_print(const char *fmt, ...)
{
va_list ap;
@@ -601,19 +604,15 @@
modinfo_t *mi;
module_t *mod, *mod2;
prop_dictionary_t filedict;
- void *plist;
- char buf[MAXMODNAME], *path;
+ char buf[MAXMODNAME];
const char *s, *p;
int error;
- size_t len, plistlen;
- bool nochroot;
+ size_t len;
KASSERT(mutex_owned(&module_lock));
filedict = NULL;
- path = NULL;
error = 0;
- nochroot = false;
/*
* Avoid recursing too far.
@@ -664,33 +663,16 @@
depth--;
return ENOMEM;
}
- path = PNBUF_GET();
- if (!autoload) {
- nochroot = false;
- snprintf(path, MAXPATHLEN, "%s", name);
- error = kobj_load_file(&mod->mod_kobj, path, nochroot);
- }
- if (autoload || (error == ENOENT)) {
- nochroot = true;
- snprintf(path, MAXPATHLEN, "%s/%s/%s.kmod",
- module_base, name, name);
- error = kobj_load_file(&mod->mod_kobj, path, nochroot);
- }
+
+ error = module_load_vfs(name, flags, autoload, mod, &filedict);
if (error != 0) {
kmem_free(mod, sizeof(*mod));
depth--;
- PNBUF_PUT(path);
- if (autoload) {
- module_print("Cannot load kernel object `%s'"
- " error=%d", name, error);
- } else {
- module_error("Cannot load kernel object `%s'"
- " error=%d", name, error);
- }
return error;
}
+ mod->mod_source = MODULE_SOURCE_FILESYS;
TAILQ_INSERT_TAIL(&pending, mod, mod_chain);
- mod->mod_source = MODULE_SOURCE_FILESYS;
+
error = module_fetch_info(mod);
if (error != 0) {
module_error("cannot fetch module info for `%s'",
@@ -820,47 +802,27 @@
goto fail2;
}
- /*
- * Load and process <module>.prop if it exists.
- */
- if (((flags & MODCTL_NO_PROP) == 0) &&
- (mod->mod_source == MODULE_SOURCE_FILESYS)) {
- error = module_load_plist_file(path, nochroot, &plist,
- &plistlen);
- if (error != 0) {
- module_print("plist load returned error %d for `%s'",
- error, path);
- } else {
- filedict = prop_dictionary_internalize(plist);
- if (filedict == NULL) {
- error = EINVAL;
- } else if (!module_merge_dicts(filedict, props)) {
- error = EINVAL;
- prop_object_release(filedict);
- filedict = NULL;
- }
- }
- if (plist != NULL) {
- kmem_free(plist, PAGE_SIZE);
- }
- if ((error != 0) && (error != ENOENT)) {
+ if (filedict) {
+ if (!module_merge_dicts(filedict, props)) {
+ module_error("module properties failed");
+ error = EINVAL;
goto fail;
}
}
-
KASSERT(module_active == NULL);
module_active = mod;
- error = (*mi->mi_modcmd)(MODULE_CMD_INIT, (filedict != NULL) ?
- filedict : props); /* props will have been merged with filedict */
+ error = (*mi->mi_modcmd)(MODULE_CMD_INIT, filedict ? filedict : props);
module_active = NULL;
- if (filedict != NULL) {
+ if (filedict) {
prop_object_release(filedict);
+ filedict = NULL;
}
if (error != 0) {
module_error("modcmd function returned error %d for `%s'",
error, mi->mi_name);
goto fail;
}
+
if (mi->mi_class == MODULE_CLASS_SECMODEL)
secmodel_register();
@@ -882,18 +844,18 @@
module_thread_kick();
}
depth--;
- if (path != NULL)
- PNBUF_PUT(path);
return 0;
fail:
kobj_unload(mod->mod_kobj);
fail2:
+ if (filedict != NULL) {
+ prop_object_release(filedict);
+ filedict = NULL;
+ }
TAILQ_REMOVE(&pending, mod, mod_chain);
kmem_free(mod, sizeof(*mod));
depth--;
- if (path != NULL)
- PNBUF_PUT(path);
return error;
}
@@ -1163,86 +1125,6 @@
}
#endif /* DDB */
-/*
- * module_load_plist_file:
- *
- * Load a plist located in the file system into memory.
- */
-static int
-module_load_plist_file(const char *modpath, const bool nochroot,
- void **basep, size_t *length)
-{
- struct nameidata nd;
- struct stat sb;
- void *base;
- char *proppath;
- size_t resid;
- int error, pathlen;
-
- base = NULL;
- *length = 0;
-
- proppath = PNBUF_GET();
- strcpy(proppath, modpath);
- pathlen = strlen(proppath);
- if ((pathlen >= 5) && (strcmp(&proppath[pathlen - 5], ".kmod") == 0)) {
- strcpy(&proppath[pathlen - 5], ".prop");
- } else if (pathlen < MAXPATHLEN - 5) {
- strcat(proppath, ".prop");
- } else {
- error = ENOENT;
- goto out1;
- }
-
- NDINIT(&nd, LOOKUP, FOLLOW | (nochroot ? NOCHROOT : 0),
- UIO_SYSSPACE, proppath);
-
- error = namei(&nd);
- if (error != 0) {
- goto out1;
- }
-
- error = vn_stat(nd.ni_vp, &sb);
- if (sb.st_size >= (PAGE_SIZE - 1)) { /* leave space for term \0 */
- error = EINVAL;
- }
- if (error != 0) {
Home |
Main Index |
Thread Index |
Old Index