tech-kern archive

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

Re: Fixed modular kernel path and different kernels



On Wed, 18 Jan 2017, Paul Goyette wrote:

One obvious and trivial way to allow for testing like this is to have
boot -a also ask for an override of the module path.

This should not be too difficult, although it would (continue to) have the restriction that modules "pushed" from the boot loader (those which are loaded via /boot.conf as well as those automatically pushed for non-ffs boot-device file systems) would continue to be loaded from the boot device.

Once that is there, also provide the override via userconf or
/boot.cfg.

Would this really be necessary? Do we have the ability to set the root file system via userconf or /boot.cfg? (Neither the boot.cfg(5) nor userconf(4) man pages hint that this is available?)


With a goal of improving the useability of kernel modularity, I'd be happy to implement this capability (WRT boot -a), if there's some sort of consensus.

I've gone ahead and implemented this - see attached patches.

Code review appreciated, as well as comments on whether or not this should be committed.




+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+
Index: share/man/man8/boot.8
===================================================================
RCS file: /cvsroot/src/share/man/man8/boot.8,v
retrieving revision 1.15
diff -u -p -r1.15 boot.8
--- share/man/man8/boot.8	16 Aug 2014 11:39:47 -0000	1.15
+++ share/man/man8/boot.8	18 Jan 2017 05:46:19 -0000
@@ -141,6 +141,12 @@ flag in
 This causes the kernel to prompt for the root file system device,
 the system crash dump device, and the path to
 .Xr init 8 .
+For modular kernels (see
+.Cd MODULAR
+in
+.Xr options 4 ) ,
+the kernel will also prompt for the path used for
+loading kernel modules.
 .It Fl b
 Sets the
 .Sy RB_HALT
Index: sys/sys/module.h
===================================================================
RCS file: /cvsroot/src/sys/sys/module.h,v
retrieving revision 1.41
diff -u -p -r1.41 module.h
--- sys/sys/module.h	16 Nov 2016 10:42:14 -0000	1.41
+++ sys/sys/module.h	18 Jan 2017 05:46:19 -0000
@@ -170,7 +170,7 @@ extern struct modlist	module_list;
 extern struct modlist	module_builtins;
 extern u_int		module_gen;
 
-void	module_init(void);
+void	module_init(int);
 void	module_start_unload_thread(void);
 void	module_builtin_require_force(void);
 void	module_init_md(void);
Index: sys/kern/init_main.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_main.c,v
retrieving revision 1.490
diff -u -p -r1.490 init_main.c
--- sys/kern/init_main.c	16 Jan 2017 09:28:40 -0000	1.490
+++ sys/kern/init_main.c	18 Jan 2017 05:46:19 -0000
@@ -337,7 +337,7 @@ main(void)
 	bpf_setops();
 
 	/* Start module system. */
-	module_init();
+	module_init(boothowto & RB_ASKNAME);
 
 	/*
 	 * Initialize the kernel authorization subsystem and start the
Index: sys/kern/kern_module.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_module.c,v
retrieving revision 1.119
diff -u -p -r1.119 kern_module.c
--- sys/kern/kern_module.c	27 Dec 2016 09:34:44 -0000	1.119
+++ sys/kern/kern_module.c	18 Jan 2017 05:46:19 -0000
@@ -55,6 +55,8 @@ __KERNEL_RCSID(0, "$NetBSD: kern_module.
 #include <sys/sysctl.h>
 #include <sys/lock.h>
 
+#include <dev/cons.h>	/* for cngetsn() (prompting for module path) */
+
 #include <uvm/uvm_extern.h>
 
 struct vm_map *module_map;
@@ -337,7 +339,7 @@ module_builtin_remove(modinfo_t *mi, boo
  *	Initialize the module subsystem.
  */
 void
-module_init(void)
+module_init(int askpath)
 {
 	__link_set_decl(modules, modinfo_t);
 	extern struct vm_map *module_map;
@@ -365,6 +367,22 @@ module_init(void)
 	    __NetBSD_Version__ / 1000000 % 100);
 #endif
 
+#ifdef _RUMPKERNEL	/* rump kernel does not provide console read/get */
+	KASSERT(askpath == 0);
+#else
+#ifdef MODULAR
+	if (askpath != 0) {
+		int len;
+		char module_path[MODULE_BASE_SIZE];
+
+		printf("module path (default %s): ", module_base);
+		len = cngetsn(module_path, sizeof(module_path)-1);
+		if (len != 0)
+			strlcpy(module_base, module_path, sizeof(module_base));
+	}
+#endif /* defined(MODULAR) */
+#endif
+
 	module_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
 	    module_listener_cb, NULL);
 
Index: sys/rump/librump/rumpkern/rump.c
===================================================================
RCS file: /cvsroot/src/sys/rump/librump/rumpkern/rump.c,v
retrieving revision 1.329
diff -u -p -r1.329 rump.c
--- sys/rump/librump/rumpkern/rump.c	8 Mar 2016 14:30:48 -0000	1.329
+++ sys/rump/librump/rumpkern/rump.c	18 Jan 2017 05:46:19 -0000
@@ -400,7 +400,7 @@ rump_init(void)
 	kqueue_init();
 	iostat_init();
 	fd_sys_init();
-	module_init();
+	module_init(0);
 	devsw_init();
 	pipe_init();
 	resource_init();


Home | Main Index | Thread Index | Old Index