tech-kern archive

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

Re: options MODULAR improvements phase 0.5



On Oct 12, 10:00am, John Nemeth wrote:
} 
}      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.

     Of course, as soon as I posted this, I realised that there was an
oversight.  The second lookup wasn't being passed NOCHROOT.  I've
modified kobj_load_file() to take a flags argument, and modified
module_do_load() to pass the correct flags.  Same deal as above, the
code is quite simple and it is tested, so I'll only wait 48 hours for
comments.

ultra: {18} pwd
/usr/src/sys/kern
ultra: {19} 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       23 May 2009 00:19:57 -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,21 @@
                        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, FOLLOW);
+               }
+               if (autoload || (error == ENOENT)) {
+                       snprintf(path, MAXPATHLEN - 1, "%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 +800,8 @@
                module_thread_kick();
        }
        depth--;
+       if (path != NULL)
+               PNBUF_PUT(path);
        return 0;

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

ultra: {20} 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 23 May 2009 00:20:06 -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, const uint32_t flags)
 {
        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, flags, 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, const uint32_t flags)
 {

        return ENOSYS;

ultra: {23} pwd
/usr/src/sys/sys
ultra: {24} 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      23 May 2009 00:22:49 -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 *, const uint32_t);
 int            kobj_load_mem(kobj_t *, void *, ssize_t);
 int            kobj_affix(kobj_t, const char *);
 void           kobj_unload(kobj_t);

}-- End of excerpt from John Nemeth


Home | Main Index | Thread Index | Old Index