1 #include <netgraph/ng_message.h>
3 #include <sys/malloc.h>
4 #include <sys/linker.h>
5 #include <sys/thread2.h>
10 /* Temporary lock stuff. */
12 /* End Temporary lock stuff. */
15 linker_api_available(void)
17 /* linker_* API won't work without a process context */
21 * nlookup_init() relies on namei_oc to be initialized,
22 * but it's not when the netgraph module is loaded during boot.
30 ng_load_module(const char *name)
32 char *path, filename[NG_TYPESIZ + 3];
36 if (!linker_api_available())
39 /* Not found, try to load it as a loadable module */
40 ksnprintf(filename, sizeof(filename), "ng_%s.ko", name);
41 if ((path = linker_search_path(filename)) == NULL)
43 error = linker_load_file(path, &lf);
46 lf->userrefs++; /* pretend kldload'ed */
51 ng_unload_module(const char *name)
53 char filename[NG_TYPESIZ + 3];
57 if (!linker_api_available())
60 /* Not found, try to load it as a loadable module */
61 ksnprintf(filename, sizeof(filename), "ng_%s.ko", name);
62 if ((lf = linker_find_file_by_name(filename)) == NULL)
64 error = linker_file_unload(lf);
67 lf->userrefs--; /* pretend kldunload'ed */
77 lockstatus_owned(struct lock *lkp, struct thread *td)
81 if (lkp->lk_exclusivecount != 0) {
82 if (td == NULL || lkp->lk_lockholder == td)
83 lock_type = LK_EXCLUSIVE;
85 lock_type = LK_EXCLOTHER;
86 } else if (lkp->lk_sharecount != 0) {
87 lock_type = LK_SHARED;
93 * Atomically drop a lockmgr lock and go to sleep. The lock is reacquired
94 * before returning from this function. Passes on the value returned by
98 lock_sleep(void *ident, int flags, const char *wmesg, int timo,
103 mode = lockstatus_owned(lk, curthread);
104 KKASSERT((mode == LK_EXCLUSIVE) || (mode == LK_SHARED));
107 tsleep_interlock(ident, flags);
108 lockmgr(lk, LK_RELEASE);
109 err = tsleep(ident, flags, wmesg, timo);