Module Name: src Committed By: jnemeth Date: Mon May 25 22:33:00 UTC 2009
Modified Files: src/sys/kern: kern_module.c subr_kobj.c src/sys/sys: kobj.h Log Message: Phase 0.5 of my options MODULAR enhancements. As suggested by ad@, these commits move all path handling into module_do_load() from kobj_load_file(). This way the final path used to load a module is available for loading <module>.plist, which will store parameters for a module. The end goal of this project is good support for MODULAR device drivers. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sys/kern/kern_module.c cvs rdiff -u -r1.36 -r1.37 src/sys/kern/subr_kobj.c cvs rdiff -u -r1.9 -r1.10 src/sys/sys/kobj.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_module.c diff -u src/sys/kern/kern_module.c:1.43 src/sys/kern/kern_module.c:1.44 --- src/sys/kern/kern_module.c:1.43 Sun May 24 14:54:17 2009 +++ src/sys/kern/kern_module.c Mon May 25 22:33:00 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.43 2009/05/24 14:54:17 ad Exp $ */ +/* $NetBSD: kern_module.c,v 1.44 2009/05/25 22:33:00 jnemeth 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.43 2009/05/24 14:54:17 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.44 2009/05/25 22:33:00 jnemeth Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -53,6 +53,7 @@ #include <sys/kauth.h> #include <sys/kthread.h> #include <sys/sysctl.h> +#include <sys/namei.h> #include <uvm/uvm_extern.h> @@ -558,7 +559,7 @@ const int maxdepth = 6; modinfo_t *mi; module_t *mod, *mod2; - char buf[MAXMODNAME]; + char buf[MAXMODNAME], *path; const char *s, *p; int error; size_t len; @@ -566,6 +567,7 @@ KASSERT(mutex_owned(&module_lock)); error = 0; + path=NULL; /* * Avoid recursing too far. @@ -616,11 +618,21 @@ depth--; return ENOMEM; } - error = kobj_load_file(&mod->mod_kobj, name, module_base, - autoload); + path = PNBUF_GET(); + if (!autoload) { + snprintf(path, MAXPATHLEN, "%s", name); + error = kobj_load_file(&mod->mod_kobj, path, FOLLOW); + } + if (autoload || (error == ENOENT)) { + snprintf(path, MAXPATHLEN, "%s/%s/%s.kmod", + module_base, name, name); + error = kobj_load_file(&mod->mod_kobj, path, + FOLLOW | NOCHROOT); + } 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); @@ -789,6 +801,8 @@ module_thread_kick(); } depth--; + if (path != NULL) + PNBUF_PUT(path); return 0; fail: @@ -797,6 +811,8 @@ TAILQ_REMOVE(&pending, mod, mod_chain); kmem_free(mod, sizeof(*mod)); depth--; + if (path != NULL) + PNBUF_PUT(path); return error; } Index: src/sys/kern/subr_kobj.c diff -u src/sys/kern/subr_kobj.c:1.36 src/sys/kern/subr_kobj.c:1.37 --- src/sys/kern/subr_kobj.c:1.36 Sun May 24 15:00:24 2009 +++ src/sys/kern/subr_kobj.c Mon May 25 22:33:00 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $ */ +/* $NetBSD: subr_kobj.c,v 1.37 2009/05/25 22:33:00 jnemeth Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.37 2009/05/25 22:33:00 jnemeth Exp $"); #include "opt_modular.h" @@ -103,12 +103,10 @@ * Load an object located in the file system. */ int -kobj_load_file(kobj_t *kop, const char *filename, const char *base, - bool autoload) +kobj_load_file(kobj_t *kop, const char *path, const uint32_t flags) { struct nameidata nd; kauth_cred_t cred; - char *path; int error; kobj_t ko; @@ -119,25 +117,9 @@ return ENOMEM; } - if (autoload) { - error = ENOENT; - } else { - NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename); - error = vn_open(&nd, FREAD, 0); - } - if (error != 0) { - if (error != ENOENT) { - goto out; - } - path = PNBUF_GET(); - snprintf(path, MAXPATHLEN - 1, "%s/%s/%s.kmod", base, - filename, filename); - NDINIT(&nd, LOOKUP, FOLLOW | NOCHROOT, UIO_SYSSPACE, path); - error = vn_open(&nd, FREAD, 0); - PNBUF_PUT(path); - } + NDINIT(&nd, LOOKUP, flags, UIO_SYSSPACE, path); + error = vn_open(&nd, FREAD, 0); - out: if (error != 0) { kmem_free(ko, sizeof(*ko)); return error; @@ -1123,7 +1105,7 @@ #else /* MODULAR */ int -kobj_load_file(kobj_t *kop, const char *name, const char *base, bool autoload) +kobj_load_file(kobj_t *kop, const char *name, const uint32_t flags) { return ENOSYS; Index: src/sys/sys/kobj.h diff -u src/sys/sys/kobj.h:1.9 src/sys/sys/kobj.h:1.10 --- src/sys/sys/kobj.h:1.9 Tue May 20 19:20:38 2008 +++ src/sys/sys/kobj.h Mon May 25 22:33:00 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kobj.h,v 1.9 2008/05/20 19:20:38 ad Exp $ */ +/* $NetBSD: kobj.h,v 1.10 2009/05/25 22:33:00 jnemeth Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ typedef struct kobj *kobj_t; /* External interface. */ -int kobj_load_file(kobj_t *, const char *, const char *, bool); +int kobj_load_file(kobj_t *, const char *, const uint32_t); int kobj_load_mem(kobj_t *, void *, ssize_t); int kobj_affix(kobj_t, const char *); void kobj_unload(kobj_t);