From 8ad55476a0c93a0bcb9e3363b8a11bd9a5c02883 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 10 Apr 2002 01:13:57 +0000 Subject: 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. --- sys/dev/digi/digi.c | 10 ++++++++-- sys/kern/kern_linker.c | 17 ++++++++++++++--- sys/sys/linker.h | 5 ++++- 3 files changed, 26 insertions(+), 6 deletions(-) (limited to 'sys') diff --git a/sys/dev/digi/digi.c b/sys/dev/digi/digi.c index 90ba01c..18ea046 100644 --- a/sys/dev/digi/digi.c +++ b/sys/dev/digi/digi.c @@ -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); diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index bad5e1e..a88d636 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -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 @@ out: 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 diff --git a/sys/sys/linker.h b/sys/sys/linker.h index 28169d5..f138df7 100644 --- a/sys/sys/linker.h +++ b/sys/sys/linker.h @@ -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. -- cgit v1.1