Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys When calling devsw_attach() we need to use the expected/...



details:   https://anonhg.NetBSD.org/src/rev/c7bdd77d40c0
branches:  trunk
changeset: 346656:c7bdd77d40c0
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jul 26 01:49:48 2016 +0000

description:
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.

diffstat:

 sys/dev/vnd.c                           |  67 ++++++++++++++++++++++++--------
 sys/rump/dev/lib/libvnd/vnd_component.c |  17 ++++---
 2 files changed, 58 insertions(+), 26 deletions(-)

diffs (179 lines):

diff -r 4ddbbe7c17a1 -r c7bdd77d40c0 sys/dev/vnd.c
--- a/sys/dev/vnd.c     Tue Jul 26 01:36:50 2016 +0000
+++ b/sys/dev/vnd.c     Tue Jul 26 01:49:48 2016 +0000
@@ -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 @@
 #include <sys/uio.h>
 #include <sys/conf.h>
 #include <sys/kauth.h>
+#include <sys/module.h>
 
 #include <net/zlib.h>
 
@@ -2041,10 +2042,6 @@
        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 @@
 #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 @@
                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:
+#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)
-                       break;
-               config_cfdriver_detach(&vnd_cd);
-               devsw_detach(&vnd_bdevsw, &vnd_cdevsw);
+                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 @@
 
        return error;
 }
-
-#endif
diff -r 4ddbbe7c17a1 -r c7bdd77d40c0 sys/rump/dev/lib/libvnd/vnd_component.c
--- a/sys/rump/dev/lib/libvnd/vnd_component.c   Tue Jul 26 01:36:50 2016 +0000
+++ b/sys/rump/dev/lib/libvnd/vnd_component.c   Tue Jul 26 01:49:48 2016 +0000
@@ -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 @@
 {
        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);
 }



Home | Main Index | Thread Index | Old Index