summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2008-05-23 00:51:34 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2008-05-23 00:51:34 +0000
commita8adf664b7a663bb38c487e0bd42901586d57a7e (patch)
treea4d938583bb8cf7aaf615094f3edcce7b52aa973
parent651d9a4d919752e72f038077308657c7d5738ab5 (diff)
Make rd act more like a 'normal' disk device, allowing the elimination of
'fakerootdev' hackery. This allows us to bring back miod@'s r1.70 subr_disk.c change to avoid the GENERIC dance when rootdev has been initialized. This in turn re-enables raidframe root devices. Add a nice panic if rootdev can't be initialized, displaying the name of the device that didn't work rather than just blowing up by de-referencing NULL. ok deraadt@
-rw-r--r--sys/dev/ramdisk.c52
-rw-r--r--sys/kern/subr_disk.c31
2 files changed, 54 insertions, 29 deletions
diff --git a/sys/dev/ramdisk.c b/sys/dev/ramdisk.c
index 7ed9a4b78c2..c6f59632cf4 100644
--- a/sys/dev/ramdisk.c
+++ b/sys/dev/ramdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ramdisk.c,v 1.40 2008/01/05 07:33:37 brad Exp $ */
+/* $OpenBSD: ramdisk.c,v 1.41 2008/05/23 00:51:33 krw Exp $ */
/* $NetBSD: ramdisk.c,v 1.8 1996/04/12 08:30:09 leo Exp $ */
/*
@@ -108,7 +108,21 @@ void rdgetdisklabel(dev_t, struct rd_softc *, struct disklabel *, int);
* XXX - that practice is questionable...
*/
struct cfdriver rd_cd = {
- NULL, "rd", DV_DULL
+ NULL, "rd", DV_DISK
+};
+
+/*
+ * Here we define a cfattach structure for inserting any new rd device into the
+ * device tree. This is needed by some archs that look for bootable devices in
+ * there.
+ */
+int rd_probe(struct device *, void *, void *);
+int rd_detach(struct device *, int);
+int rd_activate(struct device *, enum devact);
+
+struct cfattach rd_ca = {
+ sizeof(struct rd_softc), rd_probe, rd_attach,
+ rd_detach, rd_activate
};
void rdstrategy(struct buf *bp);
@@ -125,6 +139,7 @@ rdattach(n)
int n;
{
struct rd_softc *sc;
+ struct cfdata *cf;
int i;
#ifdef DIAGNOSTIC
@@ -146,6 +161,14 @@ rdattach(n)
rd_cd.cd_devs = ramdisk_devs;
/* Attach as if by autoconfig. */
+ cf = malloc(sizeof(struct cfdata), M_DEVBUF, M_NOWAIT | M_ZERO);
+ if (cf == NULL) {
+ printf("WARNING: no memory for cfdata struct\n");
+ return;
+ }
+ cf->cf_attach = &rd_ca;
+ cf->cf_driver = &rd_cd;
+
for (i = 0; i < n; i++) {
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
if (snprintf(sc->sc_dev.dv_xname, sizeof(sc->sc_dev.dv_xname),
@@ -156,6 +179,11 @@ rdattach(n)
}
ramdisk_devs[i] = sc;
sc->sc_dev.dv_unit = i;
+ sc->sc_dev.dv_class = DV_DISK;
+ sc->sc_dev.dv_parent = NULL;
+ sc->sc_dev.dv_cfdata = cf;
+ TAILQ_INSERT_TAIL(&alldevs, &sc->sc_dev, dv_list);
+ device_ref(&sc->sc_dev);
rd_attach(NULL, &sc->sc_dev, NULL);
}
}
@@ -549,7 +577,25 @@ rd_ioctl_kalloc(sc, urd, proc)
sc->sc_size = (size_t)size;
sc->sc_type = RD_KMEM_ALLOCATED;
return 0;
-}
+}
+
+int
+rd_probe(struct device *parent, void *match_, void *aux)
+{
+ return 0;
+}
+
+int
+rd_detach(struct device *self, int flags)
+{
+ return 0;
+}
+
+int
+rd_activate(struct device *self, enum devact act)
+{
+ return 0;
+}
#if RAMDISK_SERVER
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 1b2879c5386..92a267e9c1d 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.73 2008/04/07 23:10:24 krw Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.74 2008/05/23 00:51:33 krw Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -981,10 +981,6 @@ bufq_default_get(struct bufq *bq)
return (bp);
}
-#ifdef RAMDISK_HOOKS
-static struct device fakerdrootdev = { DV_DISK, {}, NULL, 0, "rd0", NULL };
-#endif
-
struct device *
getdisk(char *str, int len, int defpart, dev_t *devp)
{
@@ -992,9 +988,6 @@ getdisk(char *str, int len, int defpart, dev_t *devp)
if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
printf("use one of: exit");
-#ifdef RAMDISK_HOOKS
- printf(" %s[a-p]", fakerdrootdev.dv_xname);
-#endif
TAILQ_FOREACH(dv, &alldevs, dv_list) {
if (dv->dv_class == DV_DISK)
printf(" %s[a-p]", dv->dv_xname);
@@ -1024,20 +1017,11 @@ parsedisk(char *str, int len, int defpart, dev_t *devp)
} else
part = defpart;
-#ifdef RAMDISK_HOOKS
- if (strncmp(str, fakerdrootdev.dv_xname, len) == 0) {
- dv = &fakerdrootdev;
- goto gotdisk;
- }
-#endif
TAILQ_FOREACH(dv, &alldevs, dv_list) {
if (dv->dv_class == DV_DISK &&
strncmp(str, dv->dv_xname, len) == 0 &&
dv->dv_xname[len] == '\0') {
-#ifdef RAMDISK_HOOKS
-gotdisk:
-#endif
majdev = findblkmajor(dv);
if (majdev < 0)
panic("parsedisk");
@@ -1070,12 +1054,6 @@ setroot(struct device *bootdv, int part, int exitflags)
extern char *nfsbootdevname;
#endif
-#ifdef RAMDISK_HOOKS
- bootdv = &fakerdrootdev;
- mountroot = NULL;
- part = 0;
-#endif
-
/*
* If `swap generic' and we couldn't determine boot device,
* ask the user.
@@ -1171,10 +1149,9 @@ gotswap:
rootdv = bootdv;
rootdev = dumpdev = swapdev = NODEV;
#endif
- } else if (mountroot == NULL) {
+ } else if (mountroot == NULL && rootdev == NODEV) {
/*
- * `swap generic' or RAMDISK_HOOKS -- use the
- * device we were told to
+ * `swap generic'
*/
rootdv = bootdv;
majdev = findblkmajor(rootdv);
@@ -1204,6 +1181,8 @@ gotswap:
snprintf(buf, sizeof buf, "%s%d%c",
findblkname(majdev), unit, 'a' + part);
rootdv = parsedisk(buf, strlen(buf), 0, &nrootdev);
+ if (rootdv == NULL)
+ panic("root device (%s) not found", buf);
}
if (rootdv && rootdv == bootdv && rootdv->dv_class == DV_IFNET)