Add a function to lookup a device_t object by name.

This just walks the global list of devices looking for one with the
requested name.  The one use case outside of devctl2's implementation
is for DDB commands that wish to lookup devices by name.
This commit is contained in:
John Baldwin 2016-04-10 05:05:02 +00:00
parent b4fb3d6e02
commit 70e22add96
2 changed files with 17 additions and 6 deletions

View File

@ -5125,6 +5125,18 @@ bus_free_resource(device_t dev, int type, struct resource *r)
return (bus_release_resource(dev, type, rman_get_rid(r), r));
}
device_t
device_lookup_by_name(const char *name)
{
device_t dev;
TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
if (dev->nameunit != NULL && strcmp(dev->nameunit, name) == 0)
return (dev);
}
return (NULL);
}
/*
* /dev/devctl2 implementation. The existing /dev/devctl device has
* implicit semantics on open, so it could not be reused for this.
@ -5145,12 +5157,10 @@ find_device(struct devreq *req, device_t *devp)
* Second, try to find an attached device whose name matches
* 'name'.
*/
TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
if (dev->nameunit != NULL &&
strcmp(dev->nameunit, req->dr_name) == 0) {
*devp = dev;
return (0);
}
dev = device_lookup_by_name(req->dr_name);
if (dev != NULL) {
*devp = dev;
return (0);
}
/* Finally, give device enumerators a chance. */

View File

@ -524,6 +524,7 @@ int device_is_attached(device_t dev); /* did attach succeed? */
int device_is_enabled(device_t dev);
int device_is_suspended(device_t dev);
int device_is_quiet(device_t dev);
device_t device_lookup_by_name(const char *name);
int device_print_prettyname(device_t dev);
int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
int device_probe(device_t dev);