Module Name:    src
Committed By:   christos
Date:           Mon Oct 19 00:29:57 UTC 2015

Modified Files:
        src/sys/net/npf: npf.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/net/npf/npf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/npf/npf.c
diff -u src/sys/net/npf/npf.c:1.26 src/sys/net/npf/npf.c:1.27
--- src/sys/net/npf/npf.c:1.26	Sun Oct 18 16:39:53 2015
+++ src/sys/net/npf/npf.c	Sun Oct 18 20:29:57 2015
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.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 @@ const struct cdevsw npf_cdevsw = {
 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_init(void)
 	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();
 	}
-#endif
 	return error;
+#else
+	return 0;
+#endif
 }
 
 static int
@@ -182,7 +197,16 @@ npf_modcmd(modcmd_t cmd, void *arg)
 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

Reply via email to