tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

options MODULAR improvements phase 0.5



     I've been talking with ad@ and cube@ about improvements to options
MODULAR.  My end goal is good support for device driver modules, which
aren't really supported at this moment.  To really do this well will
require the autoconf(9) renovation and devfs.  However, for the moment
I want something that can reasonably be backported to 5.0.  The current
project is to get the kernel to load a <module>.prop file located along
side the <module>.kmod file.  This can be used to store parameters so
that you don't have to specify them every time using modload(8).  Also,
the parameters will get pulled in when a module is autoloaded.  A side
part of this will be to add bootprops so that parameters can be passed
to modules loaded by the boot loader.

     Phase 0 was to add an option to modload(8) to spit out a property
list associated with a set of parameters in order to easily generate a
<module>.prop file.  It was also to make options MODULAR work on my
primary developement platform, sparc64.

     I need a way to get the path to the <module>.prop file.  ad@
suggested that I move all path handling from kobj_load_file() to
module_do_load().  This is phase 0.5.  The code to do this is below.  I
am posting it here for comments.  I have tested it and it works fine.
Therefore, I will only wait 48 hours before committing it, since I want
to move onto the next phase, which is actually loading <module>.prop.

ultra: {25} pwd
/usr/src/sys/kern
ultra: {26} cvs diff -u -r HEAD kern_module.c
Index: kern_module.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_module.c,v
retrieving revision 1.42
diff -u -r1.42 kern_module.c
--- kern_module.c       13 Feb 2009 22:41:04 -0000      1.42
+++ kern_module.c       22 May 2009 22:14:54 -0000
@@ -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 = NULL;
        const char *s, *p;
        int error;
        size_t len;
@@ -616,11 +617,20 @@
                        depth--;
                        return ENOMEM;
                }
-               error = kobj_load_file(&mod->mod_kobj, name, module_base,
-                   autoload);
+               path = PNBUF_GET();
+               if (!autoload) {
+                       snprintf(path, MAXPATHLEN - 1, "%s", name);
+                       error = kobj_load_file(&mod->mod_kobj, path);
+               }
+               if (autoload || (error == ENOENT)) {
+                       snprintf(path, MAXPATHLEN - 1, "%s/%s/%s.kmod",
+                           module_base, name, name);
+                       error = kobj_load_file(&mod->mod_kobj, path);
+               }
                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 +799,8 @@
                module_thread_kick();
        }
        depth--;
+       if (path != NULL)
+               PNBUF_PUT(path);
        return 0;

  fail:
@@ -797,6 +809,8 @@
        TAILQ_REMOVE(&pending, mod, mod_chain);
        kmem_free(mod, sizeof(*mod));
        depth--;
+       if (path != NULL)
+               PNBUF_PUT(path);
        return error;
 }

ultra: {27} cvs diff -u -r HEAD subr_kobj.c
Index: subr_kobj.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_kobj.c,v
retrieving revision 1.34
diff -u -r1.34 subr_kobj.c
--- subr_kobj.c 13 Feb 2009 22:41:04 -0000      1.34
+++ subr_kobj.c 22 May 2009 22:15:15 -0000
@@ -162,12 +162,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)
 {
        struct nameidata nd;
        kauth_cred_t cred;
-       char *path;
        int error;
        kobj_t ko;

@@ -178,25 +176,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, FOLLOW, UIO_SYSSPACE, path);
+       error = vn_open(&nd, FREAD, 0);

- out:
        if (error != 0) {
                kmem_free(ko, sizeof(*ko));
                return error;
@@ -1182,7 +1164,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)
 {

        return ENOSYS;
ultra: {29} pwd
/usr/src/sys/sys
ultra: {30} cvs diff -u -r HEAD kobj.h
Index: kobj.h
===================================================================
RCS file: /cvsroot/src/sys/sys/kobj.h,v
retrieving revision 1.9
diff -u -r1.9 kobj.h
--- kobj.h      20 May 2008 19:20:38 -0000      1.9
+++ kobj.h      22 May 2009 22:17:40 -0000
@@ -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 *);
 int            kobj_load_mem(kobj_t *, void *, ssize_t);
 int            kobj_affix(kobj_t, const char *);
 void           kobj_unload(kobj_t);


Home | Main Index | Thread Index | Old Index