Package: freebsd-utils / 10.1~svn273304-1

006_mdconfig.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

* revert change from 1.43.2.4 to 1.43.2.5 
  it expects kld_isloaded() and kld_load() in libutil

---
 sbin/mdconfig/Makefile   |    2 +-
 sbin/mdconfig/mdconfig.c |   23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

--- a/src/sbin/mdconfig/mdconfig.c
+++ b/src/sbin/mdconfig/mdconfig.c
@@ -74,6 +74,24 @@
 #define CLASS_NAME_MD	"MD"
 
 static void
+mdmaybeload(void)
+{
+	char name1[64], name2[64];
+
+	snprintf(name1, sizeof(name1), "g_%s", MD_NAME);
+	snprintf(name2, sizeof(name2), "geom_%s", MD_NAME);
+	if (modfind(name1) == -1) {
+		/* Not present in kernel, try loading it. */
+		if (kldload(name2) == -1 || modfind(name1) == -1) {
+			if (errno != EEXIST) {
+				errx(EXIT_FAILURE,
+				    "%s module not available!", name2);
+			}
+		}
+	}
+}
+
+static void
 usage(void)
 {
 
@@ -333,8 +351,7 @@
 
 	mdio.md_version = MDIOVERSION;
 
-	if (!kld_isloaded("g_md") && kld_load("geom_md") == -1)
-		err(1, "failed to load geom_md module");
+	mdmaybeload();
 
 	fd = open(_PATH_DEV MDCTL_NAME, O_RDWR, 0);
 	if (fd < 0)