[libvirt PATCH v2 5/5] nodedev: improve error message when destroying an inactive device

Jonathon Jongsma jjongsma at redhat.com
Tue Jun 22 19:53:36 UTC 2021


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 at redhat.com>
---
 src/node_device/node_device_driver.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 497db0006a..721ba96203 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1227,6 +1227,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
@@ -1236,10 +1245,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;
 
-- 
2.31.1




More information about the libvir-list mailing list