summaryrefslogtreecommitdiff
path: root/sys/dev/cgd.c
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/dev/cgd.c
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/dev/cgd.c')
-rw-r--r--sys/dev/cgd.c59
1 files changed, 43 insertions, 16 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;