return NULL;
}
-const char *qdev_get_printable_name(DeviceState *vdev)
+const char *qdev_get_printable_name(DeviceState *dev)
{
- /*
- * Return device ID if explicity set
- * (e.g. -device virtio-blk-pci,id=foo)
- * This allows users to correlate errors with their custom device
- * names.
- */
- if (vdev->id) {
- return g_strdup(vdev->id);
+ if (dev->id) {
+ return g_strdup(dev->id);
}
/*
- * Fall back to the canonical QOM device path (eg. ID for PCI
- * devices).
- * This ensures the device is still uniquely and meaningfully
- * identified.
+ * Fall back to a bus-specific device path, if the bus
+ * provides one (e.g. PCI address "0000:00:04.0").
*/
- const char *path = qdev_get_dev_path(vdev);
+ const char *path = qdev_get_dev_path(dev);
if (path) {
return path;
}
- /*
- * Final fallback: if all else fails, return a placeholder string.
- * This ensures the error message always contains a valid string.
- */
- return g_strdup("<unknown device>");
+ return object_get_canonical_path(OBJECT(dev));
}
void qdev_add_unplug_blocker(DeviceState *dev, Error *reason)
* user-facing error messages. The function will never return NULL,
* so the name can be used without further checking or fallbacks.
*
- * If the device has an explicitly set ID (e.g. by the user on the
- * command line via "-device thisdev,id=myid") this is preferred.
- * Otherwise we try the canonical QOM device path (which will be
- * the PCI ID for PCI devices, for example). If all else fails
- * we will return the placeholder "<unknown device">.
+ * Return the device's ID if it has one. Else, return the path of a
+ * device on its bus if it has one. Else return its canonical QOM
+ * path.
*/
const char *qdev_get_printable_name(DeviceState *dev);