Page MenuHomeFreeBSD

D37517.id113550.diff
No OneTemporary

D37517.id113550.diff

diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -69,6 +69,10 @@
SYSCTL_ROOT_NODE(OID_AUTO, dev, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL,
NULL);
+static bool disable_failed_devs = false;
+SYSCTL_BOOL(_hw_bus, OID_AUTO, disable_failed_devices, CTLFLAG_RWTUN, &disable_failed_devs,
+ 0, "Do not retry attaching devices that return an error from DEVICE_ATTACH the first time");
+
/*
* Used to attach drivers to devclasses.
*/
@@ -2533,16 +2537,39 @@
if ((error = DEVICE_ATTACH(dev)) != 0) {
printf("device_attach: %s%d attach returned %d\n",
dev->driver->name, dev->unit, error);
- if (!(dev->flags & DF_FIXEDCLASS))
- devclass_delete_device(dev->devclass, dev);
- (void)device_set_driver(dev, NULL);
- device_sysctl_fini(dev);
- KASSERT(dev->busy == 0, ("attach failed but busy"));
- dev->state = DS_NOTPRESENT;
+ if (disable_failed_devs) {
+ /*
+ * When the user has asked to disable failed devices, we
+ * directly disable the device, but leave it in the
+ * attaching state. This way, it will never be probed
+ * again. This is not default because this limits the
+ * ability to fix the problem w/o rebooting (say if you
+ * have a bug in a kld, you can unload/load a fixed
+ * one). It is intended for situations where you know
+ * that attach failures are fatal for any future success
+ * of a device in a production environment where repated
+ * attempts to try again on that device have some kind
+ * of undesirable quality to them.
+ */
+ device_disable(dev);
+ } else {
+ /*
+ * Otherwise, when attach fails, tear down the state
+ * around that so we can retry when, for example, new
+ * drivers are loaded.
+ */
+ if (!(dev->flags & DF_FIXEDCLASS))
+ devclass_delete_device(dev->devclass, dev);
+ (void)device_set_driver(dev, NULL);
+ device_sysctl_fini(dev);
+ KASSERT(dev->busy == 0, ("attach failed but busy"));
+ dev->state = DS_NOTPRESENT;
+ }
return (error);
}
dev->flags |= DF_ATTACHED_ONCE;
- /* We only need the low bits of this time, but ranges from tens to thousands
+ /*
+ * We only need the low bits of this time, but ranges from tens to thousands
* have been seen, so keep 2 bytes' worth.
*/
attachentropy = (uint16_t)(get_cyclecount() - attachtime);

File Metadata

Mime Type
text/plain
Expires
Tue, Feb 17, 4:02 PM (11 m, 49 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28818685
Default Alt Text
D37517.id113550.diff (2 KB)

Event Timeline