David Powell wrote: >> I have a question here. >> I have two drivers, say A and B, that cooperate to provide a specific >> funcationality. A can call a routine provided by B and passes in a >> callback as a parameter so that B can use that to call into A. From >> this point of view, they behavior like module. Such calls could be >> issued even before the drivers create minor nodes. Yet I can only >> create one-way dependency, say A depends on B. >> The issues is: it's possible that A could be unloaded, which is very >> possible with debug kernel, when B call into A. And the system will >> panic. >> >> Is there a way out ? >> > > Great question. > > If "B" has a routine which registers a callback, it should also have > a routine which unregisters the callback. The unregistration routine > shouldn't return successfully until the callback is removed and all > callers to the callback have returned. (It depends on the situation > whether it is more appropriate to wait for callers to drain or > immediately return EBUSY). "A" should call this unregistration > routine before it allows itself to be unloaded. > > I'm no DDI expert, though, so there might be a more elegant way to > implement this relationship I don't know about. > > Dave > > _______________________________________________ > opensolaris-code mailing list > [email protected] > http://mail.opensolaris.org/mailman/listinfo/opensolaris-code > Here's a real world example:
Assume two modules, call them "afe" and "gld" (for convenience.) afe uses functions from gld, and calls into it. It has a link time dependency on gld, expressed with ld -Ndrv/gld. (This means that gld cannot unload while afe is loaded.) afe also registers operations with gld. It passes a structure of entry points to gld with a routine called gld_register. (In afe this is done in attach(9e).) afe ensures that it _unregisters_ from gld during detach(9e), using gld_unregister(). This can fail, in which case detach(9e) is aborted and DDI_FAILURE is returned. If gld_unregister() succeeds, then gld drops all references to afe entry points, and afe's detach(9e) returns DDI_SUCCESS. Now, _fini() in afe calls mod_remove(9f), which implicitly tries to detach(9e). If detach(9e) fails, then mod_remove(9f) fails, and the module is not removed from memory. This keeps the code from being yanked out from underneath GLD. Hopefully that helps. -- Garrett D'Amore, Principal Software Engineer Tadpole Computer / Computing Technologies Division, General Dynamics C4 Systems http://www.tadpolecomputer.com/ Phone: 951 325-2134 Fax: 951 325-2191 _______________________________________________ opensolaris-code mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
