Module Name:    src
Committed By:   pgoyette
Date:           Tue Jul 26 01:49:49 UTC 2016

Modified Files:
        src/sys/dev: vnd.c
        src/sys/rump/dev/lib/libvnd: vnd_component.c

Log Message:
When calling devsw_attach() we need to use the expected/official driver
name (as listed in the devsw_conv[] table) to get the expected device
majors.  Once rump initialization is finished (ie, it has created its
required device nodes), we need to detach the [bc]devsw so the module
initialization code doesn't get EEXIST.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 src/sys/dev/vnd.c
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/dev/lib/libvnd/vnd_component.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/vnd.c
diff -u src/sys/dev/vnd.c:1.256 src/sys/dev/vnd.c:1.257
--- src/sys/dev/vnd.c:1.256	Tue Dec  8 20:36:14 2015
+++ src/sys/dev/vnd.c	Tue Jul 26 01:49:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd.c,v 1.256 2015/12/08 20:36:14 christos Exp $	*/
+/*	$NetBSD: vnd.c,v 1.257 2016/07/26 01:49:48 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.256 2015/12/08 20:36:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.257 2016/07/26 01:49:48 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -118,6 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.25
 #include <sys/uio.h>
 #include <sys/conf.h>
 #include <sys/kauth.h>
+#include <sys/module.h>
 
 #include <net/zlib.h>
 
@@ -2041,10 +2042,6 @@ vnd_set_geometry(struct vnd_softc *vnd)
 	disk_set_info(vnd->sc_dev, &vnd->sc_dkdev, NULL);
 }
 
-#ifdef _MODULE
-
-#include <sys/module.h>
-
 #ifdef VND_COMPRESSION
 #define VND_DEPENDS "zlib"
 #else
@@ -2052,15 +2049,21 @@ vnd_set_geometry(struct vnd_softc *vnd)
 #endif
 
 MODULE(MODULE_CLASS_DRIVER, vnd, VND_DEPENDS);
+
+#ifdef _MODULE
+int vnd_bmajor = -1, vnd_cmajor = -1;
+
 CFDRIVER_DECL(vnd, DV_DISK, NULL);
+#endif
 
 static int
 vnd_modcmd(modcmd_t cmd, void *arg)
 {
-	int bmajor = -1, cmajor = -1,  error = 0;
+	int error = 0;
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
+#ifdef _MODULE
 		error = config_cfdriver_attach(&vnd_cd);
 		if (error)
 			break;
@@ -2068,27 +2071,57 @@ vnd_modcmd(modcmd_t cmd, void *arg)
 		error = config_cfattach_attach(vnd_cd.cd_name, &vnd_ca);
 	        if (error) {
 			config_cfdriver_detach(&vnd_cd);
-			aprint_error("%s: unable to register cfattach\n",
-			    vnd_cd.cd_name);
+			aprint_error("%s: unable to register cfattach for \n"
+			    "%s, error %d", __func__, vnd_cd.cd_name, error);
 			break;
 		}
 
-		error = devsw_attach("vnd", &vnd_bdevsw, &bmajor,
-		    &vnd_cdevsw, &cmajor);
+                /*
+                 * Attach the {b,c}devsw's
+                 */
+		error = devsw_attach("vnd", &vnd_bdevsw, &vnd_bmajor,
+		    &vnd_cdevsw, &vnd_cmajor);
+                /*
+                 * If devsw_attach fails, remove from autoconf database
+                 */
 		if (error) {
 			config_cfattach_detach(vnd_cd.cd_name, &vnd_ca);
 			config_cfdriver_detach(&vnd_cd);
+                        aprint_error("%s: unable to attach %s devsw, "
+                            "error %d", __func__, vnd_cd.cd_name, error);
 			break;
 		}
-
+#endif
 		break;
 
 	case MODULE_CMD_FINI:
-		error = config_cfattach_detach(vnd_cd.cd_name, &vnd_ca);
-		if (error)
-			break;
-		config_cfdriver_detach(&vnd_cd);
+#ifdef _MODULE
+                /*
+                 * Remove {b,c}devsw's
+                 */
 		devsw_detach(&vnd_bdevsw, &vnd_cdevsw);
+
+                /*
+                 * Now remove device from autoconf database
+                 */
+		error = config_cfattach_detach(vnd_cd.cd_name, &vnd_ca);
+                if (error) { 
+                        error = devsw_attach("vnd", &vnd_bdevsw, &vnd_bmajor,
+                            &vnd_cdevsw, &vnd_cmajor);
+                        aprint_error("%s: failed to detach %s cfattach, "
+                            "error %d\n", __func__, vnd_cd.cd_name, error);
+                        break;
+                }
+                error = config_cfdriver_detach(&vnd_cd);
+                if (error) {
+                        config_cfattach_attach(vnd_cd.cd_name, &vnd_ca); 
+                        devsw_attach("vnd", &vnd_bdevsw, &vnd_bmajor,
+                            &vnd_cdevsw, &vnd_cmajor);
+                        aprint_error("%s: failed to detach %s cfdriver, "
+                            "error %d\n", __func__, vnd_cd.cd_name, error);
+                        break;
+                }
+#endif
 		break;
 
 	case MODULE_CMD_STAT:
@@ -2100,5 +2133,3 @@ vnd_modcmd(modcmd_t cmd, void *arg)
 
 	return error;
 }
-
-#endif

Index: src/sys/rump/dev/lib/libvnd/vnd_component.c
diff -u src/sys/rump/dev/lib/libvnd/vnd_component.c:1.2 src/sys/rump/dev/lib/libvnd/vnd_component.c:1.3
--- src/sys/rump/dev/lib/libvnd/vnd_component.c:1.2	Tue Jan 26 23:12:16 2016
+++ src/sys/rump/dev/lib/libvnd/vnd_component.c	Tue Jul 26 01:49:49 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd_component.c,v 1.2 2016/01/26 23:12:16 pooka Exp $	*/
+/*	$NetBSD: vnd_component.c,v 1.3 2016/07/26 01:49:49 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd_component.c,v 1.2 2016/01/26 23:12:16 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd_component.c,v 1.3 2016/07/26 01:49:49 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -40,20 +40,21 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV)
 {
 	extern const struct bdevsw vnd_bdevsw;
 	extern const struct cdevsw vnd_cdevsw;
-	devmajor_t bmaj, cmaj;
+	extern devmajor_t vnd_bmajor, vnd_cmajor;
 	int error;
 
 	/* go, mydevfs */
-	bmaj = cmaj = -1;
 
-	if ((error = devsw_attach("/dev/vnd0", &vnd_bdevsw, &bmaj,
-	    &vnd_cdevsw, &cmaj)) != 0)
+	if ((error = devsw_attach("vnd", &vnd_bdevsw, &vnd_bmajor,
+	    &vnd_cdevsw, &vnd_cmajor)) != 0)
 		panic("cannot attach vnd: %d", error);
 
 	if ((error = rump_vfs_makedevnodes(S_IFBLK, "/dev/vnd0", 'a',
-	    bmaj, 0, 7)) != 0)
+	    vnd_bmajor, 0, 7)) != 0)
 		panic("cannot create cooked vnd dev nodes: %d", error);
 	if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/rvnd0", 'a',
-	    cmaj, 0, 7)) != 0)
+	    vnd_cmajor, 0, 7)) != 0)
 		panic("cannot create raw vnd dev nodes: %d", error);
+
+	devsw_detach(&vnd_bdevsw, &vnd_cdevsw);
 }

Reply via email to