summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-06-13 21:36:23 +0000
committerjhb <jhb@FreeBSD.org>2006-06-13 21:36:23 +0000
commit9af5dd68e4cafc61cd39c93a9cbb404beec42308 (patch)
tree6bdda3a80fe25172e30b3b25fc2a0ae45191cc84 /sys
parent00130e4f0c49136fca94a71afa4a22642743681e (diff)
downloadFreeBSD-src-9af5dd68e4cafc61cd39c93a9cbb404beec42308.zip
FreeBSD-src-9af5dd68e4cafc61cd39c93a9cbb404beec42308.tar.gz
Use kern_kldload() and kern_kldunload() to load and unload modules when
we intend for the user to be able to unload them later via kldunload(2) instead of calling linker_load_module() and then directly adjusting the ref count on the linker file structure. This makes the resulting consumer code simpler and cleaner and better hides the linker internals making it possible to sanely lock the linker.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_init.c12
-rw-r--r--sys/net80211/ieee80211_freebsd.c9
-rw-r--r--sys/netgraph/ng_socket.c11
3 files changed, 12 insertions, 20 deletions
diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c
index b890ffe..b279e89 100644
--- a/sys/kern/vfs_init.c
+++ b/sys/kern/vfs_init.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/mount.h>
#include <sys/proc.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
@@ -108,7 +109,7 @@ struct vfsconf *
vfs_byname_kld(const char *fstype, struct thread *td, int *error)
{
struct vfsconf *vfsp;
- linker_file_t lf;
+ int fileid;
vfsp = vfs_byname(fstype);
if (vfsp != NULL)
@@ -121,17 +122,14 @@ vfs_byname_kld(const char *fstype, struct thread *td, int *error)
*error = securelevel_gt(td->td_ucred, 0);
if (*error)
return (NULL);
- *error = linker_load_module(NULL, fstype, NULL, NULL, &lf);
- if (lf == NULL)
- *error = ENODEV;
+ *error = kern_kldload(td, fstype, &fileid);
if (*error)
return (NULL);
- lf->userrefs++;
+
/* Look up again to see if the VFS was loaded. */
vfsp = vfs_byname(fstype);
if (vfsp == NULL) {
- lf->userrefs--;
- linker_file_unload(lf, LINKER_UNLOAD_FORCE);
+ (void)kern_kldunload(td, fileid, LINKER_UNLOAD_FORCE);
*error = ENODEV;
return (NULL);
}
diff --git a/sys/net80211/ieee80211_freebsd.c b/sys/net80211/ieee80211_freebsd.c
index 4fa0207..912f2d0 100644
--- a/sys/net80211/ieee80211_freebsd.c
+++ b/sys/net80211/ieee80211_freebsd.c
@@ -310,14 +310,9 @@ ieee80211_notify_michael_failure(struct ieee80211com *ic,
void
ieee80211_load_module(const char *modname)
{
-#ifdef notyet
- struct thread *td = curthread;
- if (suser(td) == 0 && securelevel_gt(td->td_ucred, 0) == 0) {
- mtx_lock(&Giant);
- (void) linker_load_module(modname, NULL, NULL, NULL, NULL);
- mtx_unlock(&Giant);
- }
+#ifdef notyet
+ (void)kern_kldload(curthread, modname, NULL);
#else
printf("%s: load the %s module by hand for now.\n", __func__, modname);
#endif
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index c977c43..72bff98 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -65,6 +65,7 @@
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sx.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#ifdef NOTYET
@@ -271,24 +272,22 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
if ((type = ng_findtype(mkp->type)) == NULL) {
char filename[NG_TYPESIZ + 3];
- linker_file_t lf;
+ int fileid;
/* Not found, try to load it as a loadable module. */
snprintf(filename, sizeof(filename), "ng_%s",
mkp->type);
- mtx_lock(&Giant);
- error = linker_load_module(NULL, filename, NULL, NULL,
- &lf);
- mtx_unlock(&Giant);
+ error = kern_kldload(curthread, filename, &fileid);
if (error != 0) {
FREE(msg, M_NETGRAPH_MSG);
goto release;
}
- lf->userrefs++;
/* See if type has been loaded successfully. */
if ((type = ng_findtype(mkp->type)) == NULL) {
FREE(msg, M_NETGRAPH_MSG);
+ (void)kern_kldunload(curthread, fileid,
+ LINKER_UNLOAD_NORMAL);
error = ENXIO;
goto release;
}
OpenPOWER on IntegriCloud