]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: mdev: Improve the error msg on non-existent mdev prior to VM start
authorErik Skultety <eskultet@redhat.com>
Fri, 16 Mar 2018 09:06:04 +0000 (10:06 +0100)
committerErik Skultety <eskultet@redhat.com>
Mon, 19 Mar 2018 10:14:40 +0000 (11:14 +0100)
What one currently gets is:
failed to read '/sys/bus/mdev/devices/<UUID>/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 <eskultet@redhat.com>
src/util/virmdev.c

index e4816cf201b31af19451d48dcb71627f9447e87e..27541cf34fc434ea176a2020aa8996b0f676997f 100644 (file)
@@ -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;
 }