Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys When initializing the rump cgd component, use the correc...
details: https://anonhg.NetBSD.org/src/rev/89fe6acbb0b1
branches: trunk
changeset: 346648:89fe6acbb0b1
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Mon Jul 25 12:45:13 2016 +0000
description:
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:
sys/dev/cgd.c | 59 ++++++++++++++++++++++++--------
sys/rump/dev/lib/libcgd/cgd_component.c | 17 +++++----
2 files changed, 52 insertions(+), 24 deletions(-)
diffs (160 lines):
diff -r dae1abeec88d -r 89fe6acbb0b1 sys/dev/cgd.c
--- a/sys/dev/cgd.c Mon Jul 25 12:11:40 2016 +0000
+++ b/sys/dev/cgd.c Mon Jul 25 12:45:13 2016 +0000
@@ -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 @@
#ifdef _MODULE
CFDRIVER_DECL(cgd, DV_DISK, NULL);
+
+devmajor_t cgd_bmajor = -1, cgd_cmajor = -1;
#endif
static int
@@ -1035,10 +1037,6 @@
{
int error = 0;
-#ifdef _MODULE
- devmajor_t bmajor = -1, cmajor = -1;
-#endif
-
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
@@ -1049,16 +1047,24 @@
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 @@
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 -r dae1abeec88d -r 89fe6acbb0b1 sys/rump/dev/lib/libcgd/cgd_component.c
--- a/sys/rump/dev/lib/libcgd/cgd_component.c Mon Jul 25 12:11:40 2016 +0000
+++ b/sys/rump/dev/lib/libcgd/cgd_component.c Mon Jul 25 12:45:13 2016 +0000
@@ -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 @@
{
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);
}
Home |
Main Index |
Thread Index |
Old Index