nodedev: improve error message when destroying an inactive device

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>
This commit is contained in:
Jonathon Jongsma 2021-06-22 14:53:36 -05:00 committed by Michal Privoznik
parent bcdcaa2d08
commit dfa1e9b3eb

View 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;