Change linker_reference_module() so that it's passed a struct

mod_depend * (which may be NULL).  The only consumer of this
function at the moment is digi_loadmoduledata(), and that passes
a NULL mod_depend *.

In linker_reference_module(), check to see if we've already got
the required module loaded.  If we have, bump the reference count
and return that, otherwise continue the module search as normal.
This commit is contained in:
Brian Somers 2002-04-10 01:13:57 +00:00
parent a1b85c51bb
commit 96987c74d6
3 changed files with 26 additions and 6 deletions

View File

@ -1028,8 +1028,14 @@ digi_loadmoduledata(struct digi_softc *sc)
modlen = strlen(sc->module);
modfile = malloc(modlen + 6, M_TEMP, M_WAITOK);
snprintf(modfile, modlen + 6, "digi_%s", sc->module);
if ((res = linker_reference_module(modfile, &lf)) != 0)
printf("%s: Failed %d to load module\n", modfile, res);
if ((res = linker_reference_module(modfile, NULL, &lf)) != 0) {
if (res == ENOENT && rootdev == NODEV)
printf("%s: Failed to autoload module: No filesystem\n",
modfile);
else
printf("%s: Failed %d to autoload module\n", modfile,
res);
}
free(modfile, M_TEMP);
if (res != 0)
return (res);

View File

@ -98,6 +98,9 @@ struct modlist {
typedef struct modlist *modlist_t;
static modlisthead_t found_modules;
static modlist_t modlist_lookup2(const char *name,
struct mod_depend *verinfo);
static char *
linker_strdup(const char *str)
{
@ -345,11 +348,19 @@ linker_load_file(const char *filename, linker_file_t *result)
return (error);
}
/* XXX: function parameters are incomplete */
int
linker_reference_module(const char *modname, linker_file_t *result)
linker_reference_module(const char *modname, struct mod_depend *verinfo,
linker_file_t *result)
{
return (linker_load_module(NULL, modname, NULL, NULL, result));
modlist_t mod;
if ((mod = modlist_lookup2(modname, verinfo)) != NULL) {
*result = mod->container;
(*result)->refs++;
return (0);
}
return (linker_load_module(NULL, modname, NULL, verinfo, result));
}
linker_file_t

View File

@ -38,6 +38,8 @@
MALLOC_DECLARE(M_LINKER);
#endif
struct mod_depend;
/*
* Object representing a file which has been loaded by the linker.
*/
@ -110,7 +112,8 @@ int linker_load_file(const char* _filename, linker_file_t* _result);
/*
* Obtain a reference to a module, loading it if required.
*/
int linker_reference_module(const char* _modname, linker_file_t* _result);
int linker_reference_module(const char* _modname, struct mod_depend *_verinfo,
linker_file_t* _result);
/*
* Find a currently loaded file given its filename.