summaryrefslogtreecommitdiffstats
path: root/sbin/mdconfig
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2001-02-24 16:26:41 +0000
committerphk <phk@FreeBSD.org>2001-02-24 16:26:41 +0000
commit1629d05921c5477e9986a9540858390fb30e8e5b (patch)
treeaf5496bc51bc08bbdb80251e7db8249720ed66fa /sbin/mdconfig
parent1bdf6a6d1487f16229bd23e00ffc0ff9fdcaff8f (diff)
downloadFreeBSD-src-1629d05921c5477e9986a9540858390fb30e8e5b.zip
FreeBSD-src-1629d05921c5477e9986a9540858390fb30e8e5b.tar.gz
Make md/mdconfig do kld.
Submitted by: dcs
Diffstat (limited to 'sbin/mdconfig')
-rw-r--r--sbin/mdconfig/mdconfig.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c
index b2ea2bb..079be71 100644
--- a/sbin/mdconfig/mdconfig.c
+++ b/sbin/mdconfig/mdconfig.c
@@ -18,12 +18,16 @@
#include <err.h>
#include <sys/ioctl.h>
#include <sys/param.h>
+#include <sys/module.h>
+#include <sys/linker.h>
#include <sys/mdioctl.h>
struct md_ioctl mdio;
enum {UNSET, ATTACH, DETACH} action = UNSET;
+void mdmaybeload(void);
+
void
usage()
{
@@ -139,6 +143,7 @@ main(int argc, char **argv)
}
}
+ mdmaybeload();
fd = open("/dev/mdctl", O_RDWR, 0);
if (fd < 0)
err(1, "open(/dev/mdctl)");
@@ -156,3 +161,34 @@ main(int argc, char **argv)
return (0);
}
+void
+mdmaybeload(void)
+{
+ struct module_stat mstat;
+ int fileid, modid;
+ char *name = "md";
+ char *cp;
+
+ /* scan files in kernel */
+ mstat.version = sizeof(struct module_stat);
+ for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
+ /* scan modules in file */
+ for (modid = kldfirstmod(fileid); modid > 0;
+ modid = modfnext(modid)) {
+ if (modstat(modid, &mstat) < 0)
+ continue;
+ /* strip bus name if present */
+ if ((cp = strchr(mstat.name, '/')) != NULL) {
+ cp++;
+ } else {
+ cp = mstat.name;
+ }
+ /* already loaded? */
+ if (!strcmp(name, cp))
+ return;
+ }
+ }
+ /* not present, we should try to load it */
+ kldload(name);
+}
+
OpenPOWER on IntegriCloud