From: Erik Skultety Date: Fri, 16 Mar 2018 09:06:04 +0000 (+0100) Subject: util: mdev: Improve the error msg on non-existent mdev prior to VM start X-Git-Tag: v4.2.0-rc1~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d2e4c3e53a179057552f0dc9a861657df62d303;p=thirdparty%2Flibvirt.git util: mdev: Improve the error msg on non-existent mdev prior to VM start What one currently gets is: failed to read '/sys/bus/mdev/devices//mdev_type/device_api': No such file or directory This indicates that something is missing within the device's sysfs tree which likely might be not be the case here because the device simply doesn't exist yet. So, when creating our internal mdev obj, let's check whether the device exists first prior to trying to verify the user-provided model within domain XML. Signed-off-by: Erik Skultety --- diff --git a/src/util/virmdev.c b/src/util/virmdev.c index e4816cf201..27541cf34f 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -150,13 +150,22 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model) { 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. */ @@ -167,6 +176,7 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model) VIR_STEAL_PTR(ret, dev); cleanup: + VIR_FREE(sysfspath); virMediatedDeviceFree(dev); return ret; }