From owner-freebsd-current Fri Nov 2 14:52:26 2001 Delivered-To: freebsd-current@freebsd.org Received: from iguana.aciri.org (iguana.aciri.org [192.150.187.36]) by hub.freebsd.org (Postfix) with ESMTP id DDFB037B41E for ; Fri, 2 Nov 2001 14:52:06 -0800 (PST) Received: (from rizzo@localhost) by iguana.aciri.org (8.11.3/8.11.1) id fA2MmXG45570; Fri, 2 Nov 2001 14:48:33 -0800 (PST) (envelope-from rizzo) Date: Fri, 2 Nov 2001 14:48:33 -0800 From: Luigi Rizzo To: current@freebsd.org Subject: how to handle clean module loading/unloading ? Message-ID: <20011102144832.A45474@iguana.aciri.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.23i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I am trying to figure out how to cleany handle error conditions with module loading/unloading, especially when trying to load a module which is already statically compiled in the kernel. I have browsed through the source a bit but haven't found a good example that I could understand. Basically, i see a problem in the way module_register_init() is implemented. This function ends like this: void module_register_init(const void *arg) { ... error = MOD_EVENT(mod, MOD_LOAD); if (error) { MOD_EVENT(mod, MOD_UNLOAD); module_release(mod); } } and I have a problem understanding the reason of the call to MOD_UNLOAD in case of failure. To me the most obvious way to handle a LOAD failure was that the called function should take care to do the necessary cleanup, without deferring this task to a further call to MOD_UNLOAD. Furthermore, the latter is indistinguishable from a regular call to MOD_UNLOAD generated by kldunload unless the module that failed to register stores some state to record the failure itself. Finally, perhaps there ought to be some automatic way (such as in the DECLARE_MODULE macro) to make sure that when a module is statically compiled in, kldload fails with EEXIST without even attempting to call MOD_LOAD ? I can easily implement some conditional code in modevent, such as static int foo_modevent(module_t mod, int type, void *unused) { switch (type) { case MOD_LOAD: err = foo_init(); break ; case MOD_UNLOAD: #if !defined(KLD_MODULE) printf("cannot unload module foo, it is statically compiled\n"); err = EINVAL #else err = foo_unload(); #endif break; default: err = EINVAL ; break; } but it would be much more convenient if the check were done in some automatic way with some trick in DECLARE_MODULE. cheers luigi ----------------------------------+----------------------------------------- Luigi RIZZO, luigi@iet.unipi.it . ACIRI/ICSI (on leave from Univ. di Pisa) http://www.iet.unipi.it/~luigi/ . 1947 Center St, Berkeley CA 94704 Phone: (510) 666 2927 ----------------------------------+----------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message