Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf Fix the code so that it works in all 3 cases: no...



details:   https://anonhg.NetBSD.org/src/rev/ec638431d96f
branches:  trunk
changeset: 811260:ec638431d96f
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 19 00:29:57 2015 +0000

description:
Fix the code so that it works in all 3 cases: non-modular, modular/builtin,
modular/filesystem. In the non-modular case we initialize through attach.
In the modular/builtin case we define the module to be class misc so it
attaches late (after percpu is initialized) since driver modules attach
too early.  In the modular/filesystem case we define it to be a driver
module since we autoload it via /dev/npf open.

diffstat:

 sys/net/npf/npf.c |  42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diffs (96 lines):

diff -r b546a6a87752 -r ec638431d96f sys/net/npf/npf.c
--- a/sys/net/npf/npf.c Sun Oct 18 20:39:53 2015 +0000
+++ b/sys/net/npf/npf.c Mon Oct 19 00:29:57 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf.c,v 1.26 2015/10/18 20:39:53 jmcneill Exp $        */
+/*     $NetBSD: npf.c,v 1.27 2015/10/19 00:29:57 christos Exp $        */
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.26 2015/10/18 20:39:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.27 2015/10/19 00:29:57 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -54,12 +54,26 @@
 #include "npf_impl.h"
 #include "npf_conn.h"
 
+#ifndef _MODULE
+#include "opt_modular.h"
+#endif
+
 #include "ioconf.h"
 
 /*
  * Module and device structures.
  */
+#ifdef MODULAR
+/*
+ * Modular kernels load drivers too early, and we need percpu to be inited
+ * So we make this misc; a better way would be to have early boot and late
+ * boot drivers
+ */
+MODULE(MODULE_CLASS_MISC, npf, NULL);
+#else
+/* This module autoloads via /dev/npf so it needs to be a driver */
 MODULE(MODULE_CLASS_DRIVER, npf, NULL);
+#endif
 
 static int     npf_fini(void);
 static int     npf_dev_open(dev_t, int, int, lwp_t *);
@@ -91,10 +105,7 @@
 static int
 npf_init(void)
 {
-#ifdef _MODULE
-       devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
-#endif
-       int error = 0;
+       KASSERT(npf_stats_percpu == NULL);
 
        npf_stats_percpu = percpu_alloc(NPF_STATS_SIZE);
        npf_sysctl = NULL;
@@ -112,14 +123,18 @@
        npf_config_init();
 
 #ifdef _MODULE
+       devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
+
        /* Attach /dev/npf device. */
-       error = devsw_attach("npf", NULL, &bmajor, &npf_cdevsw, &cmajor);
+       int error = devsw_attach("npf", NULL, &bmajor, &npf_cdevsw, &cmajor);
        if (error) {
                /* It will call devsw_detach(), which is safe. */
                (void)npf_fini();
        }
+       return error;
+#else
+       return 0;
 #endif
-       return error;
 }
 
 static int
@@ -182,7 +197,16 @@
 void
 npfattach(int nunits)
 {
-       npf_init();
+#ifdef MODULAR
+       /*   
+        * Modular kernels will automatically load any built-in modules
+        * and call their modcmd() routine, so we don't need to do it
+        * again as part of pseudo-device configuration.
+        */     
+       return;
+#else
+       (void)npf_init();
+#endif   
 }
 
 static int



Home | Main Index | Thread Index | Old Index