]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: improve error message when destroying an inactive device
authorJonathon Jongsma <jjongsma@redhat.com>
Tue, 22 Jun 2021 19:53:36 +0000 (14:53 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 1 Jul 2021 14:34:03 +0000 (16:34 +0200)
When trying to destroy a node device that is not active, we end up with
a confusing error message:

  # nodedev-destroy mdev_88a6b868_46bd_4015_8e5b_26107f82da38
  error: Failed to destroy node device 'mdev_88a6b868_46bd_4015_8e5b_26107f82da38'
  error: failed to access '/sys/bus/mdev/devices/88a6b868-46bd-4015-8e5b-26107f82da38/iommu_group': No such file or directory

With this patch, the error is more clear:

  # nodedev-destroy mdev_88a6b868_46bd_4015_8e5b_26107f82da38
  error: Failed to destroy node device 'mdev_88a6b868_46bd_4015_8e5b_26107f82da38'
  error: Requested operation is not valid: Device 'mdev_88a6b868_46bd_4015_8e5b_26107f82da38' is not active

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
src/node_device/node_device_driver.c

index 9cd7134edd8bf027548193d8944bd15e54e690c4..b4dd57e5f4f107c9fb2da66309113ec05862fd14 100644 (file)
@@ -1230,6 +1230,15 @@ nodeDeviceDestroy(virNodeDevicePtr device)
 
         ret = 0;
     } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
+        g_autofree char *vfiogroup = NULL;
+        VIR_AUTOCLOSE fd = -1;
+
+        if (!virNodeDeviceObjIsActive(obj)) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("Device '%s' is not active"), def->name);
+            goto cleanup;
+        }
+
         /* If this mediated device is in use by a vm, attempting to stop it
          * will block until the vm closes the device. The nodedev driver
          * cannot query the hypervisor driver to determine whether the device
@@ -1239,10 +1248,7 @@ nodeDeviceDestroy(virNodeDevicePtr device)
          * to be opened by one user at a time. So if we get EBUSY when opening
          * the group, we infer that the device is in use and therefore we
          * shouldn't try to remove the device. */
-        g_autofree char *vfiogroup =
-            virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid);
-        VIR_AUTOCLOSE fd = -1;
-
+        vfiogroup = virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid);
         if (!vfiogroup)
             goto cleanup;