{
virMediatedDevicePtr ret = NULL;
virMediatedDevicePtr dev = NULL;
+ char *sysfspath = NULL;
- if (VIR_ALLOC(dev) < 0)
- return NULL;
+ if (!(sysfspath = virMediatedDeviceGetSysfsPath(uuidstr)))
+ goto cleanup;
+
+ if (!virFileExists(sysfspath)) {
+ virReportError(VIR_ERR_DEVICE_MISSING,
+ _("mediated device '%s' not found"), uuidstr);
+ goto cleanup;
+ }
- if (!(dev->path = virMediatedDeviceGetSysfsPath(uuidstr)))
+ if (VIR_ALLOC(dev) < 0)
goto cleanup;
+ VIR_STEAL_PTR(dev->path, sysfspath);
+
/* Check whether the user-provided model corresponds with the actually
* supported mediated device's API.
*/
VIR_STEAL_PTR(ret, dev);
cleanup:
+ VIR_FREE(sysfspath);
virMediatedDeviceFree(dev);
return ret;
}