summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorpgoyette <pgoyette@NetBSD.org>2016-07-25 12:45:13 +0000
committerpgoyette <pgoyette@NetBSD.org>2016-07-25 12:45:13 +0000
commitb243e6a45ccc28f7aaa5539bc06fc2b1e5b5ff1b (patch)
treec89d4412be0dbe6de8ec05f85765c88cb46fb5dc /sys
parentdb0ef349a8370be7e32e23a811b53b73351db4cc (diff)
When initializing the rump cgd component, use the correct driver name
(as found in the devsw_conv[] table). This will get us the "official" major numbers for the cgd device. After creating the rump file-space nodes for /dev/cgd* we then need to detach the [bc]devsw's because normal module initialization will do its own attachment, and we don't want that to fail. While here, since we're doing the devsw_attach() twice, share the results from the first call rather than starting from scratch.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/cgd.c59
-rw-r--r--sys/rump/dev/lib/libcgd/cgd_component.c17
2 files changed, 52 insertions, 24 deletions
diff --git a/sys/dev/cgd.c b/sys/dev/cgd.c
index 0a6f2116eb8..d662fb22b1e 100644
--- a/sys/dev/cgd.c
+++ b/sys/dev/cgd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.108 2016/07/10 17:40:23 riastradh Exp $ */
+/* $NetBSD: cgd.c,v 1.109 2016/07/25 12:45:13 pgoyette Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108 2016/07/10 17:40:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.109 2016/07/25 12:45:13 pgoyette Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -1028,6 +1028,8 @@ MODULE(MODULE_CLASS_DRIVER, cgd, "dk_subr");
#ifdef _MODULE
CFDRIVER_DECL(cgd, DV_DISK, NULL);
+
+devmajor_t cgd_bmajor = -1, cgd_cmajor = -1;
#endif
static int
@@ -1035,10 +1037,6 @@ cgd_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
-#ifdef _MODULE
- devmajor_t bmajor = -1, cmajor = -1;
-#endif
-
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
@@ -1049,16 +1047,24 @@ cgd_modcmd(modcmd_t cmd, void *arg)
error = config_cfattach_attach(cgd_cd.cd_name, &cgd_ca);
if (error) {
config_cfdriver_detach(&cgd_cd);
- aprint_error("%s: unable to register cfattach\n",
- cgd_cd.cd_name);
+ aprint_error("%s: unable to register cfattach for"
+ "%s, error %d\n", __func__, cgd_cd.cd_name, error);
break;
}
+ /*
+ * Attach the {b,c}devsw's
+ */
+ error = devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
+ &cgd_cdevsw, &cgd_cmajor);
- error = devsw_attach("cgd", &cgd_bdevsw, &bmajor,
- &cgd_cdevsw, &cmajor);
+ /*
+ * If devsw_attach fails, remove from autoconf database
+ */
if (error) {
config_cfattach_detach(cgd_cd.cd_name, &cgd_ca);
config_cfdriver_detach(&cgd_cd);
+ aprint_error("%s: unable to attach %s devsw, "
+ "error %d", __func__, cgd_cd.cd_name, error);
break;
}
#endif
@@ -1066,19 +1072,40 @@ cgd_modcmd(modcmd_t cmd, void *arg)
case MODULE_CMD_FINI:
#ifdef _MODULE
+ /*
+ * Remove {b,c}devsw's
+ */
+ devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
+
+ /*
+ * Now remove device from autoconf database
+ */
error = config_cfattach_detach(cgd_cd.cd_name, &cgd_ca);
- if (error)
+ if (error) {
+ error = devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
+ &cgd_cdevsw, &cgd_cmajor);
+ aprint_error("%s: failed to detach %s cfattach, "
+ "error %d\n", __func__, cgd_cd.cd_name, error);
+ break;
+ }
+ error = config_cfdriver_detach(&cgd_cd);
+ if (error) {
+ config_cfattach_attach(cgd_cd.cd_name, &cgd_ca);
+ devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
+ &cgd_cdevsw, &cgd_cmajor);
+ aprint_error("%s: failed to detach %s cfdriver, "
+ "error %d\n", __func__, cgd_cd.cd_name, error);
break;
- config_cfdriver_detach(&cgd_cd);
- devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
+ }
#endif
break;
case MODULE_CMD_STAT:
- return ENOTTY;
-
+ error = ENOTTY;
+ break;
default:
- return ENOTTY;
+ error = ENOTTY;
+ break;
}
return error;
diff --git a/sys/rump/dev/lib/libcgd/cgd_component.c b/sys/rump/dev/lib/libcgd/cgd_component.c
index 232e6508bbd..3e19a8be43b 100644
--- a/sys/rump/dev/lib/libcgd/cgd_component.c
+++ b/sys/rump/dev/lib/libcgd/cgd_component.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd_component.c,v 1.2 2016/01/26 23:12:15 pooka Exp $ */
+/* $NetBSD: cgd_component.c,v 1.3 2016/07/25 12:45:13 pgoyette Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd_component.c,v 1.2 2016/01/26 23:12:15 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd_component.c,v 1.3 2016/07/25 12:45:13 pgoyette Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -40,20 +40,21 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV)
{
extern const struct bdevsw cgd_bdevsw;
extern const struct cdevsw cgd_cdevsw;
- devmajor_t bmaj, cmaj;
+ extern devmajor_t cgd_bmajor, cgd_cmajor;
int error;
/* go, mydevfs */
- bmaj = cmaj = -1;
- if ((error = devsw_attach("/dev/cgd0", &cgd_bdevsw, &bmaj,
- &cgd_cdevsw, &cmaj)) != 0)
+ if ((error = devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
+ &cgd_cdevsw, &cgd_cmajor)) != 0)
panic("cannot attach cgd: %d", error);
if ((error = rump_vfs_makedevnodes(S_IFBLK, "/dev/cgd0", 'a',
- bmaj, 0, 7)) != 0)
+ cgd_bmajor, 0, 7)) != 0)
panic("cannot create cooked cgd dev nodes: %d", error);
if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/rcgd0", 'a',
- cmaj, 0, 7)) != 0)
+ cgd_cmajor, 0, 7)) != 0)
panic("cannot create raw cgd dev nodes: %d", error);
+
+ devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
}